Unverified Commit b0bc023f authored by Christopher Fujino's avatar Christopher Fujino Committed by GitHub

[flutter_tools] do not try to build tool from dart.sh (#129186)

Fixes https://github.com/flutter/flutter/issues/121894
parent 1c8c5336
......@@ -130,6 +130,7 @@ GOTO :after_subroutine
IF EXIST "%FLUTTER_ROOT%\version" DEL "%FLUTTER_ROOT%\version"
IF EXIST "%FLUTTER_ROOT%\bin\cache\flutter.version.json" DEL "%FLUTTER_ROOT%\bin\cache\flutter.version.json"
ECHO: > "%cache_dir%\.dartignore"
ECHO Building flutter tool... 1>&2
PUSHD "%flutter_tools_dir%"
......
......@@ -3,7 +3,6 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# ---------------------------------- NOTE ---------------------------------- #
#
# Please keep the logic in this file consistent with the logic in the
......@@ -144,6 +143,11 @@ function upgrade_flutter () (
touch "$FLUTTER_ROOT/bin/cache/.dartignore"
"$FLUTTER_ROOT/bin/internal/update_dart_sdk.sh"
if [[ "$BIN_NAME" == 'dart' ]]; then
# Don't try to build tool
return
fi
>&2 echo Building flutter tool...
# Prepare packages...
......@@ -229,6 +233,8 @@ function shared::execute() {
exit 1
fi
BIN_NAME="$(basename "$PROG_NAME")"
# File descriptor 7 is prepared here so that we can use it with
# flock(1) in _lock() (see above).
#
......@@ -247,7 +253,6 @@ function shared::execute() {
# SHARED_NAME itself is prepared by the caller script.
upgrade_flutter 7< "$SHARED_NAME"
BIN_NAME="$(basename "$PROG_NAME")"
case "$BIN_NAME" in
flutter*)
# FLUTTER_TOOL_ARGS aren't quoted below, because it is meant to be
......
......@@ -48,6 +48,64 @@ Future<void> main() async {
expect(stdout, contains('Successfully received SIGTERM!'));
},
skip: platform.isWindows); // [intended] Windows does not use the bash entrypoint
test('shared.sh does not compile flutter tool if PROG_NAME=dart', () async {
final Directory tempDir = fileSystem.systemTempDirectory.createTempSync('bash_entrypoint_test');
try {
// bash script checks it is in a git repo
ProcessResult result = await processManager.run(<String>['git', 'init'], workingDirectory: tempDir.path);
expect(result, const ProcessResultMatcher());
result = await processManager.run(<String>['git', 'commit', '--allow-empty', '-m', 'init commit'], workingDirectory: tempDir.path);
expect(result, const ProcessResultMatcher());
// copy dart and shared.sh to temp dir
final File trueSharedSh = flutterRoot.childDirectory('bin').childDirectory('internal').childFile('shared.sh');
final File fakeSharedSh = (tempDir.childDirectory('bin').childDirectory('internal')
..createSync(recursive: true))
.childFile('shared.sh');
trueSharedSh.copySync(fakeSharedSh.path);
final File fakeDartBash = tempDir.childDirectory('bin').childFile('dart');
dartBash.copySync(fakeDartBash.path);
// mark dart executable
makeExecutable(fakeDartBash);
// create no-op fake update_dart_sdk.sh script
final File updateDartSdk = tempDir.childDirectory('bin').childDirectory('internal').childFile('update_dart_sdk.sh')..writeAsStringSync('''
#!/usr/bin/env bash
echo downloaded dart sdk
''');
makeExecutable(updateDartSdk);
// create a fake dart runtime
final File dartBin = (tempDir.childDirectory('bin')
.childDirectory('cache')
.childDirectory('dart-sdk')
.childDirectory('bin')
..createSync(recursive: true))
.childFile('dart');
dartBin.writeAsStringSync('''
#!/usr/bin/env bash
echo executed dart binary
''');
makeExecutable(dartBin);
result = await processManager.run(<String>[fakeDartBash.path]);
expect(result, const ProcessResultMatcher());
expect(
(result.stdout as String).split('\n'),
// verify we ran updateDartSdk and dartBin
containsAll(<String>['downloaded dart sdk', 'executed dart binary']),
);
// Verify we did not try to compile the flutter_tool
expect(result.stderr, isNot(contains('Building flutter tool...')));
} finally {
tryToDelete(tempDir);
}
},
skip: platform.isWindows); // [intended] Windows does not use the bash entrypoint
}
// A test Dart app that will run until it receives SIGTERM
......@@ -69,3 +127,8 @@ File get dartBash {
.childFile('dart')
.absolute;
}
void makeExecutable(File file) {
final ProcessResult result = processManager.runSync(<String>['chmod', '+x', file.path]);
expect(result, const ProcessResultMatcher());
}
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