@@ -14,13 +14,21 @@ import 'package:modular_test/src/io_pipeline.dart';
14
14
import 'package:modular_test/src/pipeline.dart' ;
15
15
import 'package:modular_test/src/suite.dart' ;
16
16
import 'package:modular_test/src/runner.dart' ;
17
+ import 'package:package_config/package_config.dart' ;
17
18
19
+ String packageConfigJsonPath = ".dart_tool/package_config.json" ;
18
20
Uri sdkRoot = Platform .script.resolve ("../../../" );
21
+ Uri packageConfigUri = sdkRoot.resolve (packageConfigJsonPath);
19
22
Options _options;
20
23
String _dart2jsScript;
21
24
String _kernelWorkerScript;
25
+
26
+ // TODO(joshualitt): Figure out a way to support package configs in
27
+ // tests/modular.
28
+ PackageConfig _packageConfig;
22
29
main (List <String > args) async {
23
30
_options = Options .parse (args);
31
+ _packageConfig = await loadPackageConfigUri (packageConfigUri);
24
32
await _resolveScripts ();
25
33
await runSuite (
26
34
sdkRoot.resolve ('tests/modular/' ),
@@ -45,6 +53,17 @@ const codeId1 = const ShardDataId(codeId, 1);
45
53
const jsId = const DataId ("js" );
46
54
const txtId = const DataId ("txt" );
47
55
56
+ String _packageConfigEntry (String name, Uri root,
57
+ {Uri packageRoot, LanguageVersion version}) {
58
+ var fields = [
59
+ '"name": "${name }"' ,
60
+ '"rootUri": "$root "' ,
61
+ if (packageRoot != null ) '"packageUri": "$packageRoot "' ,
62
+ if (version != null ) '"languageVersion": "$version "'
63
+ ];
64
+ return '{${fields .join (',' )}}' ;
65
+ }
66
+
48
67
// Step that compiles sources in a module to a .dill file.
49
68
class SourceToDillStep implements IOModularStep {
50
69
@override
@@ -88,31 +107,54 @@ class SourceToDillStep implements IOModularStep {
88
107
}
89
108
}
90
109
91
- // We create a .packages file which defines the location of this module if
92
- // it is a package. The CFE requires that if a `package:` URI of a
93
- // dependency is used in an import, then we need that package entry in the
94
- // .packages file. However, after it checks that the definition exists, the
95
- // CFE will not actually use the resolved URI if a library for the import
96
- // URI is already found in one of the provided .dill files of the
97
- // dependencies. For that reason, and to ensure that a step only has access
98
- // to the files provided in a module, we generate a .packages with invalid
99
- // folders for other packages.
110
+ // We create both a .packages and package_config.json file which defines
111
+ // the location of this module if it is a package. The CFE requires that
112
+ // if a `package:` URI of a dependency is used in an import, then we need
113
+ // that package entry in the associated file. However, after it checks that
114
+ // the definition exists, the CFE will not actually use the resolved URI if
115
+ // a library for the import URI is already found in one of the provide
116
+ // .dill files of the dependencies. For that reason, and to ensure that
117
+ // a step only has access to the files provided in a module, we generate a
118
+ // config file with invalid folders for other packages.
100
119
// TODO(sigmund): follow up with the CFE to see if we can remove the need
101
- // for the .packages entry altogether if they won't need to read the
102
- // sources.
120
+ // for these dummy entries..
121
+ // TODO(joshualitt): Generate just the json file.
122
+ var packagesJson = [];
103
123
var packagesContents = new StringBuffer ();
104
124
if (module.isPackage) {
105
125
packagesContents.write ('${module .name }:${module .packageBase }\n ' );
126
+ packagesJson.add (_packageConfigEntry (
127
+ module.name, Uri .parse ('../${module .packageBase }' )));
106
128
}
129
+
107
130
Set <Module > transitiveDependencies = computeTransitiveDependencies (module);
108
131
int unusedNum = 0 ;
109
132
for (Module dependency in transitiveDependencies) {
110
133
if (dependency.isPackage) {
134
+ // rootUri should be ignored for dependent modules, so we pass in a
135
+ // bogus value.
136
+ var rootUri = Uri .parse ('unused$unusedNum ' );
111
137
unusedNum++ ;
112
- packagesContents.write ('${dependency .name }:unused$unusedNum \n ' );
138
+
139
+ var dependentPackage = _packageConfig[dependency.name];
140
+ var packageJson = dependentPackage == null
141
+ ? _packageConfigEntry (dependency.name, rootUri)
142
+ : _packageConfigEntry (dependentPackage.name, rootUri,
143
+ version: dependentPackage.languageVersion);
144
+ packagesJson.add (packageJson);
145
+ packagesContents.write ('${dependency .name }:$rootUri \n ' );
113
146
}
114
147
}
115
148
149
+ if (module.isPackage) {
150
+ await File .fromUri (root.resolve (packageConfigJsonPath))
151
+ .create (recursive: true );
152
+ await File .fromUri (root.resolve (packageConfigJsonPath)).writeAsString ('{'
153
+ ' "configVersion": ${_packageConfig .version },'
154
+ ' "packages": [ ${packagesJson .join (',' )} ]'
155
+ '}' );
156
+ }
157
+
116
158
await File .fromUri (root.resolve ('.packages' ))
117
159
.writeAsString ('$packagesContents ' );
118
160
0 commit comments