Skip to content

Commit d9d4e5c

Browse files
jakemac53commit-bot@chromium.org
authored andcommitted
copy package config changes to the modular_suite_nnbd.dart
Change-Id: Ib2c645c0d94adb60693be85b266d23b811982e70 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/153364 Auto-Submit: Jake Macdonald <[email protected]> Commit-Queue: Jake Macdonald <[email protected]> Commit-Queue: Sigmund Cherem <[email protected]> Reviewed-by: Sigmund Cherem <[email protected]>
1 parent 9547628 commit d9d4e5c

File tree

1 file changed

+52
-12
lines changed

1 file changed

+52
-12
lines changed

pkg/dev_compiler/test/modular_suite_nnbd.dart

+52-12
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,22 @@ import 'package:modular_test/src/io_pipeline.dart';
1111
import 'package:modular_test/src/pipeline.dart';
1212
import 'package:modular_test/src/suite.dart';
1313
import 'package:modular_test/src/runner.dart';
14+
import 'package:package_config/package_config.dart';
1415

16+
String packageConfigJsonPath = '.dart_tool/package_config.json';
1517
Uri sdkRoot = Platform.script.resolve('../../../');
18+
Uri packageConfigUri = sdkRoot.resolve(packageConfigJsonPath);
1619
Options _options;
1720
String _dartdevcScript;
1821
String _kernelWorkerScript;
1922

23+
// TODO(joshualitt): Figure out a way to support package configs in
24+
// tests/modular.
25+
PackageConfig _packageConfig;
26+
2027
void main(List<String> args) async {
2128
_options = Options.parse(args);
29+
_packageConfig = await loadPackageConfigUri(packageConfigUri);
2230
await _resolveScripts();
2331
await runSuite(
2432
sdkRoot.resolve('tests/modular/'),
@@ -35,6 +43,17 @@ const dillId = DataId('dill');
3543
const jsId = DataId('js');
3644
const txtId = DataId('txt');
3745

46+
String _packageConfigEntry(String name, Uri root,
47+
{Uri packageRoot, LanguageVersion version}) {
48+
var fields = [
49+
'"name": "${name}"',
50+
'"rootUri": "$root"',
51+
if (packageRoot != null) '"packageUri": "$packageRoot"',
52+
if (version != null) '"languageVersion": "$version"'
53+
];
54+
return '{${fields.join(',')}}';
55+
}
56+
3857
class SourceToSummaryDillStep implements IOModularStep {
3958
@override
4059
List<DataId> get resultData => const [dillId];
@@ -301,30 +320,51 @@ String get _d8executable {
301320

302321
Future<void> _createPackagesFile(
303322
Module module, Uri root, Set<Module> transitiveDependencies) async {
304-
// We create a .packages file which defines the location of this module if
305-
// it is a package. The CFE requires that if a `package:` URI of a
306-
// dependency is used in an import, then we need that package entry in the
307-
// .packages file. However, after it checks that the definition exists, the
308-
// CFE will not actually use the resolved URI if a library for the import
309-
// URI is already found in one of the provided .dill files of the
310-
// dependencies. For that reason, and to ensure that a step only has access
311-
// to the files provided in a module, we generate a .packages with invalid
312-
// folders for other packages.
323+
// We create both a .packages and package_config.json file which defines
324+
// the location of this module if it is a package. The CFE requires that
325+
// if a `package:` URI of a dependency is used in an import, then we need
326+
// that package entry in the associated file. However, after it checks that
327+
// the definition exists, the CFE will not actually use the resolved URI if
328+
// a library for the import URI is already found in one of the provide
329+
// .dill files of the dependencies. For that reason, and to ensure that
330+
// a step only has access to the files provided in a module, we generate a
331+
// config file with invalid folders for other packages.
313332
// TODO(sigmund): follow up with the CFE to see if we can remove the need
314-
// for the .packages entry altogether if they won't need to read the
315-
// sources.
333+
// for these dummy entries..
334+
// TODO(joshualitt): Generate just the json file.
335+
var packagesJson = [];
316336
var packagesContents = StringBuffer();
317337
if (module.isPackage) {
318338
packagesContents.write('${module.name}:${module.packageBase}\n');
339+
packagesJson.add(_packageConfigEntry(
340+
module.name, Uri.parse('../${module.packageBase}')));
319341
}
320342
var unusedNum = 0;
321343
for (var dependency in transitiveDependencies) {
322344
if (dependency.isPackage) {
345+
// rootUri should be ignored for dependent modules, so we pass in a
346+
// bogus value.
347+
var rootUri = Uri.parse('unused$unusedNum');
323348
unusedNum++;
324-
packagesContents.write('${dependency.name}:unused$unusedNum\n');
349+
var dependentPackage = _packageConfig[dependency.name];
350+
var packageJson = dependentPackage == null
351+
? _packageConfigEntry(dependency.name, rootUri)
352+
: _packageConfigEntry(dependentPackage.name, rootUri,
353+
version: dependentPackage.languageVersion);
354+
packagesJson.add(packageJson);
355+
packagesContents.write('${dependency.name}:$rootUri\n');
325356
}
326357
}
327358

359+
if (module.isPackage) {
360+
await File.fromUri(root.resolve(packageConfigJsonPath))
361+
.create(recursive: true);
362+
await File.fromUri(root.resolve(packageConfigJsonPath)).writeAsString('{'
363+
' "configVersion": ${_packageConfig.version},'
364+
' "packages": [ ${packagesJson.join(',')} ]'
365+
'}');
366+
}
367+
328368
await File.fromUri(root.resolve('.packages'))
329369
.writeAsString('$packagesContents');
330370
}

0 commit comments

Comments
 (0)