mirror of
https://github.com/dart-lang/sdk
synced 2024-10-06 14:49:43 +00:00
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 <jakemac@google.com> Commit-Queue: Jake Macdonald <jakemac@google.com> Commit-Queue: Sigmund Cherem <sigmund@google.com> Reviewed-by: Sigmund Cherem <sigmund@google.com>
This commit is contained in:
parent
9547628ecf
commit
d9d4e5ccb3
|
@ -11,14 +11,22 @@ import 'package:modular_test/src/io_pipeline.dart';
|
|||
import 'package:modular_test/src/pipeline.dart';
|
||||
import 'package:modular_test/src/suite.dart';
|
||||
import 'package:modular_test/src/runner.dart';
|
||||
import 'package:package_config/package_config.dart';
|
||||
|
||||
String packageConfigJsonPath = '.dart_tool/package_config.json';
|
||||
Uri sdkRoot = Platform.script.resolve('../../../');
|
||||
Uri packageConfigUri = sdkRoot.resolve(packageConfigJsonPath);
|
||||
Options _options;
|
||||
String _dartdevcScript;
|
||||
String _kernelWorkerScript;
|
||||
|
||||
// TODO(joshualitt): Figure out a way to support package configs in
|
||||
// tests/modular.
|
||||
PackageConfig _packageConfig;
|
||||
|
||||
void main(List<String> args) async {
|
||||
_options = Options.parse(args);
|
||||
_packageConfig = await loadPackageConfigUri(packageConfigUri);
|
||||
await _resolveScripts();
|
||||
await runSuite(
|
||||
sdkRoot.resolve('tests/modular/'),
|
||||
|
@ -35,6 +43,17 @@ const dillId = DataId('dill');
|
|||
const jsId = DataId('js');
|
||||
const txtId = DataId('txt');
|
||||
|
||||
String _packageConfigEntry(String name, Uri root,
|
||||
{Uri packageRoot, LanguageVersion version}) {
|
||||
var fields = [
|
||||
'"name": "${name}"',
|
||||
'"rootUri": "$root"',
|
||||
if (packageRoot != null) '"packageUri": "$packageRoot"',
|
||||
if (version != null) '"languageVersion": "$version"'
|
||||
];
|
||||
return '{${fields.join(',')}}';
|
||||
}
|
||||
|
||||
class SourceToSummaryDillStep implements IOModularStep {
|
||||
@override
|
||||
List<DataId> get resultData => const [dillId];
|
||||
|
@ -301,30 +320,51 @@ String get _d8executable {
|
|||
|
||||
Future<void> _createPackagesFile(
|
||||
Module module, Uri root, Set<Module> transitiveDependencies) async {
|
||||
// We create a .packages file which defines the location of this module if
|
||||
// it is a package. The CFE requires that if a `package:` URI of a
|
||||
// dependency is used in an import, then we need that package entry in the
|
||||
// .packages file. However, after it checks that the definition exists, the
|
||||
// CFE will not actually use the resolved URI if a library for the import
|
||||
// URI is already found in one of the provided .dill files of the
|
||||
// dependencies. For that reason, and to ensure that a step only has access
|
||||
// to the files provided in a module, we generate a .packages with invalid
|
||||
// folders for other packages.
|
||||
// We create both a .packages and package_config.json file which defines
|
||||
// the location of this module if it is a package. The CFE requires that
|
||||
// if a `package:` URI of a dependency is used in an import, then we need
|
||||
// that package entry in the associated file. However, after it checks that
|
||||
// the definition exists, the CFE will not actually use the resolved URI if
|
||||
// a library for the import URI is already found in one of the provide
|
||||
// .dill files of the dependencies. For that reason, and to ensure that
|
||||
// a step only has access to the files provided in a module, we generate a
|
||||
// config file with invalid folders for other packages.
|
||||
// TODO(sigmund): follow up with the CFE to see if we can remove the need
|
||||
// for the .packages entry altogether if they won't need to read the
|
||||
// sources.
|
||||
// for these dummy entries..
|
||||
// TODO(joshualitt): Generate just the json file.
|
||||
var packagesJson = [];
|
||||
var packagesContents = StringBuffer();
|
||||
if (module.isPackage) {
|
||||
packagesContents.write('${module.name}:${module.packageBase}\n');
|
||||
packagesJson.add(_packageConfigEntry(
|
||||
module.name, Uri.parse('../${module.packageBase}')));
|
||||
}
|
||||
var unusedNum = 0;
|
||||
for (var dependency in transitiveDependencies) {
|
||||
if (dependency.isPackage) {
|
||||
// rootUri should be ignored for dependent modules, so we pass in a
|
||||
// bogus value.
|
||||
var rootUri = Uri.parse('unused$unusedNum');
|
||||
unusedNum++;
|
||||
packagesContents.write('${dependency.name}:unused$unusedNum\n');
|
||||
var dependentPackage = _packageConfig[dependency.name];
|
||||
var packageJson = dependentPackage == null
|
||||
? _packageConfigEntry(dependency.name, rootUri)
|
||||
: _packageConfigEntry(dependentPackage.name, rootUri,
|
||||
version: dependentPackage.languageVersion);
|
||||
packagesJson.add(packageJson);
|
||||
packagesContents.write('${dependency.name}:$rootUri\n');
|
||||
}
|
||||
}
|
||||
|
||||
if (module.isPackage) {
|
||||
await File.fromUri(root.resolve(packageConfigJsonPath))
|
||||
.create(recursive: true);
|
||||
await File.fromUri(root.resolve(packageConfigJsonPath)).writeAsString('{'
|
||||
' "configVersion": ${_packageConfig.version},'
|
||||
' "packages": [ ${packagesJson.join(',')} ]'
|
||||
'}');
|
||||
}
|
||||
|
||||
await File.fromUri(root.resolve('.packages'))
|
||||
.writeAsString('$packagesContents');
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue