@@ -80,7 +80,7 @@ class NativeAssetsBuildRunner {
8080 singleHookTimeout = singleHookTimeout ?? const Duration (minutes: 5 ),
8181 hookEnvironment =
8282 hookEnvironment ??
83- filteredEnvironment (hookEnvironmentVariablesFilter ) {
83+ filteredEnvironment (includeHookEnvironmentVariable ) {
8484 _fileSystem = TracingFileSystem (fileSystem, _task);
8585 }
8686
@@ -538,23 +538,31 @@ class NativeAssetsBuildRunner {
538538 ),
539539 );
540540
541- /// The list of environment variables used if [hookEnvironment] is not passed
542- /// in.
543- /// This allowlist lists environment variables needed to run mainstream
544- /// compilers.
545- static const hookEnvironmentVariablesFilter = {
546- 'ANDROID_HOME' , // Needed for the NDK.
547- 'HOME' , // Needed to find tools in default install locations.
548- 'PATH' , // Needed to invoke native tools.
549- 'PROGRAMDATA' , // Needed for vswhere.exe.
550- 'SYSTEMDRIVE' , // Needed for CMake.
551- 'SYSTEMROOT' , // Needed for process invocations on Windows.
552- 'TEMP' , // Needed for temp dirs in Dart process.
553- 'TMP' , // Needed for temp dirs in Dart process.
554- 'TMPDIR' , // Needed for temp dirs in Dart process.
555- 'USERPROFILE' , // Needed to find tools in default install locations.
556- 'WINDIR' , // Needed for CMake.
557- };
541+ /// Determines whether to allow an environment variable through
542+ /// if [hookEnvironment] is not passed in.
543+ ///
544+ /// This allows environment variables needed to run mainstream compilers.
545+ static bool includeHookEnvironmentVariable (String environmentVariableName) {
546+ const staticVariablesFilter = {
547+ 'ANDROID_HOME' , // Needed for the NDK.
548+ 'HOME' , // Needed to find tools in default install locations.
549+ 'PATH' , // Needed to invoke native tools.
550+ 'PROGRAMDATA' , // Needed for vswhere.exe.
551+ 'SYSTEMDRIVE' , // Needed for CMake.
552+ 'SYSTEMROOT' , // Needed for process invocations on Windows.
553+ 'TEMP' , // Needed for temp dirs in Dart process.
554+ 'TMP' , // Needed for temp dirs in Dart process.
555+ 'TMPDIR' , // Needed for temp dirs in Dart process.
556+ 'USERPROFILE' , // Needed to find tools in default install locations.
557+ 'WINDIR' , // Needed for CMake.
558+ };
559+ const variablePrefixesFilter = {
560+ 'NIX_' , // Needed for Nix-installed toolchains.
561+ };
562+
563+ return staticVariablesFilter.contains (environmentVariableName) ||
564+ variablePrefixesFilter.any (environmentVariableName.startsWith);
565+ }
558566
559567 Future <Result <HookOutput , HooksRunnerFailure >> _runHookForPackage (
560568 Hook hook,
@@ -1198,7 +1206,7 @@ Future<List<Uri>> _readDepFile(File depFile) async {
11981206}
11991207
12001208@internal
1201- Map <String , String > filteredEnvironment (Set < String > allowList ) => {
1209+ Map <String , String > filteredEnvironment (bool Function ( String ) include ) => {
12021210 for (final entry in Platform .environment.entries)
1203- if (allowList. contains (entry.key.toUpperCase ())) entry.key: entry.value,
1211+ if (include (entry.key.toUpperCase ())) entry.key: entry.value,
12041212};
0 commit comments