Skip to content

Commit 823908a

Browse files
srawlinsCommit Queue
authored andcommitted
Simplify ConfigurationFilesMixin
Work towards #55660 This mixin has some members that can be made private, and some that can be removed. Removing a `macro` parameter also simplifies things. Change-Id: Id3b5d33ff66dde0c763499ff183943d72901d395 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/429440 Reviewed-by: Keerti Parthasarathy <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent 78c2181 commit 823908a

File tree

3 files changed

+23
-61
lines changed

3 files changed

+23
-61
lines changed

pkg/analysis_server/test/shared/shared_test_interface.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,5 @@ abstract interface class SharedTestInterface {
8383
bool meta = false,
8484
bool pedantic = false,
8585
bool vector_math = false,
86-
bool macro = false,
8786
});
8887
}

pkg/analysis_server/test/support/configuration_files.dart

Lines changed: 22 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,24 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:analyzer/file_system/file_system.dart';
6-
import 'package:analyzer/file_system/physical_file_system.dart';
76
import 'package:analyzer/src/dart/analysis/experiments.dart';
87
import 'package:analyzer/src/util/file_paths.dart' as file_paths;
98
import 'package:analyzer/utilities/package_config_file_builder.dart';
109
import 'package:analyzer_testing/mock_packages/mock_packages.dart';
11-
import 'package:analyzer_testing/package_root.dart' as package_root;
1210
import 'package:analyzer_testing/utilities/extensions/resource_provider.dart';
1311

1412
/// A mixin adding functionality to write `.dart_tool/package_config.json`
1513
/// files along with mock packages to a [ResourceProvider].
1614
mixin ConfigurationFilesMixin on MockPackagesMixin {
17-
String get latestLanguageVersion =>
18-
'${ExperimentStatus.currentVersion.major}.'
19-
'${ExperimentStatus.currentVersion.minor}';
20-
21-
String get testPackageLanguageVersion => latestLanguageVersion;
15+
/// The Dart language version of the test package being used for testing.
16+
String get testPackageLanguageVersion => _latestLanguageVersion;
2217

2318
/// The path to the test package being used for testing.
2419
String get testPackageRootPath;
2520

26-
String convertPath(String fileName) => resourceProvider.convertPath(fileName);
27-
28-
String toUriStr(String filePath) =>
29-
pathContext.toUri(convertPath(filePath)).toString();
21+
String get _latestLanguageVersion =>
22+
'${ExperimentStatus.currentVersion.major}.'
23+
'${ExperimentStatus.currentVersion.minor}';
3024

3125
/// Writes a package_config.json for the package at [projectFolderPath]. If
3226
/// [packageName] is not supplied, the last segment of [projectFolderPath] is
@@ -43,9 +37,8 @@ mixin ConfigurationFilesMixin on MockPackagesMixin {
4337
bool meta = false,
4438
bool pedantic = false,
4539
bool vector_math = false,
46-
bool macro = false,
4740
}) {
48-
projectFolderPath = convertPath(projectFolderPath);
41+
projectFolderPath = resourceProvider.convertPath(projectFolderPath);
4942

5043
if (config == null) {
5144
config = PackageConfigFileBuilder();
@@ -66,14 +59,11 @@ mixin ConfigurationFilesMixin on MockPackagesMixin {
6659
}
6760

6861
if (flutter) {
69-
{
70-
var libFolder = addUI();
71-
config.add(name: 'ui', rootPath: libFolder.parent.path);
72-
}
73-
{
74-
var libFolder = addFlutter();
75-
config.add(name: 'flutter', rootPath: libFolder.parent.path);
76-
}
62+
var uiLibFolder = addUI();
63+
config.add(name: 'ui', rootPath: uiLibFolder.parent.path);
64+
65+
var flutterLibFolder = addFlutter();
66+
config.add(name: 'flutter', rootPath: flutterLibFolder.parent.path);
7767
}
7868

7969
if (flutter_test) {
@@ -91,30 +81,18 @@ mixin ConfigurationFilesMixin on MockPackagesMixin {
9181
config.add(name: 'vector_math', rootPath: libFolder.parent.path);
9282
}
9383

94-
if (macro) {
95-
// TODO(dantup): This code may need to change/be removed depending on how
96-
// we ultimately reference the macro packages/libraries.
97-
var physical = PhysicalResourceProvider.INSTANCE;
98-
var packageRoot = physical.pathContext.normalize(
99-
package_root.packageRoot,
100-
);
101-
102-
for (var package in ['macros', '_macros']) {
103-
var destination = resourceProvider.getFolder(
104-
convertPath('$packagesRootPath/$package'),
105-
);
106-
physical
107-
.getFolder(packageRoot)
108-
.getChildAssumingFolder(package)
109-
.copyTo(destination.parent);
110-
config.add(name: package, rootPath: destination.path);
111-
}
112-
}
113-
114-
_newPackageConfigJsonFile(
115-
projectFolderPath,
116-
config.toContent(toUriStr: toUriStr),
84+
var content = config.toContent(
85+
toUriStr:
86+
(p) => pathContext.toUri(resourceProvider.convertPath(p)).toString(),
11787
);
88+
89+
var projectFolder = resourceProvider.getFolder(projectFolderPath);
90+
var dartToolFolder = projectFolder.getChildAssumingFolder(
91+
file_paths.dotDartTool,
92+
)..create();
93+
dartToolFolder
94+
.getChildAssumingFile(file_paths.packageConfigJson)
95+
.writeAsStringSync(content);
11896
}
11997

12098
/// Writes a package_config.json for the package under test (considered
@@ -127,7 +105,6 @@ mixin ConfigurationFilesMixin on MockPackagesMixin {
127105
bool meta = false,
128106
bool pedantic = false,
129107
bool vector_math = false,
130-
bool macro = false,
131108
}) {
132109
writePackageConfig(
133110
testPackageRootPath,
@@ -139,20 +116,6 @@ mixin ConfigurationFilesMixin on MockPackagesMixin {
139116
meta: meta,
140117
pedantic: pedantic,
141118
vector_math: vector_math,
142-
macro: macro,
143-
);
144-
}
145-
146-
File _newPackageConfigJsonFile(String packageRootPath, String content) {
147-
var dartToolDirectoryPath = pathContext.join(
148-
packageRootPath,
149-
file_paths.dotDartTool,
150-
);
151-
var filePath = pathContext.join(
152-
dartToolDirectoryPath,
153-
file_paths.packageConfigJson,
154119
);
155-
resourceProvider.getFolder(dartToolDirectoryPath).create();
156-
return resourceProvider.getFile(filePath)..writeAsStringSync(content);
157120
}
158121
}

pkg/analyzer_testing/lib/mock_packages/mock_packages.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ mixin MockPackagesMixin {
147147
return packageFolder.getChildAssumingFolder('lib');
148148
}
149149

150-
/// Add files of the given [packageName] to the [provider].
150+
/// Adds files of the given [packageName] to the [resourceProvider].
151151
Folder _addFiles(String packageName) {
152152
var cachedFiles = _cachedFiles;
153153
if (cachedFiles == null) {

0 commit comments

Comments
 (0)