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 @@
import 'package:pub_semver/pub_semver.dart';
import 'base/logger.dart';
import 'build_info.dart';
import 'cmake_project.dart';
import 'globals.dart' as globals;
/// Extracts the `BINARY_NAME` from a project's CMake file.
///
......@@ -41,12 +41,12 @@ String _determineVersionString(CmakeBasedProject project, BuildInfo buildInfo) {
: buildName;
}
Version _determineVersion(CmakeBasedProject project, BuildInfo buildInfo) {
Version _determineVersion(CmakeBasedProject project, BuildInfo buildInfo, Logger logger) {
final String version = _determineVersionString(project, buildInfo);
try {
return Version.parse(version);
} 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);
}
......@@ -74,13 +74,15 @@ void writeGeneratedCmakeConfig(
String flutterRoot,
CmakeBasedProject project,
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,
// the rest are put into a list to pass to the re-entrant build step.
final String escapedFlutterRoot = _escapeBackslashes(flutterRoot);
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);
// Since complex Dart build identifiers cannot be converted into integers,
......@@ -88,7 +90,7 @@ void writeGeneratedCmakeConfig(
// Warn the user as some Windows installers, like MSI, don't update files if their versions are equal.
if (buildVersion == null && project is WindowsProject) {
final String buildIdentifier = version.build.join('.');
globals.printWarning(
logger.printWarning(
'Warning: build identifier $buildIdentifier in version $version is not numeric '
'and cannot be converted into a Windows build version number. Defaulting to 0.\n'
'This may cause issues with Windows installers.'
......
......@@ -2,8 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import '../base/analyze_size.dart';
import '../base/common.dart';
import '../base/logger.dart';
import '../base/os.dart';
import '../build_info.dart';
import '../cache.dart';
......@@ -83,18 +85,20 @@ class BuildLinuxCommand extends BuildSubCommand {
'Cross-build from Linux x64 host to Linux arm64 target is not currently supported.');
}
displayNullSafetyMode(buildInfo);
final Logger logger = globals.logger;
await buildLinux(
flutterProject.linux,
buildInfo,
target: targetFile,
sizeAnalyzer: SizeAnalyzer(
fileSystem: globals.fs,
logger: globals.logger,
logger: logger,
flutterUsage: globals.flutterUsage,
),
needCrossBuild: needCrossBuild,
targetPlatform: targetPlatform,
targetSysroot: stringArg('target-sysroot')!,
logger: logger,
);
return FlutterCommandResult.success();
}
......
......@@ -34,7 +34,8 @@ Future<void> buildLinux(
bool needCrossBuild = false,
required TargetPlatform targetPlatform,
String targetSysroot = '/',
}) async {
required Logger logger,
}) async {
target ??= 'lib/main.dart';
if (!linuxProject.cmakeFile.existsSync()) {
throwToolExit('No Linux desktop project configured. See '
......@@ -43,7 +44,7 @@ Future<void> buildLinux(
}
final List<ProjectMigrator> migrators = <ProjectMigrator>[
CmakeCustomCommandMigration(linuxProject, globals.logger),
CmakeCustomCommandMigration(linuxProject, logger),
];
final ProjectMigration migration = ProjectMigration(migrators);
......@@ -59,11 +60,11 @@ Future<void> buildLinux(
environmentConfig['FLUTTER_ENGINE'] = globals.fs.path.dirname(globals.fs.path.dirname(engineOutPath));
environmentConfig['LOCAL_ENGINE'] = localEngineInfo.localEngineName;
}
writeGeneratedCmakeConfig(Cache.flutterRoot!, linuxProject, buildInfo, environmentConfig);
writeGeneratedCmakeConfig(Cache.flutterRoot!, linuxProject, buildInfo, environmentConfig, logger);
createPluginSymlinks(linuxProject.parent);
final Status status = globals.logger.startProgress(
final Status status = logger.startProgress(
'Building Linux application...',
);
try {
......@@ -97,13 +98,13 @@ Future<void> buildLinux(
.childDirectory('.flutter-devtools'), 'linux-code-size-analysis', 'json',
)..writeAsStringSync(jsonEncode(output));
// 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}',
);
// DevTools expects a file path relative to the .flutter-devtools/ dir.
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'
'dart devtools --appSizeBase=$relativeAppSizePath'
);
......
......@@ -25,6 +25,7 @@ class LinuxDevice extends DesktopDevice {
required FileSystem fileSystem,
required OperatingSystemUtils operatingSystemUtils,
}) : _operatingSystemUtils = operatingSystemUtils,
_logger = logger,
super(
'linux',
platformType: PlatformType.linux,
......@@ -36,6 +37,7 @@ class LinuxDevice extends DesktopDevice {
);
final OperatingSystemUtils _operatingSystemUtils;
final Logger _logger;
@override
bool isSupported() => true;
......@@ -66,6 +68,7 @@ class LinuxDevice extends DesktopDevice {
buildInfo,
target: mainPath,
targetPlatform: await targetPlatform,
logger: _logger,
);
}
......
......@@ -54,7 +54,9 @@ class HotEvent extends UsageEvent {
this.scannedSourcesCount,
this.reassembleTimeInMs,
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 targetPlatform;
......
......@@ -950,6 +950,7 @@ class HotRunner extends ResidentRunner {
sdkName,
emulator,
reason,
globals.flutterUsage,
);
if (result.code != 0) {
return result;
......@@ -1172,6 +1173,7 @@ typedef ReloadSourcesHelper = Future<OperationResult> Function(
String? sdkName,
bool? emulator,
String? reason,
Usage usage,
);
@visibleForTesting
......@@ -1184,6 +1186,7 @@ Future<OperationResult> defaultReloadSourcesHelper(
String? sdkName,
bool? emulator,
String? reason,
Usage usage,
) async {
final Stopwatch vmReloadTimer = Stopwatch()..start();
const String entryPath = 'main.dart.incremental.dill';
......@@ -1223,6 +1226,7 @@ Future<OperationResult> defaultReloadSourcesHelper(
fullRestart: false,
reason: reason,
fastReassemble: false,
usage: usage,
).send();
// Reset devFS lastCompileTime to ensure the file will still be marked
// as dirty on subsequent reloads.
......
......@@ -242,7 +242,7 @@ void _writeGeneratedFlutterConfig(
environment['FLUTTER_ENGINE'] = globals.fs.path.dirname(globals.fs.path.dirname(engineOutPath));
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
......
......@@ -366,6 +366,7 @@ void main() {
String? sdkName,
bool? emulator,
String? reason,
Usage usage,
) async {
firstReloadDetails['finalLibraryCount'] = 2;
firstReloadDetails['receivedLibraryCount'] = 3;
......
......@@ -3,16 +3,18 @@
// found in the LICENSE file.
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/run_hot.dart';
import 'package:flutter_tools/src/vmservice.dart';
import 'package:test/fake.dart';
import 'package:vm_service/vm_service.dart' as vm_service;
import '../src/context.dart';
//import '../src/context.dart';
import '../src/common.dart';
void main() {
testUsingContext('defaultReloadSourcesHelper() handles empty DeviceReloadReports)', () {
testWithoutContext('defaultReloadSourcesHelper() handles empty DeviceReloadReports)', () {
defaultReloadSourcesHelper(
_FakeHotRunner(),
<FlutterDevice?>[_FakeFlutterDevice()],
......@@ -22,6 +24,7 @@ void main() {
'flutter-sdk',
false,
'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