Skip to content

Commit

Permalink
[flutter_tools] do not try to build tool from dart.sh (#129186)
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherfujino authored Nov 3, 2023
1 parent 1c8c533 commit b0bc023
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
1 change: 1 addition & 0 deletions bin/internal/shared.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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%"

Expand Down
9 changes: 7 additions & 2 deletions bin/internal/shared.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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...
Expand Down Expand Up @@ -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).
#
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
}

0 comments on commit b0bc023

Please sign in to comment.