Skip to content

Commit 2835c3f

Browse files
authored
Consider the FLUTTER_TOOL_ARGS as part of the compilation stamp (#94951)
1 parent 3e6e996 commit 2835c3f

File tree

5 files changed

+51
-45
lines changed

5 files changed

+51
-45
lines changed

bin/flutter

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313

1414
set -e
1515

16+
# To debug the tool, you can uncomment the following lines to enable debug
17+
# mode and set an observatory port:
18+
# FLUTTER_TOOL_ARGS="--enable-asserts $FLUTTER_TOOL_ARGS"
19+
# FLUTTER_TOOL_ARGS="$FLUTTER_TOOL_ARGS --observe=65432"
20+
1621
# Needed because if it is set, cd may print the path it changed to.
1722
unset CDPATH
1823

bin/flutter.bat

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ REM --------------------------------------------------------------------------
1313

1414
SETLOCAL ENABLEDELAYEDEXPANSION
1515

16+
REM To debug the tool, you can uncomment the following line to enable debug mode:
17+
REM SET FLUTTER_TOOL_ARGS="--enable-asserts %FLUTTER_TOOL_ARGS%"
18+
1619
FOR %%i IN ("%~dp0..") DO SET FLUTTER_ROOT=%%~fi
1720

1821
REM If available, add location of bundled mingit to PATH
@@ -40,9 +43,6 @@ SET snapshot_path=%cache_dir%\flutter_tools.snapshot
4043
SET dart_sdk_path=%cache_dir%\dart-sdk
4144
SET dart=%dart_sdk_path%\bin\dart.exe
4245

43-
REM To debug the tool, you can uncomment the following lines to enable checked mode and set an observatory port:
44-
REM SET FLUTTER_TOOL_ARGS="--enable-asserts %FLUTTER_TOOL_ARGS%"
45-
4646
REM Chaining the call to 'dart' and 'exit' with an ampersand ensures that
4747
REM Windows reads both commands into memory once before executing them. This
4848
REM avoids nasty errors that may otherwise occur when the dart command (e.g. as

bin/internal/shared.bat

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ GOTO :after_subroutine
6969
PUSHD "%flutter_root%"
7070
FOR /f %%r IN ('git rev-parse HEAD') DO SET revision=%%r
7171
POPD
72+
SET compilekey="%revision%:%FLUTTER_TOOL_ARGS%"
73+
74+
REM Invalidate cache if:
75+
REM * SNAPSHOT_PATH is not a file, or
76+
REM * STAMP_PATH is not a file, or
77+
REM * STAMP_PATH is an empty file, or
78+
REM * Contents of STAMP_PATH is not what we are going to compile, or
79+
REM * pubspec.yaml last modified after pubspec.lock
7280

7381
REM The following IF conditions are all linked with a logical OR. However,
7482
REM there is no OR operator in batch and a GOTO construct is used as replacement.
@@ -80,7 +88,7 @@ GOTO :after_subroutine
8088
IF NOT EXIST "%snapshot_path%" GOTO do_snapshot
8189
IF NOT EXIST "%stamp_path%" GOTO do_snapshot
8290
SET /P stamp_value=<"%stamp_path%"
83-
IF !stamp_value! NEQ !revision! GOTO do_snapshot
91+
IF !stamp_value! NEQ !compilekey! GOTO do_snapshot
8492
SET pubspec_yaml_path=%flutter_tools_dir%\pubspec.yaml
8593
SET pubspec_lock_path=%flutter_tools_dir%\pubspec.lock
8694
FOR /F %%i IN ('DIR /B /O:D "%pubspec_yaml_path%" "%pubspec_lock_path%"') DO SET newer_file=%%i
@@ -164,7 +172,7 @@ GOTO :after_subroutine
164172
SET exit_code=%ERRORLEVEL%
165173
GOTO :final_exit
166174
)
167-
>"%stamp_path%" ECHO %revision%
175+
>"%stamp_path%" ECHO %compilekey%
168176

169177
REM Exit Subroutine
170178
EXIT /B

bin/internal/shared.sh

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ set -e
1717
# Needed because if it is set, cd may print the path it changed to.
1818
unset CDPATH
1919

20-
function retry_upgrade {
20+
function pub_upgrade_with_retry {
2121
local total_tries="10"
2222
local remaining_tries=$((total_tries - 1))
2323
while [[ "$remaining_tries" -gt 0 ]]; do
@@ -115,45 +115,48 @@ function upgrade_flutter () (
115115
mkdir -p "$FLUTTER_ROOT/bin/cache"
116116

117117
local revision="$(cd "$FLUTTER_ROOT"; git rev-parse HEAD)"
118+
local compilekey="$revision:$FLUTTER_TOOL_ARGS"
118119

119120
# Invalidate cache if:
120121
# * SNAPSHOT_PATH is not a file, or
121-
# * STAMP_PATH is not a file with nonzero size, or
122-
# * Contents of STAMP_PATH is not our local git HEAD revision, or
122+
# * STAMP_PATH is not a file, or
123+
# * STAMP_PATH is an empty file, or
124+
# * Contents of STAMP_PATH is not what we are going to compile, or
123125
# * pubspec.yaml last modified after pubspec.lock
124-
if [[ ! -f "$SNAPSHOT_PATH" || ! -s "$STAMP_PATH" || "$(cat "$STAMP_PATH")" != "$revision" || "$FLUTTER_TOOLS_DIR/pubspec.yaml" -nt "$FLUTTER_TOOLS_DIR/pubspec.lock" ]]; then
126+
if [[ ! -f "$SNAPSHOT_PATH" || ! -s "$STAMP_PATH" || "$(cat "$STAMP_PATH")" != "$compilekey" || "$FLUTTER_TOOLS_DIR/pubspec.yaml" -nt "$FLUTTER_TOOLS_DIR/pubspec.lock" ]]; then
125127
# Waits for the update lock to be acquired. Placing this check inside the
126128
# conditional allows the majority of flutter/dart installations to bypass
127129
# the lock entirely, but as a result this required a second verification that
128130
# the SDK is up to date.
129131
_wait_for_lock
130132

131133
# A different shell process might have updated the tool/SDK.
132-
if [[ -f "$SNAPSHOT_PATH" && -s "$STAMP_PATH" && "$(cat "$STAMP_PATH")" == "$revision" && "$FLUTTER_TOOLS_DIR/pubspec.yaml" -ot "$FLUTTER_TOOLS_DIR/pubspec.lock" ]]; then
134+
if [[ -f "$SNAPSHOT_PATH" && -s "$STAMP_PATH" && "$(cat "$STAMP_PATH")" == "$compilekey" && "$FLUTTER_TOOLS_DIR/pubspec.yaml" -ot "$FLUTTER_TOOLS_DIR/pubspec.lock" ]]; then
133135
exit $?
134136
fi
135137

138+
# Fetch Dart...
136139
rm -f "$FLUTTER_ROOT/version"
137140
touch "$FLUTTER_ROOT/bin/cache/.dartignore"
138141
"$FLUTTER_ROOT/bin/internal/update_dart_sdk.sh"
139-
VERBOSITY="--verbosity=error"
140142

141143
>&2 echo Building flutter tool...
144+
145+
# Prepare packages...
146+
VERBOSITY="--verbosity=error"
142147
if [[ "$CI" == "true" || "$BOT" == "true" || "$CONTINUOUS_INTEGRATION" == "true" || "$CHROME_HEADLESS" == "1" ]]; then
143148
PUB_ENVIRONMENT="$PUB_ENVIRONMENT:flutter_bot"
144149
VERBOSITY="--verbosity=normal"
145150
fi
146-
147151
export PUB_ENVIRONMENT="$PUB_ENVIRONMENT:flutter_install"
148-
149152
if [[ -d "$FLUTTER_ROOT/.pub-cache" ]]; then
150153
export PUB_CACHE="${PUB_CACHE:-"$FLUTTER_ROOT/.pub-cache"}"
151154
fi
155+
pub_upgrade_with_retry
152156

153-
retry_upgrade
154-
157+
# Compile...
155158
"$DART" --verbosity=error --disable-dart-dev $FLUTTER_TOOL_ARGS --snapshot="$SNAPSHOT_PATH" --packages="$FLUTTER_TOOLS_DIR/.packages" --no-enable-mirrors "$SCRIPT_PATH"
156-
echo "$revision" > "$STAMP_PATH"
159+
echo "$compilekey" > "$STAMP_PATH"
157160
fi
158161
# The exit here is extraneous since the function is run in a subshell, but
159162
# this serves as documentation that running the function in a subshell is
@@ -212,11 +215,6 @@ function shared::execute() {
212215
exit 1
213216
fi
214217

215-
# To debug the tool, you can uncomment the following lines to enable checked
216-
# mode and set an observatory port:
217-
# FLUTTER_TOOL_ARGS="--enable-asserts $FLUTTER_TOOL_ARGS"
218-
# FLUTTER_TOOL_ARGS="$FLUTTER_TOOL_ARGS --observe=65432"
219-
220218
upgrade_flutter 7< "$PROG_NAME"
221219

222220
BIN_NAME="$(basename "$PROG_NAME")"

dev/bots/test.dart

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -849,18 +849,17 @@ Future<void> _runFrameworkTests() async {
849849
'--sound-null-safety',
850850
'test_private.dart',
851851
];
852-
final Map<String, String> pubEnvironment = <String, String>{
852+
final Map<String, String> environment = <String, String>{
853853
'FLUTTER_ROOT': flutterRoot,
854+
if (Directory(pubCache).existsSync())
855+
'PUB_CACHE': pubCache,
854856
};
855-
if (Directory(pubCache).existsSync()) {
856-
pubEnvironment['PUB_CACHE'] = pubCache;
857-
}
858-
recompileFlutterToolWithAsserts(pubEnvironment);
857+
adjustEnvironmentToEnableFlutterAsserts(environment);
859858
await runCommand(
860859
pub,
861860
args,
862861
workingDirectory: path.join(flutterRoot, 'packages', 'flutter', 'test_private'),
863-
environment: pubEnvironment,
862+
environment: environment,
864863
);
865864
}
866865

@@ -1530,7 +1529,7 @@ Future<void> _runWebDebugTest(String target, {
15301529
final Map<String, String> environment = <String, String>{
15311530
'FLUTTER_WEB': 'true',
15321531
};
1533-
recompileFlutterToolWithAsserts(environment);
1532+
adjustEnvironmentToEnableFlutterAsserts(environment);
15341533
final CommandResult result = await runCommand(
15351534
flutter,
15361535
<String>[
@@ -1648,21 +1647,21 @@ Future<void> _pubRunTest(String workingDirectory, {
16481647
for (final String testPath in testPaths)
16491648
testPath,
16501649
];
1651-
final Map<String, String> pubEnvironment = <String, String>{
1650+
final Map<String, String> environment = <String, String>{
16521651
'FLUTTER_ROOT': flutterRoot,
1653-
if (includeLocalEngineEnv) ...localEngineEnv,
1652+
if (includeLocalEngineEnv)
1653+
...localEngineEnv,
1654+
if (Directory(pubCache).existsSync())
1655+
'PUB_CACHE': pubCache,
16541656
};
1655-
if (Directory(pubCache).existsSync()) {
1656-
pubEnvironment['PUB_CACHE'] = pubCache;
1657-
}
16581657
if (enableFlutterToolAsserts) {
1659-
recompileFlutterToolWithAsserts(pubEnvironment);
1658+
adjustEnvironmentToEnableFlutterAsserts(environment);
16601659
}
16611660
if (ensurePrecompiledTool) {
16621661
// We rerun the `flutter` tool here just to make sure that it is compiled
16631662
// before tests run, because the tests might time out if they have to rebuild
16641663
// the tool themselves.
1665-
await runCommand(flutter, <String>['--version'], environment: pubEnvironment);
1664+
await runCommand(flutter, <String>['--version'], environment: environment);
16661665
}
16671666
if (useFlutterTestFormatter) {
16681667
final FlutterCompactFormatter formatter = FlutterCompactFormatter();
@@ -1672,7 +1671,7 @@ Future<void> _pubRunTest(String workingDirectory, {
16721671
pub,
16731672
args,
16741673
workingDirectory: workingDirectory,
1675-
environment: pubEnvironment,
1674+
environment: environment,
16761675
);
16771676
} finally {
16781677
formatter.finish();
@@ -1683,7 +1682,7 @@ Future<void> _pubRunTest(String workingDirectory, {
16831682
pub,
16841683
args,
16851684
workingDirectory: workingDirectory,
1686-
environment: pubEnvironment,
1685+
environment: environment,
16871686
removeLine: useBuildRunner ? (String line) => line.startsWith('[INFO]') : null,
16881687
);
16891688
}
@@ -1784,20 +1783,16 @@ Future<void> _runFlutterTest(String workingDirectory, {
17841783
}
17851784
}
17861785

1787-
/// This will force the next run of the Flutter tool (if it uses the provided environment) to
1788-
/// have asserts enabled, by setting an environment variable and deleting the cache.
1789-
void recompileFlutterToolWithAsserts(Map<String, String> pubEnvironment) {
1786+
/// This will force the next run of the Flutter tool (if it uses the provided
1787+
/// environment) to have asserts enabled, by setting an environment variable.
1788+
void adjustEnvironmentToEnableFlutterAsserts(Map<String, String> environment) {
17901789
// If an existing env variable exists append to it, but only if
17911790
// it doesn't appear to already include enable-asserts.
17921791
String toolsArgs = Platform.environment['FLUTTER_TOOL_ARGS'] ?? '';
17931792
if (!toolsArgs.contains('--enable-asserts')) {
17941793
toolsArgs += ' --enable-asserts';
17951794
}
1796-
pubEnvironment['FLUTTER_TOOL_ARGS'] = toolsArgs.trim();
1797-
// The flutter_tool will originally have been snapshotted without asserts.
1798-
// We need to force it to be regenerated with them enabled.
1799-
deleteFile(path.join(flutterRoot, 'bin', 'cache', 'flutter_tools.snapshot'));
1800-
deleteFile(path.join(flutterRoot, 'bin', 'cache', 'flutter_tools.stamp'));
1795+
environment['FLUTTER_TOOL_ARGS'] = toolsArgs.trim();
18011796
}
18021797

18031798
Map<String, String> _initGradleEnvironment() {

0 commit comments

Comments
 (0)