[native_assets] Filter hook environment (#161084)

Follow up of https://github.com/flutter/flutter/pull/160672 to filter
the environment keys being passed in to build hooks.

~~Failures don't reproduce locally, so this is a draft PR to see which
environment keys are needed for the tests to succeed on CI.~~

Edit: Fixed issues by stopping to use the
Flutter-self-update-dart-executable and instead using the
Dart-sdk-dart-executable.

Relevant bug (already addressed in Dart standalone).

* https://github.com/dart-lang/native/issues/32

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [ ] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
This commit is contained in:
Daco Harkes
2025-01-06 14:05:31 +01:00
committed by GitHub
parent 2d17299f20
commit a6c057c406

View File

@@ -221,17 +221,28 @@ class FlutterNativeAssetsBuildRunnerImpl implements FlutterNativeAssetsBuildRunn
}
});
late final Uri _dartExecutable = fileSystem.directory(Cache.flutterRoot).uri.resolve('bin/dart');
// Flutter wraps the Dart executable to update it in place
// ($FLUTTER_ROOT/bin/dart). However, since this is a Dart process invocation
// in a Flutter process invocation, it should not try to update in place, so
// use the Dart standalone executable
// ($FLUTTER_ROOT/bin/cache/dart-sdk/bin/dart).
late final Uri _dartExecutable = fileSystem
.directory(Cache.flutterRoot)
.uri
.resolve('bin/cache/dart-sdk/bin/dart');
late final NativeAssetsBuildRunner _buildRunner = NativeAssetsBuildRunner(
logger: _logger,
dartExecutable: _dartExecutable,
fileSystem: fileSystem,
// TODO(dcharkes): Filter the environment with
// NativeAssetsBuildRunner.hookEnvironmentVariablesFilter.
hookEnvironment: const LocalPlatform().environment,
hookEnvironment: filteredEnvironment(NativeAssetsBuildRunner.hookEnvironmentVariablesFilter),
);
static Map<String, String> filteredEnvironment(Set<String> allowList) => <String, String>{
for (final MapEntry<String, String> entry in const LocalPlatform().environment.entries)
if (allowList.contains(entry.key.toUpperCase())) entry.key: entry.value,
};
@override
Future<bool> hasPackageConfig() {
return fileSystem.file(packageConfigPath).exists();