From 72f847f458b689a7838ec903bc117d2e18be77bc Mon Sep 17 00:00:00 2001 From: Daco Harkes Date: Wed, 8 Nov 2023 11:13:10 +0000 Subject: [PATCH] [dartdev] Error on dart compile if native assets build fails `dart run` and `dart build` already checked. `dart compile` only checked if there are no native assets. However, it should also error if native assets builds failed, as there could have been native assets resulting from those builds. Change-Id: Id90eb9b58675856421b793b271bf627506effe3c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/334223 Auto-Submit: Daco Harkes Commit-Queue: Daco Harkes Reviewed-by: Martin Kustermann --- pkg/dartdev/lib/dartdev.dart | 5 +- pkg/dartdev/lib/src/commands/compile.dart | 6 +- .../test/native_assets/build_test.dart | 29 ++++++++ .../test/native_assets/compile_test.dart | 67 +++++++++++++++++++ 4 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 pkg/dartdev/test/native_assets/compile_test.dart diff --git a/pkg/dartdev/lib/dartdev.dart b/pkg/dartdev/lib/dartdev.dart index 59ddfc5919b..feb2d2d7248 100644 --- a/pkg/dartdev/lib/dartdev.dart +++ b/pkg/dartdev/lib/dartdev.dart @@ -104,7 +104,10 @@ class DartdevRunner extends CommandRunner { if (nativeAssetsExperimentEnabled) { addCommand(BuildCommand(verbose: verbose)); } - addCommand(CompileCommand(verbose: verbose)); + addCommand(CompileCommand( + verbose: verbose, + nativeAssetsExperimentEnabled: nativeAssetsExperimentEnabled, + )); addCommand(CreateCommand(verbose: verbose)); addCommand(DebugAdapterCommand(verbose: verbose)); addCommand(DevToolsCommand(verbose: verbose)); diff --git a/pkg/dartdev/lib/src/commands/compile.dart b/pkg/dartdev/lib/src/commands/compile.dart index a6659ef5bcc..66d1c3d9475 100644 --- a/pkg/dartdev/lib/src/commands/compile.dart +++ b/pkg/dartdev/lib/src/commands/compile.dart @@ -329,7 +329,11 @@ Remove debugging information from the output and save it separately to the speci return 255; } } else { - final (_, assets) = await compileNativeAssetsJit(verbose: verbose); + final (success, assets) = await compileNativeAssetsJit(verbose: verbose); + if (!success) { + stderr.writeln('Native assets build failed.'); + return 255; + } if (assets.isNotEmpty) { stderr.writeln( "'dart compile' does currently not support native assets."); diff --git a/pkg/dartdev/test/native_assets/build_test.dart b/pkg/dartdev/test/native_assets/build_test.dart index e1f34e52e53..cb0fc6f86aa 100644 --- a/pkg/dartdev/test/native_assets/build_test.dart +++ b/pkg/dartdev/test/native_assets/build_test.dart @@ -87,4 +87,33 @@ void main(List args) async { }); } } + + test('dart build native assets build failure', timeout: longTimeout, + () async { + await nativeAssetsTest('dart_app', (dartAppUri) async { + final buildDotDart = dartAppUri.resolve('../native_add/build.dart'); + await File.fromUri(buildDotDart).writeAsString(''' +void main(List args) { + throw UnimplementedError(); +} +'''); + final result = await runDart( + arguments: [ + '--enable-experiment=native-assets', + 'build', + 'bin/dart_app.dart', + ], + workingDirectory: dartAppUri, + logger: logger, + expectExitCodeZero: false, + ); + expect( + result.stderr, + contains( + 'Native assets build failed.', + ), + ); + expect(result.exitCode, 255); + }); + }); } diff --git a/pkg/dartdev/test/native_assets/compile_test.dart b/pkg/dartdev/test/native_assets/compile_test.dart new file mode 100644 index 00000000000..e63fb7f6a6d --- /dev/null +++ b/pkg/dartdev/test/native_assets/compile_test.dart @@ -0,0 +1,67 @@ +// Copyright (c) 2023, 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. + +// @dart=2.18 + +import 'dart:io'; + +import 'package:test/test.dart'; + +import '../utils.dart'; +import 'helpers.dart'; + +void main() async { + test('dart compile not supported', timeout: longTimeout, () async { + await nativeAssetsTest('dart_app', (dartAppUri) async { + final result = await runDart( + arguments: [ + '--enable-experiment=native-assets', + 'compile', + 'exe', + 'bin/dart_app.dart', + ], + workingDirectory: dartAppUri, + logger: logger, + expectExitCodeZero: false, + ); + expect( + result.stderr, + contains( + "'dart compile' does currently not support native assets.", + ), + ); + expect(result.exitCode, 255); + }); + }); + + test('dart compile native assets build failure', timeout: longTimeout, + () async { + await nativeAssetsTest('dart_app', (dartAppUri) async { + final buildDotDart = dartAppUri.resolve('../native_add/build.dart'); + await File.fromUri(buildDotDart).writeAsString(''' +void main(List args) { + throw UnimplementedError(); +} +'''); + final result = await runDart( + arguments: [ + '--enable-experiment=native-assets', + 'compile', + 'exe', + 'bin/dart_app.dart', + ], + workingDirectory: dartAppUri, + logger: logger, + expectExitCodeZero: false, + ); + expect( + result.stderr, + contains( + 'Native assets build failed.', + ), + ); + expect(result.exitCode, 255); + }); + }); +}