File tree Expand file tree Collapse file tree 8 files changed +82
-3
lines changed Expand file tree Collapse file tree 8 files changed +82
-3
lines changed Original file line number Diff line number Diff line change 1+ ## 1.0.1
2+
3+ - Ensure build fails if a build hook does not produce an output file.
4+
15## 1.0.0
26
37- Stable release.
Original file line number Diff line number Diff line change @@ -961,7 +961,17 @@ ${e.message}''');
961961 String packageName,
962962 ) async {
963963 final file = hookOutputFile;
964- final fileContents = await file.readAsString ();
964+ final String fileContents;
965+ try {
966+ fileContents = await file.readAsString ();
967+ } on FileSystemException catch (e) {
968+ logger.severe ('''
969+ Building assets for package:$packageName failed.
970+ Error reading ${hookOutputFile .uri .toFilePath ()}.
971+
972+ ${e .message }''' );
973+ return const Failure (HooksRunnerFailure .hookRun);
974+ }
965975 logger.info ('output.json contents:\n $fileContents ' );
966976 final Map <String , Object ?> hookOutputJson;
967977 try {
Original file line number Diff line number Diff line change @@ -87,6 +87,7 @@ Future<T> _runUnderFileLock<T>(
8787 if (! await file.exists ()) await file.create (recursive: true );
8888 final randomAccessFile = await file.open (mode: FileMode .write);
8989 var printed = false ;
90+ var errorFromCallback = false ;
9091 final stopwatch = Stopwatch ()..start ();
9192 while (timeout == null || stopwatch.elapsed < timeout) {
9293 try {
@@ -96,11 +97,19 @@ Future<T> _runUnderFileLock<T>(
9697 'Last acquired by ${Platform .resolvedExecutable } '
9798 '(pid $pid ) running ${Platform .script } on ${DateTime .now ()}.' ,
9899 );
99- return await callback ();
100+ try {
101+ return await callback ();
102+ } on FileSystemException {
103+ errorFromCallback = true ;
104+ rethrow ;
105+ }
100106 } finally {
101107 await randomAccessFile.unlock ();
102108 }
103109 } on FileSystemException {
110+ if (errorFromCallback) {
111+ rethrow ;
112+ }
104113 if (! printed) {
105114 logger? .finer (
106115 'Waiting to be able to obtain lock of directory: ${file .path }.' ,
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ name: hooks_runner
22description : >-
33 This package is the backend that invokes build hooks.
44
5- version : 1.0.0
5+ version : 1.0.1
66
77repository : https://github.com/dart-lang/native/tree/main/pkgs/hooks_runner
88
Original file line number Diff line number Diff line change 1+ // Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+ // for details. All rights reserved. Use of this source code is governed by a
3+ // BSD-style license that can be found in the LICENSE file.
4+
5+ import 'package:logging/logging.dart' ;
6+ import 'package:test/test.dart' ;
7+
8+ import '../helpers.dart' ;
9+ import 'helpers.dart' ;
10+
11+ const Timeout longTimeout = Timeout (Duration (minutes: 5 ));
12+
13+ void main () async {
14+ test ('no build output' , timeout: longTimeout, () async {
15+ await inTempDir ((tempUri) async {
16+ await copyTestProjects (targetUri: tempUri);
17+ final packageUri = tempUri.resolve ('no_build_output/' );
18+
19+ await runPubGet (workingDirectory: packageUri, logger: logger);
20+
21+ final logMessages = < String > [];
22+ final result = await build (
23+ packageUri,
24+ createCapturingLogger (logMessages, level: Level .SEVERE ),
25+ dartExecutable,
26+ buildAssetTypes: [],
27+ );
28+ expect (result.isFailure, isTrue);
29+ final fullLog = logMessages.join ('\n ' );
30+ expect (fullLog, contains ('Error reading' ));
31+ expect (fullLog, contains ('output.json' ));
32+ });
33+ });
34+ }
Original file line number Diff line number Diff line change 139139- native_subtract/src/native_subtract.h
140140- no_asset_for_link/hook/link.dart
141141- no_asset_for_link/pubspec.yaml
142+ - no_build_output/hook/build.dart
143+ - no_build_output/pubspec.yaml
142144- no_hook/lib/no_hook.dart
143145- no_hook/pubspec.yaml
144146- package_reading_metadata/hook/build.dart
Original file line number Diff line number Diff line change 1+ // Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+ // for details. All rights reserved. Use of this source code is governed by a
3+ // BSD-style license that can be found in the LICENSE file.
4+
5+ void main (List <String > arguments) {
6+ // This hook does nothing, and doesn't write an output file.
7+ }
Original file line number Diff line number Diff line change 1+ name : no_build_output
2+ description : A package with a build hook that does not produce any output.
3+ version : 0.1.0
4+
5+ publish_to : none
6+
7+ resolution : workspace
8+
9+ environment :
10+ sdk : ' >=3.9.0 <4.0.0'
11+
12+ dependencies :
13+ hooks : any
You can’t perform that action at this time.
0 commit comments