Skip to content

Commit 80d8f1d

Browse files
mralephCommit Queue
authored andcommitted
[vm] Make dart run --resident work in SDK checkout
Resident runner used to look either for pubspec.yaml or .dart_tool/package_config.json to find package root. However it does not make much sense to look for pubspec.yaml you can't resolve packages using just pubspec anyway - you need package_config.json. This was making it impossible to use resident runner with packages in Dart SDK checkout: each package contains pubspec.yaml, but package_config.json is generated at the root of SDK checkout instead. This CL also removes support for .packages file - we have deprecated and removed this file in 2022. [email protected] TEST=manually Change-Id: I18ce7a1a82bc72bbc944d8ab2d40f40cdb15cc1e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/357620 Commit-Queue: Slava Egorov <[email protected]> Reviewed-by: Martin Kustermann <[email protected]>
1 parent 20f197d commit 80d8f1d

File tree

5 files changed

+26
-30
lines changed

5 files changed

+26
-30
lines changed

pkg/dartdev/lib/src/generate_kernel.dart

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import 'dart:io';
66

77
import 'package:args/args.dart';
8-
import 'package:package_config/package_config.dart';
98
import 'package:path/path.dart' as p;
109
import 'package:pub/pub.dart';
1110

@@ -51,12 +50,12 @@ Future<DartExecutableWithPackageConfig> generateKernel(
5150
final packageRoot = _packageRootFor(executable);
5251
if (packageRoot == null) {
5352
throw FrontendCompilerException._(
54-
'resident mode is only supported for Dart packages.',
53+
'Unable to locate .dart_tool/package_config.json in any parent folder.'
54+
'Did you run `pub get`?',
5555
CompilationIssue.standaloneProgramError);
5656
}
5757
await ensureCompilationServerIsRunning(serverInfoFile);
58-
// TODO: allow custom package paths with a --packages flag
59-
final packageConfig = await _resolvePackageConfig(executable, packageRoot);
58+
final packageConfig = p.join(packageRoot, packageConfigName);
6059
final cachedKernel = _cachedKernelPath(executable.executable, packageRoot);
6160
Map<String, dynamic> result;
6261
try {
@@ -185,35 +184,14 @@ String? _packageRootFor(DartExecutableWithPackageConfig executable) {
185184
Directory(p.dirname(p.canonicalize(executable.executable)));
186185

187186
while (currentDirectory.parent.path != currentDirectory.path) {
188-
if (File(p.join(currentDirectory.path, 'pubspec.yaml')).existsSync() ||
189-
File(p.join(currentDirectory.path, packageConfigName)).existsSync()) {
187+
if (File(p.join(currentDirectory.path, packageConfigName)).existsSync()) {
190188
return currentDirectory.path;
191189
}
192190
currentDirectory = currentDirectory.parent;
193191
}
194192
return null;
195193
}
196194

197-
/// Resolves the absolute path to [packageRoot]'s package_config.json file,
198-
/// returning null if the package does not contain one, or if the source
199-
/// being compiled is a standalone dart script not inside a package.
200-
Future<String?> _resolvePackageConfig(
201-
DartExecutableWithPackageConfig executable, String packageRoot) async {
202-
final packageConfig = await findPackageConfigUri(
203-
Uri.file(p.canonicalize(executable.executable)),
204-
recurse: true,
205-
onError: (_) {},
206-
);
207-
if (packageConfig != null) {
208-
final dotPackageFile = File(p.join(packageRoot, '.packages'));
209-
final packageConfigFile = File(p.join(packageRoot, packageConfigName));
210-
return packageConfigFile.existsSync()
211-
? packageConfigFile.path
212-
: dotPackageFile.path;
213-
}
214-
return null;
215-
}
216-
217195
/// Indicates the type of issue encountered with the
218196
/// Resident Frontend Compiler
219197
enum CompilationIssue {

pkg/dartdev/pubspec.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ dependencies:
2626
meta: any
2727
native_assets_builder: any
2828
native_assets_cli: any
29-
package_config: any
3029
path: any
3130
pub: any
3231
telemetry: any

pkg/dartdev/test/commands/run_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,15 +1050,15 @@ void residentRun() {
10501050

10511051
test('standalone dart program', () async {
10521052
p = project(mainSrc: 'void main() {}');
1053-
p.deleteFile('pubspec.yaml');
1053+
p.deleteFile('.dart_tool/package_config.json');
10541054
final runResult = await p.run([
10551055
'run',
10561056
'--$serverInfoOption=$serverInfoFile',
10571057
p.relativeFilePath,
10581058
]);
10591059

10601060
expect(runResult.stderr,
1061-
contains('resident mode is only supported for Dart packages.'));
1061+
contains('Unable to locate .dart_tool/package_config.json'));
10621062
expect(runResult.exitCode, isNot(0));
10631063
expect(File(serverInfoFile).existsSync(), true);
10641064
});

pkg/dartdev/test/core_test.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ void _project() {
134134

135135
test('hasPackageConfigFile positive', () {
136136
final p = project();
137-
p.file('.dart_tool/package_config.json', _packageData);
138137
Project coreProj = Project.fromDirectory(p.dir);
139138
expect(coreProj.hasPackageConfigFile, isTrue);
140139
expect(coreProj.packageConfig, isNotNull);
@@ -143,6 +142,9 @@ void _project() {
143142

144143
test('hasPackageConfigFile negative', () {
145144
final p = project();
145+
var packageConfig =
146+
File(path.join(p.dirPath, '.dart_tool/package_config.json'));
147+
packageConfig.deleteSync();
146148
Project coreProj = Project.fromDirectory(p.dir);
147149
expect(coreProj.hasPackageConfigFile, isFalse);
148150
});

pkg/dartdev/test/utils.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,23 @@ class TestProject {
9090
},
9191
),
9292
);
93+
file(
94+
'.dart_tool/package_config.json',
95+
JsonEncoder.withIndent(' ').convert(
96+
{
97+
'configVersion': 2,
98+
'generator': 'utils.dart',
99+
'packages': [
100+
{
101+
'name': name,
102+
'rootUri': '../',
103+
'packageUri': 'lib/',
104+
'languageVersion': '3.2',
105+
},
106+
],
107+
},
108+
),
109+
);
93110
if (analysisOptions != null) {
94111
file('analysis_options.yaml', analysisOptions);
95112
}

0 commit comments

Comments
 (0)