From ec8345b486077d0cfb51029084d769127f71ac38 Mon Sep 17 00:00:00 2001 From: Daco Harkes Date: Fri, 29 Nov 2024 11:43:41 +0100 Subject: [PATCH 1/3] [native_assets_builder] Test hooks stopping after failure --- .../build_runner_failure_test.dart | 40 ++++++++++ .../depend_on_fail_build/hook/build.dart | 13 +++ .../lib/depend_on_fail_build.dart | 5 ++ .../depend_on_fail_build/pubspec.yaml | 20 +++++ .../bin/depend_on_fail_build_app.dart | 9 +++ .../depend_on_fail_build_app/pubspec.yaml | 20 +++++ .../test_data/fail_build/hook/build.dart | 10 +++ .../test_data/fail_build/lib/fail_build.dart | 5 ++ .../test_data/fail_build/pubspec.yaml | 18 +++++ .../test_data/manifest.yaml | 80 ++++++++++--------- 10 files changed, 184 insertions(+), 36 deletions(-) create mode 100644 pkgs/native_assets_builder/test_data/depend_on_fail_build/hook/build.dart create mode 100644 pkgs/native_assets_builder/test_data/depend_on_fail_build/lib/depend_on_fail_build.dart create mode 100644 pkgs/native_assets_builder/test_data/depend_on_fail_build/pubspec.yaml create mode 100644 pkgs/native_assets_builder/test_data/depend_on_fail_build_app/bin/depend_on_fail_build_app.dart create mode 100644 pkgs/native_assets_builder/test_data/depend_on_fail_build_app/pubspec.yaml create mode 100644 pkgs/native_assets_builder/test_data/fail_build/hook/build.dart create mode 100644 pkgs/native_assets_builder/test_data/fail_build/lib/fail_build.dart create mode 100644 pkgs/native_assets_builder/test_data/fail_build/pubspec.yaml diff --git a/pkgs/native_assets_builder/test/build_runner/build_runner_failure_test.dart b/pkgs/native_assets_builder/test/build_runner/build_runner_failure_test.dart index b15331721..7b9566828 100644 --- a/pkgs/native_assets_builder/test/build_runner/build_runner_failure_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/build_runner_failure_test.dart @@ -102,4 +102,44 @@ void main() async { } }); }); + + test('do not build dependees after build failure', timeout: longTimeout, + () async { + await inTempDir((tempUri) async { + await copyTestProjects(targetUri: tempUri); + final packageUri = tempUri.resolve('depend_on_fail_build_app/'); + + await runPubGet( + workingDirectory: packageUri, + logger: logger, + ); + + final logMessages = []; + await build( + packageUri, + logger, + capturedLogs: logMessages, + dartExecutable, + supportedAssetTypes: [CodeAsset.type], + configValidator: validateCodeAssetBuildConfig, + buildValidator: validateCodeAssetBuildOutput, + applicationAssetValidator: validateCodeAssetInApplication, + ); + Matcher stringContainsBuildHookCompilation(String packageName) => + stringContainsInOrder([ + 'Running', + 'hook.dill', + '$packageName${Platform.pathSeparator}' + 'hook${Platform.pathSeparator}build.dart', + ]); + expect( + logMessages.join('\n'), + stringContainsBuildHookCompilation('fail_build'), + ); + expect( + logMessages.join('\n'), + isNot(stringContainsBuildHookCompilation('depends_on_fail_build')), + ); + }); + }); } diff --git a/pkgs/native_assets_builder/test_data/depend_on_fail_build/hook/build.dart b/pkgs/native_assets_builder/test_data/depend_on_fail_build/hook/build.dart new file mode 100644 index 000000000..bee5aadf4 --- /dev/null +++ b/pkgs/native_assets_builder/test_data/depend_on_fail_build/hook/build.dart @@ -0,0 +1,13 @@ +// Copyright (c) 2024, 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 'package:fail_build/fail_build.dart'; +import 'package:native_assets_cli/data_assets.dart'; + +void main(List arguments) async { + await build(arguments, (config, output) async { + // Does nothing, just depends on `package:fail_build`. + invokeFailBuildCode(); + }); +} diff --git a/pkgs/native_assets_builder/test_data/depend_on_fail_build/lib/depend_on_fail_build.dart b/pkgs/native_assets_builder/test_data/depend_on_fail_build/lib/depend_on_fail_build.dart new file mode 100644 index 000000000..0457dc633 --- /dev/null +++ b/pkgs/native_assets_builder/test_data/depend_on_fail_build/lib/depend_on_fail_build.dart @@ -0,0 +1,5 @@ +// Copyright (c) 2024, 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. + +void invokeDependOnFailBuildCode() {} diff --git a/pkgs/native_assets_builder/test_data/depend_on_fail_build/pubspec.yaml b/pkgs/native_assets_builder/test_data/depend_on_fail_build/pubspec.yaml new file mode 100644 index 000000000..253d3141f --- /dev/null +++ b/pkgs/native_assets_builder/test_data/depend_on_fail_build/pubspec.yaml @@ -0,0 +1,20 @@ +name: depend_on_fail_build +description: Has a dependency that fails to build. +version: 0.1.0 + +publish_to: none + +environment: + sdk: '>=3.3.0 <4.0.0' + +dependencies: + fail_build: + path: ../fail_build/ + # native_assets_cli: ^0.9.0 + native_assets_cli: + path: ../../../native_assets_cli/ + +dev_dependencies: + ffigen: ^8.0.2 + lints: ^3.0.0 + test: ^1.23.1 diff --git a/pkgs/native_assets_builder/test_data/depend_on_fail_build_app/bin/depend_on_fail_build_app.dart b/pkgs/native_assets_builder/test_data/depend_on_fail_build_app/bin/depend_on_fail_build_app.dart new file mode 100644 index 000000000..2abcfd041 --- /dev/null +++ b/pkgs/native_assets_builder/test_data/depend_on_fail_build_app/bin/depend_on_fail_build_app.dart @@ -0,0 +1,9 @@ +// Copyright (c) 2024, 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 'package:depend_on_fail_build/depend_on_fail_build.dart'; + +void main() { + invokeDependOnFailBuildCode(); +} diff --git a/pkgs/native_assets_builder/test_data/depend_on_fail_build_app/pubspec.yaml b/pkgs/native_assets_builder/test_data/depend_on_fail_build_app/pubspec.yaml new file mode 100644 index 000000000..ddb0ec04d --- /dev/null +++ b/pkgs/native_assets_builder/test_data/depend_on_fail_build_app/pubspec.yaml @@ -0,0 +1,20 @@ +name: depend_on_fail_build_app +description: Has a dependency that has a dependency that fails to build. +version: 0.1.0 + +publish_to: none + +environment: + sdk: '>=3.3.0 <4.0.0' + +dependencies: + depend_on_fail_build: + path: ../depend_on_fail_build/ + # native_assets_cli: ^0.9.0 + native_assets_cli: + path: ../../../native_assets_cli/ + +dev_dependencies: + ffigen: ^8.0.2 + lints: ^3.0.0 + test: ^1.23.1 diff --git a/pkgs/native_assets_builder/test_data/fail_build/hook/build.dart b/pkgs/native_assets_builder/test_data/fail_build/hook/build.dart new file mode 100644 index 000000000..790b93525 --- /dev/null +++ b/pkgs/native_assets_builder/test_data/fail_build/hook/build.dart @@ -0,0 +1,10 @@ +// Copyright (c) 2024, 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'; + +void main(List arguments) async { + print('Just here to fail the build!'); + exit(1); +} diff --git a/pkgs/native_assets_builder/test_data/fail_build/lib/fail_build.dart b/pkgs/native_assets_builder/test_data/fail_build/lib/fail_build.dart new file mode 100644 index 000000000..d6eb1aacc --- /dev/null +++ b/pkgs/native_assets_builder/test_data/fail_build/lib/fail_build.dart @@ -0,0 +1,5 @@ +// Copyright (c) 2024, 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. + +void invokeFailBuildCode() {} diff --git a/pkgs/native_assets_builder/test_data/fail_build/pubspec.yaml b/pkgs/native_assets_builder/test_data/fail_build/pubspec.yaml new file mode 100644 index 000000000..b04fe9a5d --- /dev/null +++ b/pkgs/native_assets_builder/test_data/fail_build/pubspec.yaml @@ -0,0 +1,18 @@ +name: fail_build +description: Always fails to build +version: 0.1.0 + +publish_to: none + +environment: + sdk: '>=3.3.0 <4.0.0' + +dependencies: + # native_assets_cli: ^0.9.0 + native_assets_cli: + path: ../../../native_assets_cli/ + +dev_dependencies: + ffigen: ^8.0.2 + lints: ^3.0.0 + test: ^1.23.1 diff --git a/pkgs/native_assets_builder/test_data/manifest.yaml b/pkgs/native_assets_builder/test_data/manifest.yaml index 6bcdcd32c..9ed41c7c9 100644 --- a/pkgs/native_assets_builder/test_data/manifest.yaml +++ b/pkgs/native_assets_builder/test_data/manifest.yaml @@ -28,6 +28,11 @@ - cyclic_package_2/pubspec.yaml - dart_app/bin/dart_app.dart - dart_app/pubspec.yaml +- depend_on_fail_build_app/bin/depend_on_fail_build_app.dart +- depend_on_fail_build_app/pubspec.yaml +- depend_on_fail_build/hook/build.dart +- depend_on_fail_build/lib/depend_on_fail_build.dart +- depend_on_fail_build/pubspec.yaml - drop_dylib_link/bin/drop_dylib_link.dart - drop_dylib_link/hook/build.dart - drop_dylib_link/hook/link.dart @@ -39,6 +44,9 @@ - drop_dylib_link/src/native_add.h - drop_dylib_link/src/native_multiply.c - drop_dylib_link/src/native_multiply.h +- fail_build/hook/build.dart +- fail_build/lib/fail_build.dart +- fail_build/pubspec.yaml - fail_on_os_sdk_version_link/assets/data.json - fail_on_os_sdk_version_link/hook/build.dart - fail_on_os_sdk_version_link/pubspec.yaml @@ -46,6 +54,12 @@ - fail_on_os_sdk_version_linker/pubspec.yaml - fail_on_os_sdk_version/hook/build.dart - fail_on_os_sdk_version/pubspec.yaml +- native_add_duplicate/bin/native_add_duplicate.dart +- native_add_duplicate/hook/build.dart +- native_add_duplicate/hook/link.dart +- native_add_duplicate/pubspec.yaml +- native_add_duplicate/src/native_add.c +- native_add_duplicate/src/native_add.h - native_add/ffigen.yaml - native_add/hook/build.dart - native_add/lib/native_add.dart @@ -55,12 +69,19 @@ - native_add/src/native_add.c - native_add/src/native_add.h - native_add/test/native_add_test.dart -- native_add_duplicate/bin/native_add_duplicate.dart -- native_add_duplicate/hook/build.dart -- native_add_duplicate/hook/link.dart -- native_add_duplicate/pubspec.yaml -- native_add_duplicate/src/native_add.c -- native_add_duplicate/src/native_add.h +- native_dynamic_linking/bin/native_dynamic_linking.dart +- native_dynamic_linking/ffigen.yaml +- native_dynamic_linking/hook/build.dart +- native_dynamic_linking/lib/add.dart +- native_dynamic_linking/pubspec.yaml +- native_dynamic_linking/README.md +- native_dynamic_linking/src/add.c +- native_dynamic_linking/src/add.h +- native_dynamic_linking/src/debug.c +- native_dynamic_linking/src/debug.h +- native_dynamic_linking/src/math.c +- native_dynamic_linking/src/math.h +- native_dynamic_linking/test/add_test.dart - native_subtract/ffigen.yaml - native_subtract/hook/build.dart - native_subtract/lib/native_subtract.dart @@ -75,6 +96,13 @@ - package_reading_metadata/pubspec.yaml - package_with_metadata/hook/build.dart - package_with_metadata/pubspec.yaml +- simple_data_asset/assets/test_asset.txt +- simple_data_asset/bin/deep_modify_data_asset.dart.debug +- simple_data_asset/bin/modify_data_asset.dart.debug +- simple_data_asset/bin/simple_data_asset.dart.debug +- simple_data_asset/hook/build.dart +- simple_data_asset/pubspec.yaml +- simple_data_asset/README.md - simple_link/assets/data_0.json - simple_link/assets/data_1.json - simple_link/assets/data_2.json @@ -82,13 +110,6 @@ - simple_link/hook/build.dart - simple_link/hook/link.dart - simple_link/pubspec.yaml -- simple_data_asset/pubspec.yaml -- simple_data_asset/assets/test_asset.txt -- simple_data_asset/README.md -- simple_data_asset/hook/build.dart -- simple_data_asset/bin/simple_data_asset.dart.debug -- simple_data_asset/bin/modify_data_asset.dart.debug -- simple_data_asset/bin/deep_modify_data_asset.dart.debug - some_dev_dep/bin/some_dev_dep.dart - some_dev_dep/pubspec.yaml - transformer/data/data0.json @@ -103,20 +124,20 @@ - transformer/data/data9.json - transformer/hook/build.dart - transformer/lib/src/transform.dart -- transformer/tool/generate_data.dart - transformer/pubspec.yaml -- treeshaking_native_libs/pubspec.yaml -- treeshaking_native_libs/lib/treeshaking_native_libs.dart -- treeshaking_native_libs/lib/src/treeshaking_native_libs.dart +- transformer/tool/generate_data.dart +- treeshaking_native_libs/bin/treeshaking_native_libs.dart +- treeshaking_native_libs/ffigen.yaml +- treeshaking_native_libs/hook/build.dart +- treeshaking_native_libs/hook/link.dart - treeshaking_native_libs/lib/src/treeshaking_native_libs_bindings_generated.dart -- treeshaking_native_libs/src/native_add.h -- treeshaking_native_libs/src/native_multiply.h +- treeshaking_native_libs/lib/src/treeshaking_native_libs.dart +- treeshaking_native_libs/lib/treeshaking_native_libs.dart +- treeshaking_native_libs/pubspec.yaml - treeshaking_native_libs/src/native_add.c +- treeshaking_native_libs/src/native_add.h - treeshaking_native_libs/src/native_multiply.c -- treeshaking_native_libs/hook/link.dart -- treeshaking_native_libs/hook/build.dart -- treeshaking_native_libs/bin/treeshaking_native_libs.dart -- treeshaking_native_libs/ffigen.yaml +- treeshaking_native_libs/src/native_multiply.h - wrong_build_output_2/hook/build.dart - wrong_build_output_2/pubspec.yaml - wrong_build_output_3/hook/build.dart @@ -127,16 +148,3 @@ - wrong_linker/pubspec.yaml - wrong_namespace_asset/hook/build.dart - wrong_namespace_asset/pubspec.yaml -- native_dynamic_linking/bin/native_dynamic_linking.dart -- native_dynamic_linking/hook/build.dart -- native_dynamic_linking/lib/add.dart -- native_dynamic_linking/src/add.c -- native_dynamic_linking/src/add.h -- native_dynamic_linking/src/debug.c -- native_dynamic_linking/src/debug.h -- native_dynamic_linking/src/math.c -- native_dynamic_linking/src/math.h -- native_dynamic_linking/test/add_test.dart -- native_dynamic_linking/ffigen.yaml -- native_dynamic_linking/pubspec.yaml -- native_dynamic_linking/README.md From 759d3781cdbe0f4bae5dd785238d160cd5441a46 Mon Sep 17 00:00:00 2001 From: Daco Harkes Date: Fri, 29 Nov 2024 11:44:40 +0100 Subject: [PATCH 2/3] remove print from test --- .../test/build_runner/build_runner_caching_test.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/pkgs/native_assets_builder/test/build_runner/build_runner_caching_test.dart b/pkgs/native_assets_builder/test/build_runner/build_runner_caching_test.dart index 42c5e4939..5b31cae41 100644 --- a/pkgs/native_assets_builder/test/build_runner/build_runner_caching_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/build_runner_caching_test.dart @@ -62,7 +62,6 @@ void main() async { applicationAssetValidator: validateCodeAssetInApplication, ))!; final hookUri = packageUri.resolve('hook/build.dart'); - print(logMessages.join('\n')); expect( logMessages.join('\n'), isNot(contains('Recompiling ${hookUri.toFilePath()}')), From 6b899dfa97b4a43c6c046d53aa5c44fbc79e8d03 Mon Sep 17 00:00:00 2001 From: Daco Harkes Date: Fri, 29 Nov 2024 11:55:52 +0100 Subject: [PATCH 3/3] run pub get on ci --- .github/workflows/native.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/native.yaml b/.github/workflows/native.yaml index 21094bde1..4e2396cf5 100644 --- a/.github/workflows/native.yaml +++ b/.github/workflows/native.yaml @@ -120,6 +120,15 @@ jobs: - run: dart pub get -C example/link/app_with_asset_treeshaking/ if: ${{ matrix.package == 'native_assets_cli' }} + - run: dart pub get -C test_data/fail_build/ + if: ${{ matrix.package == 'native_assets_builder' }} + + - run: dart pub get -C test_data/depend_on_fail_build/ + if: ${{ matrix.package == 'native_assets_builder' }} + + - run: dart pub get -C test_data/depend_on_fail_build_app/ + if: ${{ matrix.package == 'native_assets_builder' }} + - run: dart analyze --fatal-infos # Run on dev to ensure we're not depending on deprecated SDK things.