Skip to content

Commit 43afac1

Browse files
Reduce usage of testUsingContext (flutter#131078)
Part of flutter#47161
1 parent f2ba0a2 commit 43afac1

File tree

10 files changed

+79
-104
lines changed

10 files changed

+79
-104
lines changed

packages/flutter_tools/lib/src/cmake.dart

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
import 'package:pub_semver/pub_semver.dart';
66

7+
import 'base/logger.dart';
78
import 'build_info.dart';
89
import 'cmake_project.dart';
9-
import 'globals.dart' as globals;
1010

1111
/// Extracts the `BINARY_NAME` from a project's CMake file.
1212
///
@@ -41,12 +41,12 @@ String _determineVersionString(CmakeBasedProject project, BuildInfo buildInfo) {
4141
: buildName;
4242
}
4343

44-
Version _determineVersion(CmakeBasedProject project, BuildInfo buildInfo) {
44+
Version _determineVersion(CmakeBasedProject project, BuildInfo buildInfo, Logger logger) {
4545
final String version = _determineVersionString(project, buildInfo);
4646
try {
4747
return Version.parse(version);
4848
} on FormatException {
49-
globals.printWarning('Warning: could not parse version $version, defaulting to 1.0.0.');
49+
logger.printWarning('Warning: could not parse version $version, defaulting to 1.0.0.');
5050

5151
return Version(1, 0, 0);
5252
}
@@ -74,25 +74,27 @@ void writeGeneratedCmakeConfig(
7474
String flutterRoot,
7575
CmakeBasedProject project,
7676
BuildInfo buildInfo,
77-
Map<String, String> environment) {
77+
Map<String, String> environment,
78+
Logger logger,
79+
) {
7880
// Only a limited set of variables are needed by the CMake files themselves,
7981
// the rest are put into a list to pass to the re-entrant build step.
8082
final String escapedFlutterRoot = _escapeBackslashes(flutterRoot);
8183
final String escapedProjectDir = _escapeBackslashes(project.parent.directory.path);
8284

83-
final Version version = _determineVersion(project, buildInfo);
85+
final Version version = _determineVersion(project, buildInfo, logger);
8486
final int? buildVersion = _tryDetermineBuildVersion(version);
8587

8688
// Since complex Dart build identifiers cannot be converted into integers,
8789
// different Dart versions may be converted into the same Windows numeric version.
8890
// Warn the user as some Windows installers, like MSI, don't update files if their versions are equal.
8991
if (buildVersion == null && project is WindowsProject) {
90-
final String buildIdentifier = version.build.join('.');
91-
globals.printWarning(
92-
'Warning: build identifier $buildIdentifier in version $version is not numeric '
93-
'and cannot be converted into a Windows build version number. Defaulting to 0.\n'
94-
'This may cause issues with Windows installers.'
95-
);
92+
final String buildIdentifier = version.build.join('.');
93+
logger.printWarning(
94+
'Warning: build identifier $buildIdentifier in version $version is not numeric '
95+
'and cannot be converted into a Windows build version number. Defaulting to 0.\n'
96+
'This may cause issues with Windows installers.'
97+
);
9698
}
9799

98100
final StringBuffer buffer = StringBuffer('''

packages/flutter_tools/lib/src/commands/build_linux.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
56
import '../base/analyze_size.dart';
67
import '../base/common.dart';
8+
import '../base/logger.dart';
79
import '../base/os.dart';
810
import '../build_info.dart';
911
import '../cache.dart';
@@ -83,18 +85,20 @@ class BuildLinuxCommand extends BuildSubCommand {
8385
'Cross-build from Linux x64 host to Linux arm64 target is not currently supported.');
8486
}
8587
displayNullSafetyMode(buildInfo);
88+
final Logger logger = globals.logger;
8689
await buildLinux(
8790
flutterProject.linux,
8891
buildInfo,
8992
target: targetFile,
9093
sizeAnalyzer: SizeAnalyzer(
9194
fileSystem: globals.fs,
92-
logger: globals.logger,
95+
logger: logger,
9396
flutterUsage: globals.flutterUsage,
9497
),
9598
needCrossBuild: needCrossBuild,
9699
targetPlatform: targetPlatform,
97100
targetSysroot: stringArg('target-sysroot')!,
101+
logger: logger,
98102
);
99103
return FlutterCommandResult.success();
100104
}

packages/flutter_tools/lib/src/linux/build_linux.dart

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ final RegExp errorMatcher = RegExp(r'(?:(?:.*:\d+:\d+|clang):\s)?(fatal\s)?(?:er
2929
Future<void> buildLinux(
3030
LinuxProject linuxProject,
3131
BuildInfo buildInfo, {
32-
String? target,
33-
SizeAnalyzer? sizeAnalyzer,
34-
bool needCrossBuild = false,
35-
required TargetPlatform targetPlatform,
36-
String targetSysroot = '/',
37-
}) async {
32+
String? target,
33+
SizeAnalyzer? sizeAnalyzer,
34+
bool needCrossBuild = false,
35+
required TargetPlatform targetPlatform,
36+
String targetSysroot = '/',
37+
required Logger logger,
38+
}) async {
3839
target ??= 'lib/main.dart';
3940
if (!linuxProject.cmakeFile.existsSync()) {
4041
throwToolExit('No Linux desktop project configured. See '
@@ -43,7 +44,7 @@ Future<void> buildLinux(
4344
}
4445

4546
final List<ProjectMigrator> migrators = <ProjectMigrator>[
46-
CmakeCustomCommandMigration(linuxProject, globals.logger),
47+
CmakeCustomCommandMigration(linuxProject, logger),
4748
];
4849

4950
final ProjectMigration migration = ProjectMigration(migrators);
@@ -59,11 +60,11 @@ Future<void> buildLinux(
5960
environmentConfig['FLUTTER_ENGINE'] = globals.fs.path.dirname(globals.fs.path.dirname(engineOutPath));
6061
environmentConfig['LOCAL_ENGINE'] = localEngineInfo.localEngineName;
6162
}
62-
writeGeneratedCmakeConfig(Cache.flutterRoot!, linuxProject, buildInfo, environmentConfig);
63+
writeGeneratedCmakeConfig(Cache.flutterRoot!, linuxProject, buildInfo, environmentConfig, logger);
6364

6465
createPluginSymlinks(linuxProject.parent);
6566

66-
final Status status = globals.logger.startProgress(
67+
final Status status = logger.startProgress(
6768
'Building Linux application...',
6869
);
6970
try {
@@ -97,13 +98,13 @@ Future<void> buildLinux(
9798
.childDirectory('.flutter-devtools'), 'linux-code-size-analysis', 'json',
9899
)..writeAsStringSync(jsonEncode(output));
99100
// This message is used as a sentinel in analyze_apk_size_test.dart
100-
globals.printStatus(
101+
logger.printStatus(
101102
'A summary of your Linux bundle analysis can be found at: ${outputFile.path}',
102103
);
103104

104105
// DevTools expects a file path relative to the .flutter-devtools/ dir.
105106
final String relativeAppSizePath = outputFile.path.split('.flutter-devtools/').last.trim();
106-
globals.printStatus(
107+
logger.printStatus(
107108
'\nTo analyze your app size in Dart DevTools, run the following command:\n'
108109
'dart devtools --appSizeBase=$relativeAppSizePath'
109110
);

packages/flutter_tools/lib/src/linux/linux_device.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class LinuxDevice extends DesktopDevice {
2525
required FileSystem fileSystem,
2626
required OperatingSystemUtils operatingSystemUtils,
2727
}) : _operatingSystemUtils = operatingSystemUtils,
28+
_logger = logger,
2829
super(
2930
'linux',
3031
platformType: PlatformType.linux,
@@ -36,6 +37,7 @@ class LinuxDevice extends DesktopDevice {
3637
);
3738

3839
final OperatingSystemUtils _operatingSystemUtils;
40+
final Logger _logger;
3941

4042
@override
4143
bool isSupported() => true;
@@ -66,6 +68,7 @@ class LinuxDevice extends DesktopDevice {
6668
buildInfo,
6769
target: mainPath,
6870
targetPlatform: await targetPlatform,
71+
logger: _logger,
6972
);
7073
}
7174

packages/flutter_tools/lib/src/reporting/events.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ class HotEvent extends UsageEvent {
5454
this.scannedSourcesCount,
5555
this.reassembleTimeInMs,
5656
this.reloadVMTimeInMs,
57-
}) : super('hot', parameter, flutterUsage: globals.flutterUsage);
57+
// TODO(fujino): make this required
58+
Usage? usage,
59+
}) : super('hot', parameter, flutterUsage: usage ?? globals.flutterUsage);
5860

5961
final String? reason;
6062
final String targetPlatform;

packages/flutter_tools/lib/src/run_hot.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,7 @@ class HotRunner extends ResidentRunner {
950950
sdkName,
951951
emulator,
952952
reason,
953+
globals.flutterUsage,
953954
);
954955
if (result.code != 0) {
955956
return result;
@@ -1172,6 +1173,7 @@ typedef ReloadSourcesHelper = Future<OperationResult> Function(
11721173
String? sdkName,
11731174
bool? emulator,
11741175
String? reason,
1176+
Usage usage,
11751177
);
11761178

11771179
@visibleForTesting
@@ -1184,6 +1186,7 @@ Future<OperationResult> defaultReloadSourcesHelper(
11841186
String? sdkName,
11851187
bool? emulator,
11861188
String? reason,
1189+
Usage usage,
11871190
) async {
11881191
final Stopwatch vmReloadTimer = Stopwatch()..start();
11891192
const String entryPath = 'main.dart.incremental.dill';
@@ -1223,6 +1226,7 @@ Future<OperationResult> defaultReloadSourcesHelper(
12231226
fullRestart: false,
12241227
reason: reason,
12251228
fastReassemble: false,
1229+
usage: usage,
12261230
).send();
12271231
// Reset devFS lastCompileTime to ensure the file will still be marked
12281232
// as dirty on subsequent reloads.

packages/flutter_tools/lib/src/windows/build_windows.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ void _writeGeneratedFlutterConfig(
242242
environment['FLUTTER_ENGINE'] = globals.fs.path.dirname(globals.fs.path.dirname(engineOutPath));
243243
environment['LOCAL_ENGINE'] = localEngineInfo.localEngineName;
244244
}
245-
writeGeneratedCmakeConfig(Cache.flutterRoot!, windowsProject, buildInfo, environment);
245+
writeGeneratedCmakeConfig(Cache.flutterRoot!, windowsProject, buildInfo, environment, globals.logger);
246246
}
247247

248248
// Works around the Visual Studio 17.1.0 CMake bug described in

0 commit comments

Comments
 (0)