Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[native_assets_builder] Test hooks stopping after failure #1768

Merged
merged 3 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/native.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()}')),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <String>[];
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')),
);
});
});
}
Original file line number Diff line number Diff line change
@@ -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<String> arguments) async {
await build(arguments, (config, output) async {
// Does nothing, just depends on `package:fail_build`.
invokeFailBuildCode();
});
}
Original file line number Diff line number Diff line change
@@ -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() {}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions pkgs/native_assets_builder/test_data/fail_build/hook/build.dart
Original file line number Diff line number Diff line change
@@ -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<String> arguments) async {
print('Just here to fail the build!');
exit(1);
}
Original file line number Diff line number Diff line change
@@ -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() {}
18 changes: 18 additions & 0 deletions pkgs/native_assets_builder/test_data/fail_build/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
80 changes: 44 additions & 36 deletions pkgs/native_assets_builder/test_data/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -39,13 +44,22 @@
- 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
- fail_on_os_sdk_version_linker/hook/link.dart
- 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
Expand All @@ -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
Expand All @@ -75,20 +96,20 @@
- 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
- simple_link/assets/data_3.json
- 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
Expand All @@ -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
Expand All @@ -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