Skip to content

Commit b0bc023

Browse files
[flutter_tools] do not try to build tool from dart.sh (flutter#129186)
Fixes flutter#121894
1 parent 1c8c533 commit b0bc023

File tree

3 files changed

+71
-2
lines changed

3 files changed

+71
-2
lines changed

bin/internal/shared.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ GOTO :after_subroutine
130130
IF EXIST "%FLUTTER_ROOT%\version" DEL "%FLUTTER_ROOT%\version"
131131
IF EXIST "%FLUTTER_ROOT%\bin\cache\flutter.version.json" DEL "%FLUTTER_ROOT%\bin\cache\flutter.version.json"
132132
ECHO: > "%cache_dir%\.dartignore"
133+
133134
ECHO Building flutter tool... 1>&2
134135
PUSHD "%flutter_tools_dir%"
135136

bin/internal/shared.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# Use of this source code is governed by a BSD-style license that can be
44
# found in the LICENSE file.
55

6-
76
# ---------------------------------- NOTE ---------------------------------- #
87
#
98
# Please keep the logic in this file consistent with the logic in the
@@ -144,6 +143,11 @@ function upgrade_flutter () (
144143
touch "$FLUTTER_ROOT/bin/cache/.dartignore"
145144
"$FLUTTER_ROOT/bin/internal/update_dart_sdk.sh"
146145

146+
if [[ "$BIN_NAME" == 'dart' ]]; then
147+
# Don't try to build tool
148+
return
149+
fi
150+
147151
>&2 echo Building flutter tool...
148152

149153
# Prepare packages...
@@ -229,6 +233,8 @@ function shared::execute() {
229233
exit 1
230234
fi
231235

236+
BIN_NAME="$(basename "$PROG_NAME")"
237+
232238
# File descriptor 7 is prepared here so that we can use it with
233239
# flock(1) in _lock() (see above).
234240
#
@@ -247,7 +253,6 @@ function shared::execute() {
247253
# SHARED_NAME itself is prepared by the caller script.
248254
upgrade_flutter 7< "$SHARED_NAME"
249255

250-
BIN_NAME="$(basename "$PROG_NAME")"
251256
case "$BIN_NAME" in
252257
flutter*)
253258
# FLUTTER_TOOL_ARGS aren't quoted below, because it is meant to be

packages/flutter_tools/test/integration.shard/bash_entrypoint_test.dart

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,64 @@ Future<void> main() async {
4848
expect(stdout, contains('Successfully received SIGTERM!'));
4949
},
5050
skip: platform.isWindows); // [intended] Windows does not use the bash entrypoint
51+
52+
test('shared.sh does not compile flutter tool if PROG_NAME=dart', () async {
53+
final Directory tempDir = fileSystem.systemTempDirectory.createTempSync('bash_entrypoint_test');
54+
try {
55+
// bash script checks it is in a git repo
56+
ProcessResult result = await processManager.run(<String>['git', 'init'], workingDirectory: tempDir.path);
57+
expect(result, const ProcessResultMatcher());
58+
result = await processManager.run(<String>['git', 'commit', '--allow-empty', '-m', 'init commit'], workingDirectory: tempDir.path);
59+
expect(result, const ProcessResultMatcher());
60+
61+
// copy dart and shared.sh to temp dir
62+
final File trueSharedSh = flutterRoot.childDirectory('bin').childDirectory('internal').childFile('shared.sh');
63+
final File fakeSharedSh = (tempDir.childDirectory('bin').childDirectory('internal')
64+
..createSync(recursive: true))
65+
.childFile('shared.sh');
66+
trueSharedSh.copySync(fakeSharedSh.path);
67+
final File fakeDartBash = tempDir.childDirectory('bin').childFile('dart');
68+
dartBash.copySync(fakeDartBash.path);
69+
// mark dart executable
70+
makeExecutable(fakeDartBash);
71+
72+
// create no-op fake update_dart_sdk.sh script
73+
final File updateDartSdk = tempDir.childDirectory('bin').childDirectory('internal').childFile('update_dart_sdk.sh')..writeAsStringSync('''
74+
#!/usr/bin/env bash
75+
76+
echo downloaded dart sdk
77+
''');
78+
makeExecutable(updateDartSdk);
79+
80+
// create a fake dart runtime
81+
final File dartBin = (tempDir.childDirectory('bin')
82+
.childDirectory('cache')
83+
.childDirectory('dart-sdk')
84+
.childDirectory('bin')
85+
..createSync(recursive: true))
86+
.childFile('dart');
87+
dartBin.writeAsStringSync('''
88+
#!/usr/bin/env bash
89+
90+
echo executed dart binary
91+
''');
92+
makeExecutable(dartBin);
93+
94+
result = await processManager.run(<String>[fakeDartBash.path]);
95+
expect(result, const ProcessResultMatcher());
96+
expect(
97+
(result.stdout as String).split('\n'),
98+
// verify we ran updateDartSdk and dartBin
99+
containsAll(<String>['downloaded dart sdk', 'executed dart binary']),
100+
);
101+
102+
// Verify we did not try to compile the flutter_tool
103+
expect(result.stderr, isNot(contains('Building flutter tool...')));
104+
} finally {
105+
tryToDelete(tempDir);
106+
}
107+
},
108+
skip: platform.isWindows); // [intended] Windows does not use the bash entrypoint
51109
}
52110

53111
// A test Dart app that will run until it receives SIGTERM
@@ -69,3 +127,8 @@ File get dartBash {
69127
.childFile('dart')
70128
.absolute;
71129
}
130+
131+
void makeExecutable(File file) {
132+
final ProcessResult result = processManager.runSync(<String>['chmod', '+x', file.path]);
133+
expect(result, const ProcessResultMatcher());
134+
}

0 commit comments

Comments
 (0)