[dartdev] dart compile exe only warn on hooks for bin/

`dart build cli` only supports `bin/` scripts. So don't suggest it
as replacement for `dart compile` for non bin scripts.

Bug: https://github.com/dart-lang/sdk/issues/62593
Change-Id: I61cf60d4f168f10067295d4876c859e72eb32881
Cq-Include-Trybots: luci.dart.try:pkg-linux-debug-try,pkg-linux-release-arm64-try,pkg-linux-release-try,pkg-mac-release-arm64-try,pkg-mac-release-try,pkg-win-release-arm64-try,pkg-win-release-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/478640
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Morgan :) <davidmorgan@google.com>
This commit is contained in:
Daco Harkes
2026-02-05 06:47:47 -08:00
committed by Commit Queue
parent 09cc803061
commit 70ec554263
2 changed files with 70 additions and 9 deletions
+18 -9
View File
@@ -709,17 +709,26 @@ Remove debugging information from the output and save it separately to the speci
verbose: verbose,
target: target,
);
if (!nativeAssetsExperimentEnabled) {
if (await builder.warnOnNativeAssets()) {
final isBinScript = path.isWithin(
path.canonicalize(path.join(Directory.current.path, 'bin')),
path.canonicalize(sourcePath),
);
if (isBinScript) {
if (!nativeAssetsExperimentEnabled) {
if (await builder.warnOnNativeAssets()) {
return 255;
}
} else if (await builder.hasHooks()) {
final packages = (await builder.packagesWithBuildHooks()).join(
', ',
);
stderr.writeln(
"'dart compile' does not support build hooks, use 'dart build' instead.\n"
'Packages with build hooks: $packages.',
);
return 255;
}
} else if (await builder.hasHooks()) {
final packages = (await builder.packagesWithBuildHooks()).join(', ');
stderr.writeln(
"'dart compile' does not support build hooks, use 'dart build' instead.\n"
'Packages with build hooks: $packages.',
);
return 255;
}
}
}
@@ -49,6 +49,58 @@ void main() async {
});
});
test('dart compile only bails in bin/', timeout: longTimeout, () async {
await nativeAssetsTest('dart_app', (dartAppUri) async {
await runDart(
arguments: ['pub', 'get'],
workingDirectory: dartAppUri,
logger: logger,
);
// 1. Compiling in bin/ should fail.
final resultBin = await runDart(
arguments: [
'compile',
'exe',
'bin/dart_app.dart',
],
workingDirectory: dartAppUri,
logger: logger,
expectExitCodeZero: false,
);
expect(resultBin.exitCode, 255);
expect(
resultBin.stderr,
contains(
"'dart compile' does not support build hooks, use 'dart build' instead.",
),
);
// 2. Compiling outside bin/ should succeed (even if it might fail at runtime).
final otherFile = File.fromUri(dartAppUri.resolve('tool/other.dart'));
await otherFile.parent.create(recursive: true);
await otherFile.writeAsString('void main() { print("hello"); }');
final resultOther = await runDart(
arguments: [
'-v',
'compile',
'exe',
'tool/other.dart',
],
workingDirectory: dartAppUri,
logger: logger,
);
expect(resultOther.exitCode, 0);
final exePath = dartAppUri.resolve('tool/other.exe').toFilePath();
final resultRun = await runProcess(
executable: Uri.file(exePath),
logger: logger,
);
expect(resultRun.stdout, contains('hello'));
});
});
test('Recorded usages in dart2js', timeout: longTimeout, () async {
await recordUseTest('drop_data_asset', (dartAppUri) async {
await runDart(