@@ -6,6 +6,7 @@ import 'dart:async';
6
6
import 'dart:convert' ;
7
7
import 'dart:io' ;
8
8
9
+ import 'package:collection/collection.dart' ;
9
10
import 'package:logging/logging.dart' ;
10
11
import 'package:native_assets_cli/native_assets_cli_internal.dart' ;
11
12
import 'package:package_config/package_config.dart' ;
@@ -96,7 +97,6 @@ class NativeAssetsBuildRunner {
96
97
required OS targetOS,
97
98
required BuildMode buildMode,
98
99
required Uri workingDirectory,
99
- required bool includeParentEnvironment,
100
100
PackageLayout ? packageLayout,
101
101
String ? runPackageName,
102
102
required List <String > supportedAssetTypes,
@@ -165,7 +165,6 @@ class NativeAssetsBuildRunner {
165
165
buildValidator (config as BuildConfig , output as BuildOutput ),
166
166
packageLayout.packageConfigUri,
167
167
workingDirectory,
168
- includeParentEnvironment,
169
168
null ,
170
169
packageLayout,
171
170
);
@@ -205,7 +204,6 @@ class NativeAssetsBuildRunner {
205
204
required BuildMode buildMode,
206
205
required Uri workingDirectory,
207
206
required ApplicationAssetValidator applicationAssetValidator,
208
- required bool includeParentEnvironment,
209
207
PackageLayout ? packageLayout,
210
208
Uri ? resourceIdentifiers,
211
209
String ? runPackageName,
@@ -269,7 +267,6 @@ class NativeAssetsBuildRunner {
269
267
linkValidator (config as LinkConfig , output as LinkOutput ),
270
268
packageLayout.packageConfigUri,
271
269
workingDirectory,
272
- includeParentEnvironment,
273
270
resourceIdentifiers,
274
271
packageLayout,
275
272
);
@@ -330,7 +327,6 @@ class NativeAssetsBuildRunner {
330
327
required OS targetOS,
331
328
required Uri workingDirectory,
332
329
required bool linkingEnabled,
333
- required bool includeParentEnvironment,
334
330
PackageLayout ? packageLayout,
335
331
String ? runPackageName,
336
332
required List <String > supportedAssetTypes,
@@ -341,7 +337,6 @@ class NativeAssetsBuildRunner {
341
337
validator: (HookConfig config, HookOutput output) =>
342
338
buildValidator (config as BuildConfig , output as BuildOutput ),
343
339
workingDirectory: workingDirectory,
344
- includeParentEnvironment: includeParentEnvironment,
345
340
packageLayout: packageLayout,
346
341
runPackageName: runPackageName,
347
342
supportedAssetTypes: supportedAssetTypes,
@@ -353,7 +348,6 @@ class NativeAssetsBuildRunner {
353
348
required _HookValidator validator,
354
349
required OS targetOS,
355
350
required Uri workingDirectory,
356
- required bool includeParentEnvironment,
357
351
PackageLayout ? packageLayout,
358
352
String ? runPackageName,
359
353
required bool linkingEnabled,
@@ -420,7 +414,6 @@ class NativeAssetsBuildRunner {
420
414
config.packageRoot.resolve ('hook/${hook .scriptName }' ),
421
415
packageConfigUri,
422
416
workingDirectory,
423
- includeParentEnvironment,
424
417
);
425
418
if (! compileSuccess) return null ;
426
419
@@ -438,7 +431,6 @@ class NativeAssetsBuildRunner {
438
431
validator,
439
432
packageConfigUri,
440
433
workingDirectory,
441
- includeParentEnvironment,
442
434
null ,
443
435
hookKernelFile,
444
436
packageLayout! ,
@@ -458,7 +450,6 @@ class NativeAssetsBuildRunner {
458
450
_HookValidator validator,
459
451
Uri packageConfigUri,
460
452
Uri workingDirectory,
461
- bool includeParentEnvironment,
462
453
Uri ? resources,
463
454
PackageLayout packageLayout,
464
455
) async {
@@ -481,7 +472,6 @@ class NativeAssetsBuildRunner {
481
472
config.packageRoot.resolve ('hook/${hook .scriptName }' ),
482
473
packageConfigUri,
483
474
workingDirectory,
484
- includeParentEnvironment,
485
475
);
486
476
if (! compileSuccess) {
487
477
return null ;
@@ -496,7 +486,12 @@ class NativeAssetsBuildRunner {
496
486
final dependenciesHashes =
497
487
DependenciesHashFile (file: dependenciesHashFile);
498
488
final lastModifiedCutoffTime = DateTime .now ();
499
- if (buildOutputFile.existsSync () && dependenciesHashFile.existsSync ()) {
489
+ final environmentFile = File .fromUri (
490
+ config.outputDirectory.resolve ('../environment.json' ),
491
+ );
492
+ if (buildOutputFile.existsSync () &&
493
+ dependenciesHashFile.existsSync () &&
494
+ environmentFile.existsSync ()) {
500
495
late final HookOutput output;
501
496
try {
502
497
output = _readHookOutputFromUri (hook, buildOutputFile);
@@ -510,9 +505,15 @@ ${e.message}
510
505
''' );
511
506
return null ;
512
507
}
508
+
513
509
final outdatedFile =
514
510
await dependenciesHashes.findOutdatedFileSystemEntity ();
515
- if (outdatedFile == null ) {
511
+ final environmentChanged = (! await environmentFile.exists ()) ||
512
+ ! const MapEquality <String , String >().equals (
513
+ (json.decode (await environmentFile.readAsString ()) as Map )
514
+ .cast <String , String >(),
515
+ Platform .environment);
516
+ if (outdatedFile == null && ! environmentChanged) {
516
517
logger.info (
517
518
'Skipping ${hook .name } for ${config .packageName }'
518
519
' in ${outDir .toFilePath ()}.'
@@ -522,11 +523,19 @@ ${e.message}
522
523
// check here whether the config is equal.
523
524
return output;
524
525
}
525
- logger.info (
526
- 'Rerunning ${hook .name } for ${config .packageName }'
527
- ' in ${outDir .toFilePath ()}.'
528
- ' ${outdatedFile .toFilePath ()} changed.' ,
529
- );
526
+ if (outdatedFile != null ) {
527
+ logger.info (
528
+ 'Rerunning ${hook .name } for ${config .packageName }'
529
+ ' in ${outDir .toFilePath ()}.'
530
+ ' ${outdatedFile .toFilePath ()} changed.' ,
531
+ );
532
+ } else {
533
+ logger.info (
534
+ 'Rerunning ${hook .name } for ${config .packageName }'
535
+ ' in ${outDir .toFilePath ()}.'
536
+ ' The environment variables changed.' ,
537
+ );
538
+ }
530
539
}
531
540
532
541
final result = await _runHookForPackage (
@@ -535,7 +544,6 @@ ${e.message}
535
544
validator,
536
545
packageConfigUri,
537
546
workingDirectory,
538
- includeParentEnvironment,
539
547
resources,
540
548
hookKernelFile,
541
549
packageLayout,
@@ -545,6 +553,9 @@ ${e.message}
545
553
await dependenciesHashFile.delete ();
546
554
}
547
555
} else {
556
+ await environmentFile.writeAsString (
557
+ json.encode (Platform .environment),
558
+ );
548
559
final modifiedDuringBuild =
549
560
await dependenciesHashes.hashFilesAndDirectories (
550
561
[
@@ -569,7 +580,6 @@ ${e.message}
569
580
_HookValidator validator,
570
581
Uri packageConfigUri,
571
582
Uri workingDirectory,
572
- bool includeParentEnvironment,
573
583
Uri ? resources,
574
584
File hookKernelFile,
575
585
PackageLayout packageLayout,
@@ -597,7 +607,6 @@ ${e.message}
597
607
executable: dartExecutable,
598
608
arguments: arguments,
599
609
logger: logger,
600
- includeParentEnvironment: includeParentEnvironment,
601
610
);
602
611
603
612
var deleteOutputIfExists = false ;
@@ -680,7 +689,6 @@ ${e.message}
680
689
Uri scriptUri,
681
690
Uri packageConfigUri,
682
691
Uri workingDirectory,
683
- bool includeParentEnvironment,
684
692
) async {
685
693
final kernelFile = File .fromUri (
686
694
outputDirectory.resolve ('../hook.dill' ),
@@ -717,7 +725,6 @@ ${e.message}
717
725
scriptUri,
718
726
packageConfigUri,
719
727
workingDirectory,
720
- includeParentEnvironment,
721
728
kernelFile,
722
729
depFile,
723
730
);
@@ -760,7 +767,6 @@ ${e.message}
760
767
Uri scriptUri,
761
768
Uri packageConfigUri,
762
769
Uri workingDirectory,
763
- bool includeParentEnvironment,
764
770
File kernelFile,
765
771
File depFile,
766
772
) async {
@@ -777,7 +783,6 @@ ${e.message}
777
783
executable: dartExecutable,
778
784
arguments: compileArguments,
779
785
logger: logger,
780
- includeParentEnvironment: includeParentEnvironment,
781
786
);
782
787
var success = true ;
783
788
if (compileResult.exitCode != 0 ) {
0 commit comments