Unverified Commit b4d5c8f4 authored by Matan Lurey's avatar Matan Lurey Committed by GitHub

Update `flutter_tools/bin/*.(dart|sh)` to provide, if set, --local-engine-host. (#132336)

Partial work towards https://github.com/flutter/flutter/issues/132245.

Other than updating error messages, and passing `$LOCAL_ENGINE_HOST`
downwards, this PR should not change the behavior of any existing
workflows or code (i.e. it's purely additive).
parent 7dff527b
...@@ -66,9 +66,23 @@ BuildApp() { ...@@ -66,9 +66,23 @@ BuildApp() {
EchoError "This engine is not compatible with FLUTTER_BUILD_MODE: '${build_mode}'." EchoError "This engine is not compatible with FLUTTER_BUILD_MODE: '${build_mode}'."
EchoError "You can fix this by updating the LOCAL_ENGINE environment variable, or" EchoError "You can fix this by updating the LOCAL_ENGINE environment variable, or"
EchoError "by running:" EchoError "by running:"
EchoError " flutter build macos --local-engine=host_${build_mode}" EchoError " flutter build macos --local-engine=host_${build_mode} --local-engine-host=host_${build_mode}"
EchoError "or" EchoError "or"
EchoError " flutter build macos --local-engine=host_${build_mode}_unopt" EchoError " flutter build macos --local-engine=host_${build_mode}_unopt --local-engine-host=host_${build_mode}_unopt"
EchoError "========================================================================"
exit -1
fi
fi
if [[ -n "$LOCAL_ENGINE_HOST" ]]; then
if [[ $(echo "$LOCAL_ENGINE_HOST" | tr "[:upper:]" "[:lower:]") != *"$build_mode"* ]]; then
EchoError "========================================================================"
EchoError "ERROR: Requested build with Flutter local engine at '${LOCAL_ENGINE_HOST}'"
EchoError "This engine is not compatible with FLUTTER_BUILD_MODE: '${build_mode}'."
EchoError "You can fix this by updating the LOCAL_ENGINE_HOST environment variable, or"
EchoError "by running:"
EchoError " flutter build macos --local-engine=host_${build_mode} --local-engine-host=host_${build_mode}"
EchoError "or"
EchoError " flutter build macos --local-engine=host_${build_mode}_unopt --local-engine-host=host_${build_mode}_unopt"
EchoError "========================================================================" EchoError "========================================================================"
exit -1 exit -1
fi fi
...@@ -94,6 +108,9 @@ BuildApp() { ...@@ -94,6 +108,9 @@ BuildApp() {
if [[ -n "$LOCAL_ENGINE" ]]; then if [[ -n "$LOCAL_ENGINE" ]]; then
flutter_args+=("--local-engine=${LOCAL_ENGINE}") flutter_args+=("--local-engine=${LOCAL_ENGINE}")
fi fi
if [[ -n "$LOCAL_ENGINE_HOST" ]]; then
flutter_args+=("--local-engine-host=${LOCAL_ENGINE_HOST}")
fi
flutter_args+=( flutter_args+=(
"assemble" "assemble"
"--no-version-check" "--no-version-check"
......
...@@ -21,6 +21,7 @@ Future<void> main(List<String> arguments) async { ...@@ -21,6 +21,7 @@ Future<void> main(List<String> arguments) async {
?? pathJoin(<String>['lib', 'main.dart']); ?? pathJoin(<String>['lib', 'main.dart']);
final String? codeSizeDirectory = Platform.environment['CODE_SIZE_DIRECTORY']; final String? codeSizeDirectory = Platform.environment['CODE_SIZE_DIRECTORY'];
final String? localEngine = Platform.environment['LOCAL_ENGINE']; final String? localEngine = Platform.environment['LOCAL_ENGINE'];
final String? localEngineHost = Platform.environment['LOCAL_ENGINE_HOST'];
final String? projectDirectory = Platform.environment['PROJECT_DIR']; final String? projectDirectory = Platform.environment['PROJECT_DIR'];
final String? splitDebugInfo = Platform.environment['SPLIT_DEBUG_INFO']; final String? splitDebugInfo = Platform.environment['SPLIT_DEBUG_INFO'];
final String? bundleSkSLPath = Platform.environment['BUNDLE_SKSL_PATH']; final String? bundleSkSLPath = Platform.environment['BUNDLE_SKSL_PATH'];
...@@ -46,9 +47,22 @@ ERROR: Requested build with Flutter local engine at '$localEngine' ...@@ -46,9 +47,22 @@ ERROR: Requested build with Flutter local engine at '$localEngine'
This engine is not compatible with FLUTTER_BUILD_MODE: '$buildMode'. This engine is not compatible with FLUTTER_BUILD_MODE: '$buildMode'.
You can fix this by updating the LOCAL_ENGINE environment variable, or You can fix this by updating the LOCAL_ENGINE environment variable, or
by running: by running:
flutter build <platform> --local-engine=host_$buildMode flutter build <platform> --local-engine=<platform>_$buildMode --local-engine-host=host_$buildMode
or or
flutter build <platform> --local-engine=host_${buildMode}_unopt flutter build <platform> --local-engine=<platform>_${buildMode}_unopt --local-engine-host=host_${buildMode}_unopt
========================================================================
''');
exit(1);
}
if (localEngineHost != null && !localEngineHost.contains(buildMode)) {
stderr.write('''
ERROR: Requested build with Flutter local engine host at '$localEngineHost'
This engine is not compatible with FLUTTER_BUILD_MODE: '$buildMode'.
You can fix this by updating the LOCAL_ENGINE_HOST environment variable, or
by running:
flutter build <platform> --local-engine=<platform>_$buildMode --local-engine-host=host_$buildMode
or
flutter build <platform> --local-engine=<platform>_$buildMode --local-engine-host=host_${buildMode}_unopt
======================================================================== ========================================================================
'''); ''');
exit(1); exit(1);
...@@ -72,6 +86,7 @@ or ...@@ -72,6 +86,7 @@ or
'--prefixed-errors', '--prefixed-errors',
if (flutterEngine != null) '--local-engine-src-path=$flutterEngine', if (flutterEngine != null) '--local-engine-src-path=$flutterEngine',
if (localEngine != null) '--local-engine=$localEngine', if (localEngine != null) '--local-engine=$localEngine',
if (localEngineHost != null) '--local-engine-host=$localEngineHost',
'assemble', 'assemble',
'--no-version-check', '--no-version-check',
'--output=build', '--output=build',
......
...@@ -345,6 +345,10 @@ class Context { ...@@ -345,6 +345,10 @@ class Context {
flutterArgs.add('--local-engine=${environment['LOCAL_ENGINE']}'); flutterArgs.add('--local-engine=${environment['LOCAL_ENGINE']}');
} }
if (environment['LOCAL_ENGINE_HOST'] != null && environment['LOCAL_ENGINE_HOST']!.isNotEmpty) {
flutterArgs.add('--local-engine-host=${environment['LOCAL_ENGINE_HOST']}');
}
flutterArgs.addAll(<String>[ flutterArgs.addAll(<String>[
'assemble', 'assemble',
'--no-version-check', '--no-version-check',
......
...@@ -70,4 +70,25 @@ void main() { ...@@ -70,4 +70,25 @@ void main() {
), ),
); );
}); });
testWithoutContext('tool_backend.dart exits if local engine host does not match build mode', () async {
final ProcessResult result = await processManager.run(<String>[
dart,
toolBackend,
'linux-x64',
'debug',
], environment: <String, String>{
'PROJECT_DIR': examplePath,
'LOCAL_ENGINE': 'debug_foo_bar', // OK
'LOCAL_ENGINE_HOST': 'release_foo_bar', // Does not contain "debug",
});
expect(
result,
const ProcessResultMatcher(
exitCode: 1,
stderrPattern: "ERROR: Requested build with Flutter local engine host at 'release_foo_bar'",
),
);
});
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment