Consider the FLUTTER_TOOL_ARGS as part of the compilation stamp (#94951)

This commit is contained in:
Ian Hickson
2022-01-10 15:20:05 -08:00
committed by GitHub
parent 3e6e996f9e
commit 2835c3f116
5 changed files with 51 additions and 45 deletions

View File

@@ -849,18 +849,17 @@ Future<void> _runFrameworkTests() async {
'--sound-null-safety',
'test_private.dart',
];
final Map<String, String> pubEnvironment = <String, String>{
final Map<String, String> environment = <String, String>{
'FLUTTER_ROOT': flutterRoot,
if (Directory(pubCache).existsSync())
'PUB_CACHE': pubCache,
};
if (Directory(pubCache).existsSync()) {
pubEnvironment['PUB_CACHE'] = pubCache;
}
recompileFlutterToolWithAsserts(pubEnvironment);
adjustEnvironmentToEnableFlutterAsserts(environment);
await runCommand(
pub,
args,
workingDirectory: path.join(flutterRoot, 'packages', 'flutter', 'test_private'),
environment: pubEnvironment,
environment: environment,
);
}
@@ -1530,7 +1529,7 @@ Future<void> _runWebDebugTest(String target, {
final Map<String, String> environment = <String, String>{
'FLUTTER_WEB': 'true',
};
recompileFlutterToolWithAsserts(environment);
adjustEnvironmentToEnableFlutterAsserts(environment);
final CommandResult result = await runCommand(
flutter,
<String>[
@@ -1648,21 +1647,21 @@ Future<void> _pubRunTest(String workingDirectory, {
for (final String testPath in testPaths)
testPath,
];
final Map<String, String> pubEnvironment = <String, String>{
final Map<String, String> environment = <String, String>{
'FLUTTER_ROOT': flutterRoot,
if (includeLocalEngineEnv) ...localEngineEnv,
if (includeLocalEngineEnv)
...localEngineEnv,
if (Directory(pubCache).existsSync())
'PUB_CACHE': pubCache,
};
if (Directory(pubCache).existsSync()) {
pubEnvironment['PUB_CACHE'] = pubCache;
}
if (enableFlutterToolAsserts) {
recompileFlutterToolWithAsserts(pubEnvironment);
adjustEnvironmentToEnableFlutterAsserts(environment);
}
if (ensurePrecompiledTool) {
// We rerun the `flutter` tool here just to make sure that it is compiled
// before tests run, because the tests might time out if they have to rebuild
// the tool themselves.
await runCommand(flutter, <String>['--version'], environment: pubEnvironment);
await runCommand(flutter, <String>['--version'], environment: environment);
}
if (useFlutterTestFormatter) {
final FlutterCompactFormatter formatter = FlutterCompactFormatter();
@@ -1672,7 +1671,7 @@ Future<void> _pubRunTest(String workingDirectory, {
pub,
args,
workingDirectory: workingDirectory,
environment: pubEnvironment,
environment: environment,
);
} finally {
formatter.finish();
@@ -1683,7 +1682,7 @@ Future<void> _pubRunTest(String workingDirectory, {
pub,
args,
workingDirectory: workingDirectory,
environment: pubEnvironment,
environment: environment,
removeLine: useBuildRunner ? (String line) => line.startsWith('[INFO]') : null,
);
}
@@ -1784,20 +1783,16 @@ Future<void> _runFlutterTest(String workingDirectory, {
}
}
/// This will force the next run of the Flutter tool (if it uses the provided environment) to
/// have asserts enabled, by setting an environment variable and deleting the cache.
void recompileFlutterToolWithAsserts(Map<String, String> pubEnvironment) {
/// This will force the next run of the Flutter tool (if it uses the provided
/// environment) to have asserts enabled, by setting an environment variable.
void adjustEnvironmentToEnableFlutterAsserts(Map<String, String> environment) {
// If an existing env variable exists append to it, but only if
// it doesn't appear to already include enable-asserts.
String toolsArgs = Platform.environment['FLUTTER_TOOL_ARGS'] ?? '';
if (!toolsArgs.contains('--enable-asserts')) {
toolsArgs += ' --enable-asserts';
}
pubEnvironment['FLUTTER_TOOL_ARGS'] = toolsArgs.trim();
// The flutter_tool will originally have been snapshotted without asserts.
// We need to force it to be regenerated with them enabled.
deleteFile(path.join(flutterRoot, 'bin', 'cache', 'flutter_tools.snapshot'));
deleteFile(path.join(flutterRoot, 'bin', 'cache', 'flutter_tools.stamp'));
environment['FLUTTER_TOOL_ARGS'] = toolsArgs.trim();
}
Map<String, String> _initGradleEnvironment() {