Unverified Commit 43afac1e authored by Christopher Fujino's avatar Christopher Fujino Committed by GitHub

Reduce usage of testUsingContext (#131078)

Part of https://github.com/flutter/flutter/issues/47161
parent f2ba0a2b
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
import 'package:pub_semver/pub_semver.dart'; import 'package:pub_semver/pub_semver.dart';
import 'base/logger.dart';
import 'build_info.dart'; import 'build_info.dart';
import 'cmake_project.dart'; import 'cmake_project.dart';
import 'globals.dart' as globals;
/// Extracts the `BINARY_NAME` from a project's CMake file. /// Extracts the `BINARY_NAME` from a project's CMake file.
/// ///
...@@ -41,12 +41,12 @@ String _determineVersionString(CmakeBasedProject project, BuildInfo buildInfo) { ...@@ -41,12 +41,12 @@ String _determineVersionString(CmakeBasedProject project, BuildInfo buildInfo) {
: buildName; : buildName;
} }
Version _determineVersion(CmakeBasedProject project, BuildInfo buildInfo) { Version _determineVersion(CmakeBasedProject project, BuildInfo buildInfo, Logger logger) {
final String version = _determineVersionString(project, buildInfo); final String version = _determineVersionString(project, buildInfo);
try { try {
return Version.parse(version); return Version.parse(version);
} on FormatException { } on FormatException {
globals.printWarning('Warning: could not parse version $version, defaulting to 1.0.0.'); logger.printWarning('Warning: could not parse version $version, defaulting to 1.0.0.');
return Version(1, 0, 0); return Version(1, 0, 0);
} }
...@@ -74,25 +74,27 @@ void writeGeneratedCmakeConfig( ...@@ -74,25 +74,27 @@ void writeGeneratedCmakeConfig(
String flutterRoot, String flutterRoot,
CmakeBasedProject project, CmakeBasedProject project,
BuildInfo buildInfo, BuildInfo buildInfo,
Map<String, String> environment) { Map<String, String> environment,
Logger logger,
) {
// Only a limited set of variables are needed by the CMake files themselves, // Only a limited set of variables are needed by the CMake files themselves,
// the rest are put into a list to pass to the re-entrant build step. // the rest are put into a list to pass to the re-entrant build step.
final String escapedFlutterRoot = _escapeBackslashes(flutterRoot); final String escapedFlutterRoot = _escapeBackslashes(flutterRoot);
final String escapedProjectDir = _escapeBackslashes(project.parent.directory.path); final String escapedProjectDir = _escapeBackslashes(project.parent.directory.path);
final Version version = _determineVersion(project, buildInfo); final Version version = _determineVersion(project, buildInfo, logger);
final int? buildVersion = _tryDetermineBuildVersion(version); final int? buildVersion = _tryDetermineBuildVersion(version);
// Since complex Dart build identifiers cannot be converted into integers, // Since complex Dart build identifiers cannot be converted into integers,
// different Dart versions may be converted into the same Windows numeric version. // different Dart versions may be converted into the same Windows numeric version.
// Warn the user as some Windows installers, like MSI, don't update files if their versions are equal. // Warn the user as some Windows installers, like MSI, don't update files if their versions are equal.
if (buildVersion == null && project is WindowsProject) { if (buildVersion == null && project is WindowsProject) {
final String buildIdentifier = version.build.join('.'); final String buildIdentifier = version.build.join('.');
globals.printWarning( logger.printWarning(
'Warning: build identifier $buildIdentifier in version $version is not numeric ' 'Warning: build identifier $buildIdentifier in version $version is not numeric '
'and cannot be converted into a Windows build version number. Defaulting to 0.\n' 'and cannot be converted into a Windows build version number. Defaulting to 0.\n'
'This may cause issues with Windows installers.' 'This may cause issues with Windows installers.'
); );
} }
final StringBuffer buffer = StringBuffer(''' final StringBuffer buffer = StringBuffer('''
......
...@@ -2,8 +2,10 @@ ...@@ -2,8 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import '../base/analyze_size.dart'; import '../base/analyze_size.dart';
import '../base/common.dart'; import '../base/common.dart';
import '../base/logger.dart';
import '../base/os.dart'; import '../base/os.dart';
import '../build_info.dart'; import '../build_info.dart';
import '../cache.dart'; import '../cache.dart';
...@@ -83,18 +85,20 @@ class BuildLinuxCommand extends BuildSubCommand { ...@@ -83,18 +85,20 @@ class BuildLinuxCommand extends BuildSubCommand {
'Cross-build from Linux x64 host to Linux arm64 target is not currently supported.'); 'Cross-build from Linux x64 host to Linux arm64 target is not currently supported.');
} }
displayNullSafetyMode(buildInfo); displayNullSafetyMode(buildInfo);
final Logger logger = globals.logger;
await buildLinux( await buildLinux(
flutterProject.linux, flutterProject.linux,
buildInfo, buildInfo,
target: targetFile, target: targetFile,
sizeAnalyzer: SizeAnalyzer( sizeAnalyzer: SizeAnalyzer(
fileSystem: globals.fs, fileSystem: globals.fs,
logger: globals.logger, logger: logger,
flutterUsage: globals.flutterUsage, flutterUsage: globals.flutterUsage,
), ),
needCrossBuild: needCrossBuild, needCrossBuild: needCrossBuild,
targetPlatform: targetPlatform, targetPlatform: targetPlatform,
targetSysroot: stringArg('target-sysroot')!, targetSysroot: stringArg('target-sysroot')!,
logger: logger,
); );
return FlutterCommandResult.success(); return FlutterCommandResult.success();
} }
......
...@@ -29,12 +29,13 @@ final RegExp errorMatcher = RegExp(r'(?:(?:.*:\d+:\d+|clang):\s)?(fatal\s)?(?:er ...@@ -29,12 +29,13 @@ final RegExp errorMatcher = RegExp(r'(?:(?:.*:\d+:\d+|clang):\s)?(fatal\s)?(?:er
Future<void> buildLinux( Future<void> buildLinux(
LinuxProject linuxProject, LinuxProject linuxProject,
BuildInfo buildInfo, { BuildInfo buildInfo, {
String? target, String? target,
SizeAnalyzer? sizeAnalyzer, SizeAnalyzer? sizeAnalyzer,
bool needCrossBuild = false, bool needCrossBuild = false,
required TargetPlatform targetPlatform, required TargetPlatform targetPlatform,
String targetSysroot = '/', String targetSysroot = '/',
}) async { required Logger logger,
}) async {
target ??= 'lib/main.dart'; target ??= 'lib/main.dart';
if (!linuxProject.cmakeFile.existsSync()) { if (!linuxProject.cmakeFile.existsSync()) {
throwToolExit('No Linux desktop project configured. See ' throwToolExit('No Linux desktop project configured. See '
...@@ -43,7 +44,7 @@ Future<void> buildLinux( ...@@ -43,7 +44,7 @@ Future<void> buildLinux(
} }
final List<ProjectMigrator> migrators = <ProjectMigrator>[ final List<ProjectMigrator> migrators = <ProjectMigrator>[
CmakeCustomCommandMigration(linuxProject, globals.logger), CmakeCustomCommandMigration(linuxProject, logger),
]; ];
final ProjectMigration migration = ProjectMigration(migrators); final ProjectMigration migration = ProjectMigration(migrators);
...@@ -59,11 +60,11 @@ Future<void> buildLinux( ...@@ -59,11 +60,11 @@ Future<void> buildLinux(
environmentConfig['FLUTTER_ENGINE'] = globals.fs.path.dirname(globals.fs.path.dirname(engineOutPath)); environmentConfig['FLUTTER_ENGINE'] = globals.fs.path.dirname(globals.fs.path.dirname(engineOutPath));
environmentConfig['LOCAL_ENGINE'] = localEngineInfo.localEngineName; environmentConfig['LOCAL_ENGINE'] = localEngineInfo.localEngineName;
} }
writeGeneratedCmakeConfig(Cache.flutterRoot!, linuxProject, buildInfo, environmentConfig); writeGeneratedCmakeConfig(Cache.flutterRoot!, linuxProject, buildInfo, environmentConfig, logger);
createPluginSymlinks(linuxProject.parent); createPluginSymlinks(linuxProject.parent);
final Status status = globals.logger.startProgress( final Status status = logger.startProgress(
'Building Linux application...', 'Building Linux application...',
); );
try { try {
...@@ -97,13 +98,13 @@ Future<void> buildLinux( ...@@ -97,13 +98,13 @@ Future<void> buildLinux(
.childDirectory('.flutter-devtools'), 'linux-code-size-analysis', 'json', .childDirectory('.flutter-devtools'), 'linux-code-size-analysis', 'json',
)..writeAsStringSync(jsonEncode(output)); )..writeAsStringSync(jsonEncode(output));
// This message is used as a sentinel in analyze_apk_size_test.dart // This message is used as a sentinel in analyze_apk_size_test.dart
globals.printStatus( logger.printStatus(
'A summary of your Linux bundle analysis can be found at: ${outputFile.path}', 'A summary of your Linux bundle analysis can be found at: ${outputFile.path}',
); );
// DevTools expects a file path relative to the .flutter-devtools/ dir. // DevTools expects a file path relative to the .flutter-devtools/ dir.
final String relativeAppSizePath = outputFile.path.split('.flutter-devtools/').last.trim(); final String relativeAppSizePath = outputFile.path.split('.flutter-devtools/').last.trim();
globals.printStatus( logger.printStatus(
'\nTo analyze your app size in Dart DevTools, run the following command:\n' '\nTo analyze your app size in Dart DevTools, run the following command:\n'
'dart devtools --appSizeBase=$relativeAppSizePath' 'dart devtools --appSizeBase=$relativeAppSizePath'
); );
......
...@@ -25,6 +25,7 @@ class LinuxDevice extends DesktopDevice { ...@@ -25,6 +25,7 @@ class LinuxDevice extends DesktopDevice {
required FileSystem fileSystem, required FileSystem fileSystem,
required OperatingSystemUtils operatingSystemUtils, required OperatingSystemUtils operatingSystemUtils,
}) : _operatingSystemUtils = operatingSystemUtils, }) : _operatingSystemUtils = operatingSystemUtils,
_logger = logger,
super( super(
'linux', 'linux',
platformType: PlatformType.linux, platformType: PlatformType.linux,
...@@ -36,6 +37,7 @@ class LinuxDevice extends DesktopDevice { ...@@ -36,6 +37,7 @@ class LinuxDevice extends DesktopDevice {
); );
final OperatingSystemUtils _operatingSystemUtils; final OperatingSystemUtils _operatingSystemUtils;
final Logger _logger;
@override @override
bool isSupported() => true; bool isSupported() => true;
...@@ -66,6 +68,7 @@ class LinuxDevice extends DesktopDevice { ...@@ -66,6 +68,7 @@ class LinuxDevice extends DesktopDevice {
buildInfo, buildInfo,
target: mainPath, target: mainPath,
targetPlatform: await targetPlatform, targetPlatform: await targetPlatform,
logger: _logger,
); );
} }
......
...@@ -54,7 +54,9 @@ class HotEvent extends UsageEvent { ...@@ -54,7 +54,9 @@ class HotEvent extends UsageEvent {
this.scannedSourcesCount, this.scannedSourcesCount,
this.reassembleTimeInMs, this.reassembleTimeInMs,
this.reloadVMTimeInMs, this.reloadVMTimeInMs,
}) : super('hot', parameter, flutterUsage: globals.flutterUsage); // TODO(fujino): make this required
Usage? usage,
}) : super('hot', parameter, flutterUsage: usage ?? globals.flutterUsage);
final String? reason; final String? reason;
final String targetPlatform; final String targetPlatform;
......
...@@ -950,6 +950,7 @@ class HotRunner extends ResidentRunner { ...@@ -950,6 +950,7 @@ class HotRunner extends ResidentRunner {
sdkName, sdkName,
emulator, emulator,
reason, reason,
globals.flutterUsage,
); );
if (result.code != 0) { if (result.code != 0) {
return result; return result;
...@@ -1172,6 +1173,7 @@ typedef ReloadSourcesHelper = Future<OperationResult> Function( ...@@ -1172,6 +1173,7 @@ typedef ReloadSourcesHelper = Future<OperationResult> Function(
String? sdkName, String? sdkName,
bool? emulator, bool? emulator,
String? reason, String? reason,
Usage usage,
); );
@visibleForTesting @visibleForTesting
...@@ -1184,6 +1186,7 @@ Future<OperationResult> defaultReloadSourcesHelper( ...@@ -1184,6 +1186,7 @@ Future<OperationResult> defaultReloadSourcesHelper(
String? sdkName, String? sdkName,
bool? emulator, bool? emulator,
String? reason, String? reason,
Usage usage,
) async { ) async {
final Stopwatch vmReloadTimer = Stopwatch()..start(); final Stopwatch vmReloadTimer = Stopwatch()..start();
const String entryPath = 'main.dart.incremental.dill'; const String entryPath = 'main.dart.incremental.dill';
...@@ -1223,6 +1226,7 @@ Future<OperationResult> defaultReloadSourcesHelper( ...@@ -1223,6 +1226,7 @@ Future<OperationResult> defaultReloadSourcesHelper(
fullRestart: false, fullRestart: false,
reason: reason, reason: reason,
fastReassemble: false, fastReassemble: false,
usage: usage,
).send(); ).send();
// Reset devFS lastCompileTime to ensure the file will still be marked // Reset devFS lastCompileTime to ensure the file will still be marked
// as dirty on subsequent reloads. // as dirty on subsequent reloads.
......
...@@ -242,7 +242,7 @@ void _writeGeneratedFlutterConfig( ...@@ -242,7 +242,7 @@ void _writeGeneratedFlutterConfig(
environment['FLUTTER_ENGINE'] = globals.fs.path.dirname(globals.fs.path.dirname(engineOutPath)); environment['FLUTTER_ENGINE'] = globals.fs.path.dirname(globals.fs.path.dirname(engineOutPath));
environment['LOCAL_ENGINE'] = localEngineInfo.localEngineName; environment['LOCAL_ENGINE'] = localEngineInfo.localEngineName;
} }
writeGeneratedCmakeConfig(Cache.flutterRoot!, windowsProject, buildInfo, environment); writeGeneratedCmakeConfig(Cache.flutterRoot!, windowsProject, buildInfo, environment, globals.logger);
} }
// Works around the Visual Studio 17.1.0 CMake bug described in // Works around the Visual Studio 17.1.0 CMake bug described in
......
...@@ -366,6 +366,7 @@ void main() { ...@@ -366,6 +366,7 @@ void main() {
String? sdkName, String? sdkName,
bool? emulator, bool? emulator,
String? reason, String? reason,
Usage usage,
) async { ) async {
firstReloadDetails['finalLibraryCount'] = 2; firstReloadDetails['finalLibraryCount'] = 2;
firstReloadDetails['receivedLibraryCount'] = 3; firstReloadDetails['receivedLibraryCount'] = 3;
......
...@@ -3,16 +3,18 @@ ...@@ -3,16 +3,18 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter_tools/src/devfs.dart'; import 'package:flutter_tools/src/devfs.dart';
import 'package:flutter_tools/src/reporting/reporting.dart';
import 'package:flutter_tools/src/resident_runner.dart'; import 'package:flutter_tools/src/resident_runner.dart';
import 'package:flutter_tools/src/run_hot.dart'; import 'package:flutter_tools/src/run_hot.dart';
import 'package:flutter_tools/src/vmservice.dart'; import 'package:flutter_tools/src/vmservice.dart';
import 'package:test/fake.dart'; import 'package:test/fake.dart';
import 'package:vm_service/vm_service.dart' as vm_service; import 'package:vm_service/vm_service.dart' as vm_service;
import '../src/context.dart'; //import '../src/context.dart';
import '../src/common.dart';
void main() { void main() {
testUsingContext('defaultReloadSourcesHelper() handles empty DeviceReloadReports)', () { testWithoutContext('defaultReloadSourcesHelper() handles empty DeviceReloadReports)', () {
defaultReloadSourcesHelper( defaultReloadSourcesHelper(
_FakeHotRunner(), _FakeHotRunner(),
<FlutterDevice?>[_FakeFlutterDevice()], <FlutterDevice?>[_FakeFlutterDevice()],
...@@ -22,6 +24,7 @@ void main() { ...@@ -22,6 +24,7 @@ void main() {
'flutter-sdk', 'flutter-sdk',
false, false,
'test-reason', 'test-reason',
TestUsage(),
); );
}); });
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment