Skip to content

Commit 400c700

Browse files
[hooks_runner] Pass NIX_ environment variables through in hooks_runner (#2634)
1 parent f0f2522 commit 400c700

File tree

4 files changed

+36
-22
lines changed

4 files changed

+36
-22
lines changed

pkgs/hooks_runner/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.23.0
2+
3+
- **Breaking change**: Replaced `NativeAssetsBuildRunner.hookEnvironmentVariablesFilter`
4+
with `NativeAssetsBuildRunner.includeHookEnvironmentVariable` to account for
5+
environment variables that start with a particular prefix (i.e., `NIX_`).
6+
17
## 0.22.1
28

39
* Fix caches not being invalidated on (1) user-defines changing, (2) metadata

pkgs/hooks_runner/lib/src/build_runner/build_runner.dart

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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
};

pkgs/hooks_runner/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: hooks_runner
22
description: >-
33
This package is the backend that invokes build hooks.
44
5-
version: 0.22.1
5+
version: 0.23.0
66

77
repository: https://github.com/dart-lang/native/tree/main/pkgs/hooks_runner
88

pkgs/hooks_runner/test/build_runner/build_runner_caching_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ void main() async {
276276
hookEnvironment: modifiedEnvKey == 'PATH'
277277
? null
278278
: filteredEnvironment(
279-
NativeAssetsBuildRunner.hookEnvironmentVariablesFilter,
279+
NativeAssetsBuildRunner.includeHookEnvironmentVariable,
280280
),
281281
)).success;
282282
logMessages.clear();

0 commit comments

Comments
 (0)