From a6c057c406103d68ecaa42da86063f533d4f7f72 Mon Sep 17 00:00:00 2001 From: Daco Harkes Date: Mon, 6 Jan 2025 14:05:31 +0100 Subject: [PATCH] [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. [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 --- .../isolated/native_assets/native_assets.dart | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/flutter_tools/lib/src/isolated/native_assets/native_assets.dart b/packages/flutter_tools/lib/src/isolated/native_assets/native_assets.dart index e2d9a2224e..a63fcc4bc3 100644 --- a/packages/flutter_tools/lib/src/isolated/native_assets/native_assets.dart +++ b/packages/flutter_tools/lib/src/isolated/native_assets/native_assets.dart @@ -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 filteredEnvironment(Set allowList) => { + for (final MapEntry entry in const LocalPlatform().environment.entries) + if (allowList.contains(entry.key.toUpperCase())) entry.key: entry.value, + }; + @override Future hasPackageConfig() { return fileSystem.file(packageConfigPath).exists();