@@ -152,6 +152,8 @@ class NativeAssetsBuildRunner {
152
152
),
153
153
],
154
154
null ,
155
+ buildDirUri,
156
+ outDirUri,
155
157
);
156
158
if (result == null ) return null ;
157
159
final (hookOutput, hookDeps) = result;
@@ -253,6 +255,8 @@ class NativeAssetsBuildRunner {
253
255
),
254
256
],
255
257
resourceIdentifiers,
258
+ buildDirUri,
259
+ outDirUri,
256
260
);
257
261
if (result == null ) return null ;
258
262
final (hookOutput, hookDeps) = result;
@@ -295,7 +299,7 @@ class NativeAssetsBuildRunner {
295
299
await outDir.create (recursive: true );
296
300
}
297
301
final outDirSharedUri = packageLayout.dartToolNativeAssetsBuilder.resolve (
298
- 'shared/${package .name }/$hook /' ,
302
+ 'shared/${package .name }/${ hook . name } /' ,
299
303
);
300
304
final outDirShared = _fileSystem.directory (outDirSharedUri);
301
305
if (! await outDirShared.exists ()) {
@@ -310,111 +314,112 @@ class NativeAssetsBuildRunner {
310
314
HookInput input,
311
315
_HookValidator validator,
312
316
Uri ? resources,
313
- ) async {
314
- final outDir = input. outputDirectory;
315
- return await runUnderDirectoriesLock (
316
- _fileSystem,
317
- [
318
- _fileSystem.directory (input.outputDirectoryShared).parent.uri,
319
- _fileSystem.directory (input. outputDirectory).parent.uri,
320
- ],
321
- timeout: singleHookTimeout,
322
- logger: logger,
323
- () async {
324
- final hookCompileResult = await _compileHookForPackageCached (
325
- input.packageName,
326
- input.outputDirectory ,
327
- input.packageRoot.resolve ('hook/${hook .scriptName }' ),
328
- );
329
- if (hookCompileResult == null ) {
330
- return null ;
331
- }
332
- final (hookKernelFile, hookHashes) = hookCompileResult;
317
+ Uri buildDirUri,
318
+ Uri outputDirectory,
319
+ ) async => await runUnderDirectoriesLock (
320
+ _fileSystem,
321
+ [
322
+ _fileSystem.directory (input.outputDirectoryShared).parent.uri,
323
+ _fileSystem.directory (outputDirectory).parent.uri,
324
+ ],
325
+ timeout: singleHookTimeout,
326
+ logger: logger,
327
+ () async {
328
+ final hookCompileResult = await _compileHookForPackageCached (
329
+ input.packageName,
330
+ buildDirUri ,
331
+ input.packageRoot.resolve ('hook/${hook .scriptName }' ),
332
+ );
333
+ if (hookCompileResult == null ) {
334
+ return null ;
335
+ }
336
+ final (hookKernelFile, hookHashes) = hookCompileResult;
333
337
334
- final buildOutputFile = _fileSystem.file (input.outputFile);
335
- final buildOutputFileDeprecated = _fileSystem
336
- // ignore: deprecated_member_use
337
- .file (input. outputDirectory.resolve (hook.outputNameDeprecated));
338
+ final buildOutputFile = _fileSystem.file (input.outputFile);
339
+ final buildOutputFileDeprecated = _fileSystem
340
+ // ignore: deprecated_member_use
341
+ .file (outputDirectory.resolve (hook.outputNameDeprecated));
338
342
339
- final dependenciesHashFile = input.outputDirectory .resolve (
340
- '../ dependencies.dependencies_hash_file.json' ,
341
- );
342
- final dependenciesHashes = DependenciesHashFile (
343
- _fileSystem,
344
- fileUri: dependenciesHashFile,
345
- );
346
- final lastModifiedCutoffTime = DateTime .now ();
347
- if ((buildOutputFile.existsSync () ||
348
- buildOutputFileDeprecated.existsSync ()) &&
349
- await dependenciesHashes.exists ()) {
350
- late final HookOutput output;
351
- try {
352
- output = _readHookOutputFromUri (
353
- hook,
354
- buildOutputFile,
355
- buildOutputFileDeprecated,
356
- );
357
- } on FormatException catch (e) {
358
- logger.severe ('''
343
+ final dependenciesHashFile = buildDirUri .resolve (
344
+ ' dependencies.dependencies_hash_file.json' ,
345
+ );
346
+ final dependenciesHashes = DependenciesHashFile (
347
+ _fileSystem,
348
+ fileUri: dependenciesHashFile,
349
+ );
350
+ final lastModifiedCutoffTime = DateTime .now ();
351
+ if ((buildOutputFile.existsSync () ||
352
+ buildOutputFileDeprecated.existsSync ()) &&
353
+ await dependenciesHashes.exists ()) {
354
+ late final HookOutput output;
355
+ try {
356
+ output = _readHookOutputFromUri (
357
+ hook,
358
+ buildOutputFile,
359
+ buildOutputFileDeprecated,
360
+ );
361
+ } on FormatException catch (e) {
362
+ logger.severe ('''
359
363
Building assets for package:${input .packageName } failed.
360
364
${input .outputFile .toFilePath ()} contained a format error.
361
365
362
366
Contents: ${buildOutputFile .readAsStringSync ()}.
363
367
${e .message }
364
368
''' );
365
- return null ;
366
- }
369
+ return null ;
370
+ }
367
371
368
- final outdatedDependency = await dependenciesHashes
369
- .findOutdatedDependency (hookEnvironment);
370
- if (outdatedDependency == null ) {
371
- logger.info (
372
- 'Skipping ${hook .name } for ${input .packageName }'
373
- ' in ${outDir .toFilePath ()}.'
374
- ' Last build on ${output .timestamp }.' ,
375
- );
376
- // All build flags go into [outDir]. Therefore we do not have to
377
- // check here whether the input is equal.
378
- return (output, hookHashes.fileSystemEntities);
379
- }
372
+ final outdatedDependency = await dependenciesHashes
373
+ .findOutdatedDependency (hookEnvironment);
374
+ if (outdatedDependency == null ) {
380
375
logger.info (
381
- 'Rerunning ${hook .name } for ${input .packageName }'
382
- ' in ${outDir .toFilePath ()}. $outdatedDependency ' ,
376
+ 'Skipping ${hook .name } for ${input .packageName }'
377
+ ' in ${buildDirUri .toFilePath ()}.'
378
+ ' Last build on ${output .timestamp }.' ,
383
379
);
380
+ // All build flags go into [outDir]. Therefore we do not have to
381
+ // check here whether the input is equal.
382
+ return (output, hookHashes.fileSystemEntities);
384
383
}
384
+ logger.info (
385
+ 'Rerunning ${hook .name } for ${input .packageName }'
386
+ ' in ${buildDirUri .toFilePath ()}. $outdatedDependency ' ,
387
+ );
388
+ }
385
389
386
- final result = await _runHookForPackage (
387
- hook,
388
- input,
389
- validator,
390
- resources,
391
- hookKernelFile,
390
+ final result = await _runHookForPackage (
391
+ hook,
392
+ input,
393
+ validator,
394
+ resources,
395
+ hookKernelFile,
396
+ hookEnvironment,
397
+ buildDirUri,
398
+ outputDirectory,
399
+ );
400
+ if (result == null ) {
401
+ if (await dependenciesHashes.exists ()) {
402
+ await dependenciesHashes.delete ();
403
+ }
404
+ return null ;
405
+ } else {
406
+ final modifiedDuringBuild = await dependenciesHashes.hashDependencies (
407
+ [
408
+ ...result.dependencies,
409
+ // Also depend on the compiled hook. Don't depend on the sources,
410
+ // if only whitespace changes, we don't need to rerun the hook.
411
+ hookKernelFile.uri,
412
+ ],
413
+ lastModifiedCutoffTime,
392
414
hookEnvironment,
393
415
);
394
- if (result == null ) {
395
- if (await dependenciesHashes.exists ()) {
396
- await dependenciesHashes.delete ();
397
- }
398
- return null ;
399
- } else {
400
- final modifiedDuringBuild = await dependenciesHashes.hashDependencies (
401
- [
402
- ...result.dependencies,
403
- // Also depend on the compiled hook. Don't depend on the sources,
404
- // if only whitespace changes, we don't need to rerun the hook.
405
- hookKernelFile.uri,
406
- ],
407
- lastModifiedCutoffTime,
408
- hookEnvironment,
409
- );
410
- if (modifiedDuringBuild != null ) {
411
- logger.severe ('File modified during build. Build must be rerun.' );
412
- }
416
+ if (modifiedDuringBuild != null ) {
417
+ logger.severe ('File modified during build. Build must be rerun.' );
413
418
}
414
- return (result, hookHashes.fileSystemEntities);
415
- },
416
- );
417
- }
419
+ }
420
+ return (result, hookHashes.fileSystemEntities);
421
+ },
422
+ );
418
423
419
424
/// The list of environment variables used if [hookEnvironment] is not passed
420
425
/// in.
@@ -441,8 +446,10 @@ ${e.message}
441
446
Uri ? resources,
442
447
File hookKernelFile,
443
448
Map <String , String > environment,
449
+ Uri buildDirUri,
450
+ Uri outputDirectory,
444
451
) async {
445
- final inputFile = input.outputDirectory. resolve ('../ input.json' );
452
+ final inputFile = buildDirUri. resolve ('input.json' );
446
453
final inputFileContents = const JsonEncoder .withIndent (
447
454
' ' ,
448
455
).convert (input.json);
@@ -456,7 +463,7 @@ ${e.message}
456
463
}
457
464
final hookOutputUriDeprecated =
458
465
// ignore: deprecated_member_use
459
- input. outputDirectory.resolve (hook.outputNameDeprecated);
466
+ outputDirectory.resolve (hook.outputNameDeprecated);
460
467
final hookOutputFileDeprecated = _fileSystem.file (hookOutputUriDeprecated);
461
468
if (await hookOutputFileDeprecated.exists ()) {
462
469
// Ensure we'll never read outdated build results.
@@ -469,7 +476,7 @@ ${e.message}
469
476
'--config=${inputFile .toFilePath ()}' ,
470
477
if (resources != null ) resources.toFilePath (),
471
478
];
472
- final wrappedLogger = await _createFileStreamingLogger (input );
479
+ final wrappedLogger = await _createFileStreamingLogger (buildDirUri );
473
480
final workingDirectory = input.packageRoot;
474
481
final result = await runProcess (
475
482
filesystem: _fileSystem,
@@ -539,14 +546,10 @@ ${e.message}
539
546
}
540
547
}
541
548
542
- Future <Logger > _createFileStreamingLogger (HookInput input) async {
543
- final stdoutFile = _fileSystem.file (
544
- input.outputDirectory.resolve ('../stdout.txt' ),
545
- );
549
+ Future <Logger > _createFileStreamingLogger (Uri buildDirUri) async {
550
+ final stdoutFile = _fileSystem.file (buildDirUri.resolve ('stdout.txt' ));
546
551
await stdoutFile.writeAsString ('' );
547
- final stderrFile = _fileSystem.file (
548
- input.outputDirectory.resolve ('../stderr.txt' ),
549
- );
552
+ final stderrFile = _fileSystem.file (buildDirUri.resolve ('stderr.txt' ));
550
553
await stderrFile.writeAsString ('' );
551
554
final wrappedLogger =
552
555
Logger .detached ('' )
@@ -590,21 +593,19 @@ ${e.message}
590
593
Future <(File kernelFile, DependenciesHashFile cacheFile)?>
591
594
_compileHookForPackageCached (
592
595
String packageName,
593
- Uri outputDirectory ,
596
+ Uri buildDirUri ,
594
597
Uri scriptUri,
595
598
) async {
596
599
// Don't invalidate cache with environment changes.
597
600
final environmentForCaching = < String , String > {};
598
- final packageConfigHashable = outputDirectory .resolve (
599
- '../ package_config_hashable.json' ,
601
+ final packageConfigHashable = buildDirUri .resolve (
602
+ 'package_config_hashable.json' ,
600
603
);
601
604
await _makeHashablePackageConfig (packageConfigHashable);
602
- final kernelFile = _fileSystem.file (
603
- outputDirectory.resolve ('../hook.dill' ),
604
- );
605
- final depFile = _fileSystem.file (outputDirectory.resolve ('../hook.dill.d' ));
606
- final dependenciesHashFile = outputDirectory.resolve (
607
- '../hook.dependencies_hash_file.json' ,
605
+ final kernelFile = _fileSystem.file (buildDirUri.resolve ('hook.dill' ));
606
+ final depFile = _fileSystem.file (buildDirUri.resolve ('hook.dill.d' ));
607
+ final dependenciesHashFile = buildDirUri.resolve (
608
+ 'hook.dependencies_hash_file.json' ,
608
609
);
609
610
final dependenciesHashes = DependenciesHashFile (
610
611
_fileSystem,
0 commit comments