a94b8ae45d
This relands the following CLs
[vm] Make VM support .dart_tool/package_config.json
https://dart-review.googlesource.com/c/sdk/+/145462
[vm] Make Isolate.resolveUri() work for both `.packages` and `dart_tool/package_config.json`
https://dart-review.googlesource.com/c/sdk/+/145803
[vm] Skip (newly enabled) isolate tests on simarm* and hot-reload configs
https://dart-review.googlesource.com/c/sdk/+/145861
[vm] Remove ../0 postfix from status file entries (test framework does not recognize those multitests)
https://dart-review.googlesource.com/c/sdk/+/145940
[vm] - Fix hang when no package config or .packages exist
https://dart-review.googlesource.com/c/sdk/+/145661
The only change (extra patchset) is to let VM prefer the old/legacy
".packages" format and only use the newer
".dart_tool/package_config.json" if we failed to find a ".packages".
Closes https://github.com/dart-lang/sdk/issues/41739
Closes https://github.com/dart-lang/sdk/issues/41649
Change-Id: I220f808540e6e521d985ae763968f64dbf57fe67
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/145942
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
182 lines
6.2 KiB
Dart
182 lines
6.2 KiB
Dart
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
import 'dart:io';
|
|
|
|
import 'package:expect/expect.dart';
|
|
import 'package:path/path.dart' as path;
|
|
|
|
final executable = Platform.executable;
|
|
|
|
main() async {
|
|
// Run the Dart VM with or without:
|
|
// --packages=<packages|package_config>
|
|
for (final runWithPackagesArg in const [true, false]) {
|
|
// Run the isolate with or without
|
|
// Isolate.spawnUri(..., packageConfig: <packages|package_config>)
|
|
print('TEST runWithPackagesArg = $runWithPackagesArg ');
|
|
for (final spawnWithPackageConfig in const [true, false]) {
|
|
print('TEST spawnWithPackageConfig = $spawnWithPackageConfig ');
|
|
final bool checkForResolveUri =
|
|
runWithPackagesArg || !spawnWithPackageConfig;
|
|
await runDotPackagesTest(
|
|
runWithPackagesArg, spawnWithPackageConfig, checkForResolveUri);
|
|
for (final optionalPackageUri in const [true, false]) {
|
|
print('TEST optionalPackageUri = $optionalPackageUri');
|
|
await runPackageConfigTest(runWithPackagesArg, spawnWithPackageConfig,
|
|
optionalPackageUri, checkForResolveUri);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
Future runPackageConfigTest(bool withPackagesArg, bool spawnWithArg,
|
|
bool optionalPackageUri, bool checkForResolveUri) async {
|
|
await withApplicationDirAndDotDartToolPackageConfig(
|
|
(String tempDir, String packageJson, String mainFile) async {
|
|
final args = [if (withPackagesArg) '--packages=$packageJson', mainFile];
|
|
await run(executable, args);
|
|
}, spawnWithArg, optionalPackageUri, checkForResolveUri);
|
|
}
|
|
|
|
Future runDotPackagesTest(
|
|
bool withPackagesArg, bool spawnWithArg, bool checkForResolveUri) async {
|
|
await withApplicationDirAndDotPackages(
|
|
(String tempDir, String dotPackagesFile, String mainFile) async {
|
|
final args = [
|
|
if (withPackagesArg) '--packages=$dotPackagesFile',
|
|
mainFile,
|
|
];
|
|
await run(executable, args);
|
|
}, spawnWithArg, checkForResolveUri);
|
|
}
|
|
|
|
Future withApplicationDirAndDotPackages(
|
|
Future fn(String tempDir, String packagesDir, String mainFile),
|
|
bool spawnWithArg,
|
|
bool checkForResolveUri) async {
|
|
await withTempDir((String tempDir) async {
|
|
// Setup ".packages"
|
|
final dotPackagesFile =
|
|
path.join(tempDir, spawnWithArg ? 'baz.packages' : '.packages');
|
|
await File(dotPackagesFile).writeAsString(buildDotPackages('foo'));
|
|
|
|
final mainFile = path.join(tempDir, 'main.dart');
|
|
final childIsolateFile = path.join(tempDir, 'child_isolate.dart');
|
|
final importUri = 'package:foo/child_isolate.dart';
|
|
await File(childIsolateFile).writeAsString(buildChildIsolate());
|
|
await File(mainFile).writeAsString(buildMainIsolate(
|
|
importUri,
|
|
spawnWithArg ? dotPackagesFile : null,
|
|
checkForResolveUri ? childIsolateFile : null));
|
|
|
|
await fn(tempDir, dotPackagesFile, mainFile);
|
|
});
|
|
}
|
|
|
|
Future withApplicationDirAndDotDartToolPackageConfig(
|
|
Future fn(String tempDir, String packageJson, String mainFile),
|
|
bool spawnWithArg,
|
|
bool optionalPackageUri,
|
|
bool checkForResolveUri) async {
|
|
await withTempDir((String tempDir) async {
|
|
// Setup ".dart_tool/package_config.json"
|
|
final dotDartToolDir = path.join(tempDir, '.dart_tool');
|
|
await Directory(dotDartToolDir).create();
|
|
final packageConfigJsonFile = path.join(
|
|
dotDartToolDir, spawnWithArg ? 'baz.packages' : 'package_config.json');
|
|
await File(packageConfigJsonFile)
|
|
.writeAsString(buildPackageConfig('foo', optionalPackageUri));
|
|
|
|
// Setup actual application
|
|
final mainFile = path.join(tempDir, 'main.dart');
|
|
final childIsolateFile = path.join(tempDir, 'child_isolate.dart');
|
|
final importUri = 'package:foo/child_isolate.dart';
|
|
await File(childIsolateFile).writeAsString(buildChildIsolate());
|
|
await File(mainFile).writeAsString(buildMainIsolate(
|
|
importUri,
|
|
spawnWithArg ? packageConfigJsonFile : null,
|
|
checkForResolveUri ? childIsolateFile : null));
|
|
|
|
await fn(tempDir, packageConfigJsonFile, mainFile);
|
|
});
|
|
}
|
|
|
|
Future withTempDir(Future fn(String dir)) async {
|
|
final dir = await Directory.systemTemp.createTemp('spawn_uri');
|
|
try {
|
|
await fn(dir.absolute.path);
|
|
} finally {
|
|
await dir.delete(recursive: true);
|
|
}
|
|
}
|
|
|
|
Future<ProcessResult> run(String executable, List<String> args,
|
|
{String? cwd}) async {
|
|
print('Running $executable ${args.join(' ')}');
|
|
final String workingDirectory = cwd ?? Directory.current.absolute.path;
|
|
final result = await Process.run(executable, ['--trace-loading', ...args],
|
|
workingDirectory: workingDirectory);
|
|
print('exitCode:\n${result.exitCode}');
|
|
print('stdout:\n${result.stdout}');
|
|
print('stdout:\n${result.stderr}');
|
|
Expect.equals(0, result.exitCode);
|
|
return result;
|
|
}
|
|
|
|
String buildDotPackages(String packageName) => '$packageName:.';
|
|
|
|
String buildPackageConfig(String packageName, bool optionalPackageUri) => '''
|
|
{
|
|
"configVersion": 2,
|
|
"packages": [
|
|
{
|
|
"name": "$packageName",
|
|
"rootUri": "../"
|
|
${optionalPackageUri ? ', "packageUri": "./"' : ''}
|
|
}
|
|
]
|
|
}
|
|
''';
|
|
|
|
String buildChildIsolate() => '''
|
|
import 'dart:isolate';
|
|
|
|
main(List<String> args, SendPort message) {
|
|
message.send('child isolate is done');
|
|
}
|
|
''';
|
|
|
|
String buildMainIsolate(
|
|
String spawnUri, String? packageConfigUri, String? childIsolatePath) =>
|
|
'''
|
|
import 'dart:isolate';
|
|
import 'dart:io' as io;
|
|
|
|
main(List<String> args) async {
|
|
io.exitCode = 1;
|
|
|
|
final uri = Uri.parse('$spawnUri');
|
|
final resolvedUri = await Isolate.resolvePackageUri(uri);
|
|
if ("""\${resolvedUri?.toFilePath()}""" != r"""$childIsolatePath""") {
|
|
throw 'Could not Isolate.resolvePackageUri(uri).';
|
|
}
|
|
|
|
final rp = ReceivePort();
|
|
final isolateArgs = <String>['a'];
|
|
await Isolate.spawnUri(
|
|
uri,
|
|
isolateArgs,
|
|
rp.sendPort,
|
|
packageConfig: ${packageConfigUri != null ? 'Uri.file(r"$packageConfigUri")' : 'null'});
|
|
final childIsolateMessage = await rp.first;
|
|
if (childIsolateMessage != 'child isolate is done') {
|
|
throw 'Did not receive correct message from child isolate.';
|
|
}
|
|
|
|
// Test was successful.
|
|
io.exitCode = 0;
|
|
}
|
|
''';
|