mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Split globals.dart into null sound and unsound libraries (#79016)
This commit is contained in:
parent
dff957fb5c
commit
8ddc27e607
@ -13,7 +13,7 @@ import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/context_runner.dart';
|
||||
import 'package:flutter_tools/src/devfs.dart';
|
||||
import 'package:flutter_tools/src/bundle.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
import 'package:flutter_tools/src/reporting/reporting.dart';
|
||||
|
||||
const String _kOptionPackages = 'packages';
|
||||
|
@ -10,7 +10,7 @@ import '../base/io.dart';
|
||||
import '../base/process.dart';
|
||||
import '../base/utils.dart';
|
||||
import '../base/version.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../globals_null_migrated.dart' as globals;
|
||||
import '../ios/plist_parser.dart';
|
||||
|
||||
AndroidStudio get androidStudio => context.get<AndroidStudio>();
|
||||
|
@ -12,7 +12,7 @@ import '../base/error_handling_io.dart';
|
||||
import '../base/file_system.dart';
|
||||
import '../base/logger.dart';
|
||||
import '../base/platform.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../globals_null_migrated.dart' as globals;
|
||||
import '../project.dart';
|
||||
import '../template.dart';
|
||||
import 'deferred_components_validator.dart';
|
||||
|
@ -113,7 +113,7 @@ class AppContext {
|
||||
|
||||
/// Gets the value associated with the specified [type], or `null` if no
|
||||
/// such value has been associated.
|
||||
T get<T>() {
|
||||
T? get<T>() {
|
||||
dynamic value = _generateIfNecessary(T, _overrides);
|
||||
if (value == null && _parent != null) {
|
||||
value = _parent!.get<T>();
|
||||
|
@ -5,7 +5,7 @@
|
||||
import 'context.dart';
|
||||
import 'platform.dart';
|
||||
|
||||
UserMessages get userMessages => context.get<UserMessages>();
|
||||
UserMessages get userMessages => context.get<UserMessages>()!;
|
||||
|
||||
/// Class containing message strings that can be produced by Flutter tools.
|
||||
class UserMessages {
|
||||
|
@ -15,7 +15,7 @@ import 'base/os.dart';
|
||||
import 'base/utils.dart';
|
||||
import 'build_system/targets/icon_tree_shaker.dart';
|
||||
import 'convert.dart';
|
||||
import 'globals.dart' as globals;
|
||||
import 'globals_null_migrated.dart' as globals;
|
||||
|
||||
/// Information about a build to be performed or used.
|
||||
class BuildInfo {
|
||||
|
@ -9,7 +9,7 @@ import '../../base/build.dart';
|
||||
import '../../base/deferred_component.dart';
|
||||
import '../../base/file_system.dart';
|
||||
import '../../build_info.dart';
|
||||
import '../../globals.dart' as globals hide fs, artifacts, logger, processManager;
|
||||
import '../../globals.dart' as globals show platform, printError, xcode;
|
||||
import '../../project.dart';
|
||||
import '../build_system.dart';
|
||||
import '../depfile.dart';
|
||||
|
@ -12,7 +12,7 @@ import '../../base/file_system.dart';
|
||||
import '../../build_info.dart';
|
||||
import '../../compile.dart';
|
||||
import '../../dart/package_map.dart';
|
||||
import '../../globals.dart' as globals hide fs, processManager, artifacts, logger;
|
||||
import '../../globals.dart' as globals show xcode;
|
||||
import '../build_system.dart';
|
||||
import '../depfile.dart';
|
||||
import '../exceptions.dart';
|
||||
|
@ -12,7 +12,7 @@ import '../../base/common.dart';
|
||||
import '../../base/file_system.dart';
|
||||
import '../../base/io.dart';
|
||||
import '../../build_info.dart';
|
||||
import '../../globals.dart' as globals hide fs, logger, processManager, artifacts;
|
||||
import '../../globals.dart' as globals show xcode;
|
||||
import '../../macos/xcode.dart';
|
||||
import '../../project.dart';
|
||||
import '../build_system.dart';
|
||||
|
@ -10,7 +10,7 @@ import '../../base/file_system.dart';
|
||||
import '../../base/io.dart';
|
||||
import '../../base/process.dart';
|
||||
import '../../build_info.dart';
|
||||
import '../../globals.dart' as globals hide fs, logger, artifacts, processManager;
|
||||
import '../../globals.dart' as globals show xcode;
|
||||
import '../build_system.dart';
|
||||
import '../depfile.dart';
|
||||
import '../exceptions.dart';
|
||||
|
@ -18,7 +18,7 @@ import '../base/terminal.dart';
|
||||
import '../base/utils.dart';
|
||||
import '../cache.dart';
|
||||
import '../dart/analysis.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../globals_null_migrated.dart' as globals;
|
||||
|
||||
/// Common behavior for `flutter analyze` and `flutter analyze --watch`
|
||||
abstract class AnalyzeBase {
|
||||
|
@ -8,7 +8,7 @@ import '../base/common.dart';
|
||||
import '../build_info.dart';
|
||||
import '../bundle.dart';
|
||||
import '../features.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../globals_null_migrated.dart' as globals;
|
||||
import '../project.dart';
|
||||
import '../reporting/reporting.dart';
|
||||
import '../runner/flutter_command.dart';
|
||||
|
@ -12,7 +12,7 @@ import '../cache.dart';
|
||||
import '../features.dart';
|
||||
import '../fuchsia/fuchsia_build.dart';
|
||||
import '../fuchsia/fuchsia_pm.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../globals_null_migrated.dart' as globals;
|
||||
import '../project.dart';
|
||||
import '../runner/flutter_command.dart' show FlutterCommandResult;
|
||||
import 'build.dart';
|
||||
|
@ -10,7 +10,7 @@ import '../base/common.dart';
|
||||
import '../build_info.dart';
|
||||
import '../cache.dart';
|
||||
import '../features.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../globals_null_migrated.dart' as globals;
|
||||
import '../project.dart';
|
||||
import '../runner/flutter_command.dart' show FlutterCommandResult;
|
||||
import '../windows/build_windows.dart';
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
// @dart = 2.8
|
||||
|
||||
import '../globals.dart' as globals;
|
||||
import '../globals_null_migrated.dart' as globals;
|
||||
import '../runner/flutter_command.dart';
|
||||
|
||||
class GenerateCommand extends FlutterCommand {
|
||||
|
@ -7,7 +7,7 @@
|
||||
import '../base/common.dart';
|
||||
import '../base/file_system.dart';
|
||||
import '../base/logger.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../globals_null_migrated.dart' as globals;
|
||||
import '../localizations/gen_l10n.dart';
|
||||
import '../localizations/gen_l10n_types.dart';
|
||||
import '../localizations/localizations_utils.dart';
|
||||
|
@ -7,7 +7,7 @@
|
||||
import '../base/common.dart';
|
||||
import '../base/file_system.dart';
|
||||
import '../cache.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../globals_null_migrated.dart' as globals;
|
||||
import '../runner/flutter_command.dart';
|
||||
import '../template.dart';
|
||||
|
||||
|
@ -9,7 +9,7 @@ import '../application_package.dart';
|
||||
import '../base/common.dart';
|
||||
import '../base/io.dart';
|
||||
import '../device.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../globals_null_migrated.dart' as globals;
|
||||
import '../runner/flutter_command.dart';
|
||||
|
||||
class InstallCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
|
||||
|
@ -10,7 +10,7 @@ import '../base/common.dart';
|
||||
import '../base/io.dart';
|
||||
import '../cache.dart';
|
||||
import '../device.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../globals_null_migrated.dart' as globals;
|
||||
import '../runner/flutter_command.dart';
|
||||
|
||||
class LogsCommand extends FlutterCommand {
|
||||
|
@ -10,7 +10,7 @@ import '../base/common.dart';
|
||||
import '../base/file_system.dart';
|
||||
import '../convert.dart';
|
||||
import '../device.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../globals_null_migrated.dart' as globals;
|
||||
import '../runner/flutter_command.dart';
|
||||
import '../vmservice.dart';
|
||||
|
||||
|
@ -8,7 +8,7 @@ import 'package:completion/completion.dart';
|
||||
|
||||
import '../base/common.dart';
|
||||
import '../base/file_system.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../globals_null_migrated.dart' as globals;
|
||||
import '../runner/flutter_command.dart';
|
||||
|
||||
class ShellCompletionCommand extends FlutterCommand {
|
||||
|
@ -16,7 +16,7 @@ import '../bundle.dart';
|
||||
import '../cache.dart';
|
||||
import '../devfs.dart';
|
||||
import '../device.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../globals_null_migrated.dart' as globals;
|
||||
import '../project.dart';
|
||||
import '../runner/flutter_command.dart';
|
||||
import '../test/coverage_collector.dart';
|
||||
|
@ -15,7 +15,7 @@ import '../base/logger.dart';
|
||||
import '../base/net.dart';
|
||||
import '../cache.dart';
|
||||
import '../dart/pub.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../globals_null_migrated.dart' as globals;
|
||||
import '../runner/flutter_command.dart';
|
||||
|
||||
/// Map from package name to package version, used to artificially pin a pub
|
||||
|
@ -9,7 +9,7 @@ import 'package:meta/meta.dart';
|
||||
import '../application_package.dart';
|
||||
import '../base/file_system.dart';
|
||||
import '../build_info.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../globals_null_migrated.dart' as globals;
|
||||
import '../project.dart';
|
||||
|
||||
abstract class FuchsiaApp extends ApplicationPackage {
|
||||
|
@ -5,7 +5,7 @@
|
||||
// @dart = 2.8
|
||||
|
||||
import '../base/process.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../globals_null_migrated.dart' as globals;
|
||||
|
||||
import 'fuchsia_device.dart';
|
||||
|
||||
|
@ -4,35 +4,21 @@
|
||||
|
||||
// @dart = 2.8
|
||||
|
||||
import 'package:process/process.dart';
|
||||
|
||||
import 'android/android_sdk.dart';
|
||||
import 'android/android_studio.dart';
|
||||
import 'android/gradle_utils.dart';
|
||||
import 'artifacts.dart';
|
||||
import 'base/bot_detector.dart';
|
||||
import 'base/config.dart';
|
||||
import 'base/context.dart';
|
||||
import 'base/error_handling_io.dart';
|
||||
import 'base/file_system.dart';
|
||||
import 'base/io.dart';
|
||||
import 'base/logger.dart';
|
||||
import 'base/net.dart';
|
||||
import 'base/os.dart';
|
||||
import 'base/platform.dart';
|
||||
import 'base/process.dart';
|
||||
import 'base/signals.dart';
|
||||
import 'base/template.dart';
|
||||
import 'base/terminal.dart';
|
||||
import 'base/time.dart';
|
||||
import 'base/user_messages.dart';
|
||||
import 'build_system/build_system.dart';
|
||||
import 'cache.dart';
|
||||
import 'device.dart';
|
||||
import 'doctor.dart';
|
||||
import 'fuchsia/fuchsia_sdk.dart';
|
||||
import 'globals_null_migrated.dart' as globals;
|
||||
import 'ios/ios_workflow.dart';
|
||||
import 'ios/plist_parser.dart';
|
||||
import 'ios/simulators.dart';
|
||||
import 'ios/xcodeproj.dart';
|
||||
import 'macos/cocoapods.dart';
|
||||
@ -44,24 +30,21 @@ import 'reporting/reporting.dart';
|
||||
import 'runner/local_engine.dart';
|
||||
import 'version.dart';
|
||||
|
||||
export 'globals_null_migrated.dart';
|
||||
|
||||
Artifacts get artifacts => context.get<Artifacts>();
|
||||
BuildSystem get buildSystem => context.get<BuildSystem>();
|
||||
Cache get cache => context.get<Cache>();
|
||||
Config get config => context.get<Config>();
|
||||
CrashReporter get crashReporter => context.get<CrashReporter>();
|
||||
Doctor get doctor => context.get<Doctor>();
|
||||
HttpClientFactory get httpClientFactory => context.get<HttpClientFactory>();
|
||||
Logger get logger => context.get<Logger>();
|
||||
OperatingSystemUtils get os => context.get<OperatingSystemUtils>();
|
||||
PersistentToolState get persistentToolState => PersistentToolState.instance;
|
||||
Signals get signals => context.get<Signals>() ?? LocalSignals.instance;
|
||||
Usage get flutterUsage => context.get<Usage>();
|
||||
DeviceManager get deviceManager => context.get<DeviceManager>();
|
||||
|
||||
FlutterProjectFactory get projectFactory {
|
||||
return context.get<FlutterProjectFactory>() ?? FlutterProjectFactory(
|
||||
logger: logger,
|
||||
fileSystem: fs,
|
||||
logger: globals.logger,
|
||||
fileSystem: globals.fs,
|
||||
);
|
||||
}
|
||||
|
||||
@ -69,30 +52,6 @@ CocoaPodsValidator get cocoapodsValidator => context.get<CocoaPodsValidator>();
|
||||
|
||||
LocalEngineLocator get localEngineLocator => context.get<LocalEngineLocator>();
|
||||
|
||||
/// Currently active implementation of the file system.
|
||||
///
|
||||
/// By default it uses local disk-based implementation. Override this in tests
|
||||
/// with [MemoryFileSystem].
|
||||
FileSystem get fs => ErrorHandlingFileSystem(
|
||||
delegate: context.get<FileSystem>() ?? localFileSystem,
|
||||
platform: platform,
|
||||
);
|
||||
|
||||
FileSystemUtils get fsUtils => context.get<FileSystemUtils>() ?? FileSystemUtils(
|
||||
fileSystem: fs,
|
||||
platform: platform,
|
||||
);
|
||||
|
||||
const ProcessManager _kLocalProcessManager = LocalProcessManager();
|
||||
|
||||
/// The active process manager.
|
||||
ProcessManager get processManager => context.get<ProcessManager>() ?? _kLocalProcessManager;
|
||||
ProcessUtils get processUtils => context.get<ProcessUtils>();
|
||||
|
||||
const Platform _kLocalPlatform = LocalPlatform();
|
||||
|
||||
Platform get platform => context.get<Platform>() ?? _kLocalPlatform;
|
||||
|
||||
AndroidStudio get androidStudio => context.get<AndroidStudio>();
|
||||
AndroidSdk get androidSdk => context.get<AndroidSdk>();
|
||||
CocoaPods get cocoaPods => context.get<CocoaPods>();
|
||||
@ -100,22 +59,14 @@ FlutterVersion get flutterVersion => context.get<FlutterVersion>();
|
||||
FuchsiaArtifacts get fuchsiaArtifacts => context.get<FuchsiaArtifacts>();
|
||||
IOSSimulatorUtils get iosSimulatorUtils => context.get<IOSSimulatorUtils>();
|
||||
IOSWorkflow get iosWorkflow => context.get<IOSWorkflow>();
|
||||
UserMessages get userMessages => context.get<UserMessages>();
|
||||
Xcode get xcode => context.get<Xcode>();
|
||||
XcodeProjectInterpreter get xcodeProjectInterpreter => context.get<XcodeProjectInterpreter>();
|
||||
|
||||
XCDevice get xcdevice => context.get<XCDevice>();
|
||||
|
||||
final OutputPreferences _default = OutputPreferences(
|
||||
wrapText: stdio.hasTerminal ?? false,
|
||||
showColor: platform.stdoutSupportsAnsi,
|
||||
stdio: stdio,
|
||||
);
|
||||
OutputPreferences get outputPreferences => context.get<OutputPreferences>() ?? _default;
|
||||
|
||||
final BotDetector _defaultBotDetector = BotDetector(
|
||||
httpClientFactory: context.get<HttpClientFactory>() ?? () => HttpClient(),
|
||||
platform: platform,
|
||||
platform: globals.platform,
|
||||
persistentToolState: persistentToolState,
|
||||
);
|
||||
|
||||
@ -123,105 +74,5 @@ BotDetector get botDetector => context.get<BotDetector>() ?? _defaultBotDetector
|
||||
|
||||
Future<bool> get isRunningOnBot => botDetector.isRunningOnBot;
|
||||
|
||||
/// The current system clock instance.
|
||||
SystemClock get systemClock => context.get<SystemClock>();
|
||||
|
||||
ProcessInfo get processInfo => context.get<ProcessInfo>();
|
||||
|
||||
/// Display an error level message to the user. Commands should use this if they
|
||||
/// fail in some way.
|
||||
///
|
||||
/// Set [emphasis] to true to make the output bold if it's supported.
|
||||
/// Set [color] to a [TerminalColor] to color the output, if the logger
|
||||
/// supports it. The [color] defaults to [TerminalColor.red].
|
||||
void printError(
|
||||
String message, {
|
||||
StackTrace stackTrace,
|
||||
bool emphasis,
|
||||
TerminalColor color,
|
||||
int indent,
|
||||
int hangingIndent,
|
||||
bool wrap,
|
||||
}) {
|
||||
logger.printError(
|
||||
message,
|
||||
stackTrace: stackTrace,
|
||||
emphasis: emphasis ?? false,
|
||||
color: color,
|
||||
indent: indent,
|
||||
hangingIndent: hangingIndent,
|
||||
wrap: wrap,
|
||||
);
|
||||
}
|
||||
|
||||
/// Display normal output of the command. This should be used for things like
|
||||
/// progress messages, success messages, or just normal command output.
|
||||
///
|
||||
/// Set `emphasis` to true to make the output bold if it's supported.
|
||||
///
|
||||
/// Set `newline` to false to skip the trailing linefeed.
|
||||
///
|
||||
/// If `indent` is provided, each line of the message will be prepended by the
|
||||
/// specified number of whitespaces.
|
||||
void printStatus(
|
||||
String message, {
|
||||
bool emphasis,
|
||||
bool newline,
|
||||
TerminalColor color,
|
||||
int indent,
|
||||
int hangingIndent,
|
||||
bool wrap,
|
||||
}) {
|
||||
logger.printStatus(
|
||||
message,
|
||||
emphasis: emphasis ?? false,
|
||||
color: color,
|
||||
newline: newline ?? true,
|
||||
indent: indent,
|
||||
hangingIndent: hangingIndent,
|
||||
wrap: wrap,
|
||||
);
|
||||
}
|
||||
|
||||
/// Use this for verbose tracing output. Users can turn this output on in order
|
||||
/// to help diagnose issues with the toolchain or with their setup.
|
||||
void printTrace(String message) => logger.printTrace(message);
|
||||
|
||||
AnsiTerminal get terminal {
|
||||
return context?.get<AnsiTerminal>() ?? _defaultAnsiTerminal;
|
||||
}
|
||||
|
||||
final AnsiTerminal _defaultAnsiTerminal = AnsiTerminal(
|
||||
stdio: stdio,
|
||||
platform: platform,
|
||||
);
|
||||
|
||||
/// The global Stdio wrapper.
|
||||
Stdio get stdio => context.get<Stdio>() ?? (_stdioInstance ??= Stdio());
|
||||
Stdio _stdioInstance;
|
||||
|
||||
PlistParser get plistParser => context.get<PlistParser>() ?? (
|
||||
_plistInstance ??= PlistParser(
|
||||
fileSystem: fs,
|
||||
processManager: processManager,
|
||||
logger: logger,
|
||||
));
|
||||
PlistParser _plistInstance;
|
||||
|
||||
/// The global template renderer.
|
||||
TemplateRenderer get templateRenderer => context.get<TemplateRenderer>();
|
||||
|
||||
/// Gradle utils in the current [AppContext].
|
||||
GradleUtils get gradleUtils => context.get<GradleUtils>();
|
||||
|
||||
ShutdownHooks get shutdownHooks => context.get<ShutdownHooks>();
|
||||
|
||||
// Unless we're in a test of this class's signal handling features, we must
|
||||
// have only one instance created with the singleton LocalSignals instance
|
||||
// and the catchable signals it considers to be fatal.
|
||||
LocalFileSystem _instance;
|
||||
LocalFileSystem get localFileSystem => _instance ??= LocalFileSystem(
|
||||
LocalSignals.instance,
|
||||
Signals.defaultExitSignals,
|
||||
shutdownHooks,
|
||||
);
|
||||
|
161
packages/flutter_tools/lib/src/globals_null_migrated.dart
Normal file
161
packages/flutter_tools/lib/src/globals_null_migrated.dart
Normal file
@ -0,0 +1,161 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:process/process.dart';
|
||||
|
||||
import 'base/config.dart';
|
||||
import 'base/context.dart';
|
||||
import 'base/error_handling_io.dart';
|
||||
import 'base/file_system.dart';
|
||||
import 'base/io.dart';
|
||||
import 'base/logger.dart';
|
||||
import 'base/net.dart';
|
||||
import 'base/os.dart';
|
||||
import 'base/platform.dart';
|
||||
import 'base/process.dart';
|
||||
import 'base/signals.dart';
|
||||
import 'base/template.dart';
|
||||
import 'base/terminal.dart';
|
||||
import 'base/time.dart';
|
||||
import 'base/user_messages.dart';
|
||||
import 'ios/plist_parser.dart';
|
||||
|
||||
Config get config => context.get<Config>()!;
|
||||
HttpClientFactory get httpClientFactory => context.get<HttpClientFactory>()!;
|
||||
Logger get logger => context.get<Logger>()!;
|
||||
OperatingSystemUtils get os => context.get<OperatingSystemUtils>()!;
|
||||
Signals get signals => context.get<Signals>() ?? LocalSignals.instance;
|
||||
|
||||
/// Currently active implementation of the file system.
|
||||
///
|
||||
/// By default it uses local disk-based implementation. Override this in tests
|
||||
/// with [MemoryFileSystem].
|
||||
FileSystem get fs => ErrorHandlingFileSystem(
|
||||
delegate: context.get<FileSystem>() ?? localFileSystem,
|
||||
platform: platform,
|
||||
);
|
||||
|
||||
FileSystemUtils get fsUtils => context.get<FileSystemUtils>() ?? FileSystemUtils(
|
||||
fileSystem: fs,
|
||||
platform: platform,
|
||||
);
|
||||
|
||||
const ProcessManager _kLocalProcessManager = LocalProcessManager();
|
||||
|
||||
/// The active process manager.
|
||||
ProcessManager get processManager => context.get<ProcessManager>() ?? _kLocalProcessManager;
|
||||
ProcessUtils get processUtils => context.get<ProcessUtils>()!;
|
||||
|
||||
const Platform _kLocalPlatform = LocalPlatform();
|
||||
Platform get platform => context.get<Platform>() ?? _kLocalPlatform;
|
||||
|
||||
UserMessages get userMessages => context.get<UserMessages>()!;
|
||||
|
||||
final OutputPreferences _default = OutputPreferences(
|
||||
wrapText: stdio.hasTerminal,
|
||||
showColor: platform.stdoutSupportsAnsi,
|
||||
stdio: stdio,
|
||||
);
|
||||
OutputPreferences get outputPreferences => context.get<OutputPreferences>() ?? _default;
|
||||
|
||||
/// The current system clock instance.
|
||||
SystemClock get systemClock => context.get<SystemClock>() ?? _systemClock;
|
||||
SystemClock _systemClock = const SystemClock();
|
||||
|
||||
ProcessInfo get processInfo => context.get<ProcessInfo>()!;
|
||||
|
||||
/// Display an error level message to the user. Commands should use this if they
|
||||
/// fail in some way.
|
||||
///
|
||||
/// Set [emphasis] to true to make the output bold if it's supported.
|
||||
/// Set [color] to a [TerminalColor] to color the output, if the logger
|
||||
/// supports it. The [color] defaults to [TerminalColor.red].
|
||||
void printError(
|
||||
String message, {
|
||||
StackTrace? stackTrace,
|
||||
bool? emphasis,
|
||||
TerminalColor? color,
|
||||
int? indent,
|
||||
int? hangingIndent,
|
||||
bool? wrap,
|
||||
}) {
|
||||
logger.printError(
|
||||
message,
|
||||
stackTrace: stackTrace,
|
||||
emphasis: emphasis ?? false,
|
||||
color: color,
|
||||
indent: indent,
|
||||
hangingIndent: hangingIndent,
|
||||
wrap: wrap,
|
||||
);
|
||||
}
|
||||
|
||||
/// Display normal output of the command. This should be used for things like
|
||||
/// progress messages, success messages, or just normal command output.
|
||||
///
|
||||
/// Set `emphasis` to true to make the output bold if it's supported.
|
||||
///
|
||||
/// Set `newline` to false to skip the trailing linefeed.
|
||||
///
|
||||
/// If `indent` is provided, each line of the message will be prepended by the
|
||||
/// specified number of whitespaces.
|
||||
void printStatus(
|
||||
String message, {
|
||||
bool? emphasis,
|
||||
bool? newline,
|
||||
TerminalColor? color,
|
||||
int? indent,
|
||||
int? hangingIndent,
|
||||
bool? wrap,
|
||||
}) {
|
||||
logger.printStatus(
|
||||
message,
|
||||
emphasis: emphasis ?? false,
|
||||
color: color,
|
||||
newline: newline ?? true,
|
||||
indent: indent,
|
||||
hangingIndent: hangingIndent,
|
||||
wrap: wrap,
|
||||
);
|
||||
}
|
||||
|
||||
/// Use this for verbose tracing output. Users can turn this output on in order
|
||||
/// to help diagnose issues with the toolchain or with their setup.
|
||||
void printTrace(String message) => logger.printTrace(message);
|
||||
|
||||
AnsiTerminal get terminal {
|
||||
return context.get<AnsiTerminal>() ?? _defaultAnsiTerminal;
|
||||
}
|
||||
|
||||
final AnsiTerminal _defaultAnsiTerminal = AnsiTerminal(
|
||||
stdio: stdio,
|
||||
platform: platform,
|
||||
);
|
||||
|
||||
/// The global Stdio wrapper.
|
||||
Stdio get stdio => context.get<Stdio>() ?? (_stdioInstance ??= Stdio());
|
||||
Stdio? _stdioInstance;
|
||||
|
||||
PlistParser get plistParser => context.get<PlistParser>() ?? (
|
||||
_plistInstance ??= PlistParser(
|
||||
fileSystem: fs,
|
||||
processManager: processManager,
|
||||
logger: logger,
|
||||
));
|
||||
PlistParser? _plistInstance;
|
||||
|
||||
/// The global template renderer.
|
||||
TemplateRenderer get templateRenderer => context.get<TemplateRenderer>()!;
|
||||
|
||||
ShutdownHooks? get shutdownHooks => context.get<ShutdownHooks>();
|
||||
|
||||
// Unless we're in a test of this class's signal handling features, we must
|
||||
// have only one instance created with the singleton LocalSignals instance
|
||||
// and the catchable signals it considers to be fatal.
|
||||
LocalFileSystem? _instance;
|
||||
LocalFileSystem get localFileSystem => _instance ??= LocalFileSystem(
|
||||
LocalSignals.instance,
|
||||
Signals.defaultExitSignals,
|
||||
shutdownHooks,
|
||||
);
|
@ -10,7 +10,7 @@ import '../application_package.dart';
|
||||
import '../base/file_system.dart';
|
||||
import '../build_info.dart';
|
||||
import '../cmake.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../globals_null_migrated.dart' as globals;
|
||||
import '../project.dart';
|
||||
|
||||
abstract class LinuxApp extends ApplicationPackage {
|
||||
|
@ -10,7 +10,7 @@ import '../base/file_system.dart';
|
||||
import '../base/logger.dart';
|
||||
import '../convert.dart';
|
||||
import '../flutter_manifest.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../globals_null_migrated.dart' as globals;
|
||||
|
||||
import 'gen_l10n_templates.dart';
|
||||
import 'gen_l10n_types.dart';
|
||||
|
@ -11,7 +11,7 @@ import '../base/file_system.dart';
|
||||
import '../base/io.dart';
|
||||
import '../base/utils.dart';
|
||||
import '../build_info.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../globals_null_migrated.dart' as globals;
|
||||
import '../ios/plist_parser.dart';
|
||||
import '../project.dart';
|
||||
|
||||
|
@ -12,7 +12,7 @@ import 'base/common.dart';
|
||||
import 'base/file_system.dart';
|
||||
import 'build_info.dart';
|
||||
import 'device.dart';
|
||||
import 'globals.dart' as globals;
|
||||
import 'globals_null_migrated.dart' as globals;
|
||||
import 'resident_devtools_handler.dart';
|
||||
import 'resident_runner.dart';
|
||||
import 'tracing.dart';
|
||||
|
@ -12,7 +12,7 @@ import '../base/file_system.dart';
|
||||
import '../base/io.dart';
|
||||
import '../base/process.dart';
|
||||
import '../base/utils.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../globals_null_migrated.dart' as globals;
|
||||
import '../vmservice.dart';
|
||||
|
||||
import 'test_device.dart';
|
||||
|
@ -19,7 +19,7 @@ import '../compile.dart';
|
||||
import '../convert.dart';
|
||||
import '../dart/language_version.dart';
|
||||
import '../device.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../globals_null_migrated.dart' as globals;
|
||||
import '../project.dart';
|
||||
import '../test/test_wrapper.dart';
|
||||
|
||||
|
@ -12,7 +12,7 @@ import '../base/common.dart';
|
||||
import '../base/file_system.dart';
|
||||
import '../base/io.dart';
|
||||
import '../convert.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../globals_null_migrated.dart' as globals;
|
||||
import 'test_compiler.dart';
|
||||
import 'test_config.dart';
|
||||
|
||||
|
@ -11,7 +11,7 @@ import '../base/file_system.dart';
|
||||
import '../base/utils.dart';
|
||||
import '../build_info.dart';
|
||||
import '../cmake.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../globals_null_migrated.dart' as globals;
|
||||
import '../project.dart';
|
||||
|
||||
abstract class WindowsApp extends ApplicationPackage {
|
||||
|
@ -14,7 +14,7 @@ import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/commands/assemble.dart';
|
||||
import 'package:flutter_tools/src/convert.dart';
|
||||
import 'package:flutter_tools/src/features.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
|
@ -18,7 +18,7 @@ import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/commands/attach.dart';
|
||||
import 'package:flutter_tools/src/device.dart';
|
||||
import 'package:flutter_tools/src/device_port_forwader.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
import 'package:flutter_tools/src/ios/devices.dart';
|
||||
import 'package:flutter_tools/src/project.dart';
|
||||
import 'package:flutter_tools/src/resident_runner.dart';
|
||||
|
@ -35,16 +35,10 @@ void main() {
|
||||
group('general', () {
|
||||
MemoryFileSystem fs;
|
||||
Directory buildDirectory;
|
||||
FlutterProject projectUnderTest;
|
||||
|
||||
setUp(() {
|
||||
fs = MemoryFileSystem.test();
|
||||
|
||||
final Directory currentDirectory = fs.currentDirectory;
|
||||
buildDirectory = currentDirectory.childDirectory('build');
|
||||
buildDirectory.createSync(recursive: true);
|
||||
|
||||
projectUnderTest = FlutterProject.fromDirectory(currentDirectory);
|
||||
FlutterProject setupProjectUnderTest(Directory currentDirectory) {
|
||||
// This needs to be run within testWithoutContext and not setUp since FlutterProject uses context.
|
||||
final FlutterProject projectUnderTest = FlutterProject.fromDirectory(currentDirectory);
|
||||
projectUnderTest.ios.xcodeWorkspace.createSync(recursive: true);
|
||||
projectUnderTest.macos.xcodeWorkspace.createSync(recursive: true);
|
||||
|
||||
@ -65,9 +59,20 @@ void main() {
|
||||
projectUnderTest.windows.ephemeralDirectory.createSync(recursive: true);
|
||||
projectUnderTest.flutterPluginsFile.createSync(recursive: true);
|
||||
projectUnderTest.flutterPluginsDependenciesFile.createSync(recursive: true);
|
||||
|
||||
return projectUnderTest;
|
||||
}
|
||||
|
||||
setUp(() {
|
||||
fs = MemoryFileSystem.test();
|
||||
|
||||
final Directory currentDirectory = fs.currentDirectory;
|
||||
buildDirectory = currentDirectory.childDirectory('build');
|
||||
buildDirectory.createSync(recursive: true);
|
||||
});
|
||||
|
||||
testUsingContext('$CleanCommand removes build and .dart_tool and ephemeral directories, cleans Xcode', () async {
|
||||
final FlutterProject projectUnderTest = setupProjectUnderTest(fs.currentDirectory);
|
||||
// Xcode is installed and version satisfactory.
|
||||
when(mockXcodeProjectInterpreter.isInstalled).thenReturn(true);
|
||||
when(mockXcodeProjectInterpreter.majorVersion).thenReturn(1000);
|
||||
@ -102,6 +107,7 @@ void main() {
|
||||
});
|
||||
|
||||
testUsingContext('$CleanCommand cleans Xcode verbosely', () async {
|
||||
setupProjectUnderTest(fs.currentDirectory);
|
||||
// Xcode is installed and version satisfactory.
|
||||
when(mockXcodeProjectInterpreter.isInstalled).thenReturn(true);
|
||||
when(mockXcodeProjectInterpreter.majorVersion).thenReturn(1000);
|
||||
|
@ -14,7 +14,7 @@ import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/build_info.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/commands/config.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
import 'package:flutter_tools/src/reporting/reporting.dart';
|
||||
import 'package:flutter_tools/src/version.dart';
|
||||
import 'package:test/fake.dart';
|
||||
|
@ -11,7 +11,7 @@ import 'package:flutter_tools/src/commands/create.dart';
|
||||
import 'package:flutter_tools/src/convert.dart';
|
||||
import 'package:flutter_tools/src/doctor.dart';
|
||||
import 'package:flutter_tools/src/reporting/reporting.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
@ -66,7 +66,7 @@ void main() {
|
||||
});
|
||||
});
|
||||
|
||||
test('set template type as usage value', () => testbed.run(() async {
|
||||
testUsingContext('set template type as usage value', () => testbed.run(() async {
|
||||
final CreateCommand command = CreateCommand();
|
||||
final CommandRunner<void> runner = createTestCommandRunner(command);
|
||||
|
||||
@ -83,7 +83,7 @@ void main() {
|
||||
expect(await command.usageValues, containsPair(CustomDimensions.commandCreateProjectType, 'plugin'));
|
||||
}));
|
||||
|
||||
test('set iOS host language type as usage value', () => testbed.run(() async {
|
||||
testUsingContext('set iOS host language type as usage value', () => testbed.run(() async {
|
||||
final CreateCommand command = CreateCommand();
|
||||
final CommandRunner<void> runner = createTestCommandRunner(command);
|
||||
|
||||
@ -104,7 +104,7 @@ void main() {
|
||||
|
||||
}));
|
||||
|
||||
test('set Android host language type as usage value', () => testbed.run(() async {
|
||||
testUsingContext('set Android host language type as usage value', () => testbed.run(() async {
|
||||
final CreateCommand command = CreateCommand();
|
||||
final CommandRunner<void> runner = createTestCommandRunner(command);
|
||||
|
||||
|
@ -13,7 +13,7 @@ import 'package:flutter_tools/src/base/utils.dart';
|
||||
import 'package:flutter_tools/src/commands/daemon.dart';
|
||||
import 'package:flutter_tools/src/features.dart';
|
||||
import 'package:flutter_tools/src/fuchsia/fuchsia_workflow.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
import 'package:flutter_tools/src/ios/ios_workflow.dart';
|
||||
import 'package:flutter_tools/src/resident_runner.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
@ -22,7 +22,7 @@ import 'package:flutter_tools/src/commands/doctor.dart';
|
||||
import 'package:flutter_tools/src/device.dart';
|
||||
import 'package:flutter_tools/src/doctor.dart';
|
||||
import 'package:flutter_tools/src/features.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
import 'package:flutter_tools/src/reporting/reporting.dart';
|
||||
import 'package:flutter_tools/src/version.dart';
|
||||
import 'package:flutter_tools/src/vscode/vscode.dart';
|
||||
|
@ -9,7 +9,7 @@ import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/template.dart';
|
||||
import 'package:flutter_tools/src/commands/ide_config.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
|
@ -12,7 +12,7 @@ import 'package:flutter_tools/src/base/io.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/commands/shell_completion.dart';
|
||||
import 'package:process/process.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
|
@ -13,7 +13,7 @@ import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/commands/build_aar.dart';
|
||||
import 'package:flutter_tools/src/project.dart';
|
||||
import 'package:flutter_tools/src/reporting/reporting.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:process/process.dart';
|
||||
import 'package:test/fake.dart';
|
||||
|
@ -16,7 +16,7 @@ import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/commands/build_apk.dart';
|
||||
import 'package:flutter_tools/src/project.dart';
|
||||
import 'package:flutter_tools/src/reporting/reporting.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:process/process.dart';
|
||||
|
||||
|
@ -11,7 +11,7 @@ import 'package:flutter_tools/src/base/context.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/commands/build_appbundle.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
import 'package:flutter_tools/src/project.dart';
|
||||
import 'package:flutter_tools/src/reporting/reporting.dart';
|
||||
import 'package:process/process.dart';
|
||||
|
@ -17,7 +17,7 @@ import 'package:flutter_tools/src/features.dart';
|
||||
import 'package:flutter_tools/src/reporting/reporting.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:process/process.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
|
@ -8,7 +8,7 @@ import 'package:args/command_runner.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/commands/format.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
|
@ -10,7 +10,7 @@ import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/commands/upgrade.dart';
|
||||
import 'package:flutter_tools/src/convert.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
import 'package:flutter_tools/src/persistent_tool_state.dart';
|
||||
import 'package:flutter_tools/src/runner/flutter_command.dart';
|
||||
import 'package:flutter_tools/src/version.dart';
|
||||
|
@ -9,7 +9,7 @@ import 'package:flutter_tools/src/android/android_studio.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/base/version.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
import 'package:flutter_tools/src/ios/plist_parser.dart';
|
||||
import 'package:test/fake.dart';
|
||||
|
||||
|
@ -12,7 +12,7 @@ import 'package:flutter_tools/src/base/io.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/base/user_messages.dart';
|
||||
import 'package:flutter_tools/src/doctor.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
|
@ -10,7 +10,7 @@ import 'package:flutter_tools/src/android/gradle_errors.dart';
|
||||
import 'package:flutter_tools/src/android/gradle_utils.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
import 'package:flutter_tools/src/project.dart';
|
||||
import 'package:flutter_tools/src/reporting/reporting.dart';
|
||||
|
||||
|
@ -17,7 +17,7 @@ import 'package:flutter_tools/src/base/logger.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/build_info.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
import 'package:flutter_tools/src/project.dart';
|
||||
import 'package:flutter_tools/src/reporting/reporting.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
@ -17,7 +17,7 @@ import 'package:flutter_tools/src/base/user_messages.dart';
|
||||
import 'package:flutter_tools/src/build_info.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/fuchsia/application_package.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
import 'package:flutter_tools/src/ios/application_package.dart';
|
||||
import 'package:flutter_tools/src/ios/plist_parser.dart';
|
||||
import 'package:flutter_tools/src/project.dart';
|
||||
|
@ -12,7 +12,7 @@ import 'package:file/memory.dart';
|
||||
import 'package:flutter_tools/src/asset.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
|
||||
import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
|
@ -12,7 +12,7 @@ import 'package:file/memory.dart';
|
||||
import 'package:flutter_tools/src/asset.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
|
||||
import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
|
@ -13,7 +13,7 @@ import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/bundle.dart';
|
||||
import 'package:flutter_tools/src/devfs.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
|
||||
import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
|
@ -12,7 +12,7 @@ import 'package:file/memory.dart';
|
||||
import 'package:flutter_tools/src/asset.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
|
||||
import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
import 'package:flutter_tools/src/asset.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
|
||||
import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
|
@ -7,7 +7,7 @@
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/build_system/build_system.dart';
|
||||
import 'package:flutter_tools/src/build_system/exceptions.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
|
||||
import '../../src/common.dart';
|
||||
|
||||
|
@ -13,7 +13,7 @@ import 'package:flutter_tools/src/build_system/build_system.dart';
|
||||
import 'package:flutter_tools/src/build_system/depfile.dart';
|
||||
import 'package:flutter_tools/src/build_system/targets/common.dart';
|
||||
import 'package:flutter_tools/src/build_system/targets/web.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
import 'package:process/process.dart';
|
||||
|
||||
import '../../../src/common.dart';
|
||||
|
@ -10,7 +10,7 @@ import 'package:flutter_tools/src/build_info.dart';
|
||||
import 'package:flutter_tools/src/build_system/build_system.dart';
|
||||
import 'package:flutter_tools/src/bundle.dart';
|
||||
import 'package:flutter_tools/src/project.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
|
||||
import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
|
@ -11,7 +11,7 @@ import 'package:flutter_tools/src/base/io.dart';
|
||||
import 'package:flutter_tools/src/base/logger.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/devtools_launcher.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
import 'package:flutter_tools/src/persistent_tool_state.dart';
|
||||
import 'package:flutter_tools/src/resident_runner.dart';
|
||||
|
||||
|
@ -32,7 +32,7 @@ import 'package:flutter_tools/src/fuchsia/fuchsia_pm.dart';
|
||||
import 'package:flutter_tools/src/fuchsia/fuchsia_sdk.dart';
|
||||
import 'package:flutter_tools/src/fuchsia/fuchsia_workflow.dart';
|
||||
import 'package:flutter_tools/src/fuchsia/tiles_ctl.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
import 'package:flutter_tools/src/project.dart';
|
||||
import 'package:flutter_tools/src/vmservice.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
@ -12,7 +12,7 @@ import 'package:flutter_tools/src/base/config.dart';
|
||||
import 'package:flutter_tools/src/base/io.dart';
|
||||
import 'package:flutter_tools/src/base/terminal.dart';
|
||||
import 'package:flutter_tools/src/ios/code_signing.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
|
@ -13,7 +13,7 @@ import 'package:flutter_tools/src/build_info.dart';
|
||||
import 'package:flutter_tools/src/devfs.dart';
|
||||
import 'package:flutter_tools/src/device.dart';
|
||||
import 'package:flutter_tools/src/device_port_forwader.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
import 'package:flutter_tools/src/ios/application_package.dart';
|
||||
import 'package:flutter_tools/src/ios/plist_parser.dart';
|
||||
import 'package:flutter_tools/src/ios/simulators.dart';
|
||||
|
@ -13,7 +13,7 @@ import 'package:flutter_tools/src/base/os.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/base/utils.dart';
|
||||
import 'package:flutter_tools/src/ios/plist_parser.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
import 'package:flutter_tools/src/macos/application_package.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
|
@ -27,7 +27,6 @@ typedef InvokeProcess = Future<ProcessResult> Function();
|
||||
void main() {
|
||||
FileSystem fileSystem;
|
||||
FakeProcessManager fakeProcessManager;
|
||||
FlutterProject projectUnderTest;
|
||||
CocoaPods cocoaPodsUnderTest;
|
||||
BufferLogger logger;
|
||||
TestUsage usage;
|
||||
@ -58,14 +57,19 @@ void main() {
|
||||
)).createSync(recursive: true);
|
||||
}
|
||||
|
||||
FlutterProject setupProjectUnderTest() {
|
||||
// This needs to be run within testWithoutContext and not setUp since FlutterProject uses context.
|
||||
final FlutterProject projectUnderTest = FlutterProject.fromDirectory(fileSystem.directory('project'));
|
||||
projectUnderTest.ios.xcodeProject.createSync(recursive: true);
|
||||
projectUnderTest.macos.xcodeProject.createSync(recursive: true);
|
||||
return projectUnderTest;
|
||||
}
|
||||
|
||||
setUp(() async {
|
||||
Cache.flutterRoot = 'flutter';
|
||||
fileSystem = MemoryFileSystem.test();
|
||||
fakeProcessManager = FakeProcessManager.list(<FakeCommand>[]);
|
||||
logger = BufferLogger.test();
|
||||
projectUnderTest = FlutterProject.fromDirectory(fileSystem.directory('project'));
|
||||
projectUnderTest.ios.xcodeProject.createSync(recursive: true);
|
||||
projectUnderTest.macos.xcodeProject.createSync(recursive: true);
|
||||
usage = TestUsage();
|
||||
cocoaPodsUnderTest = CocoaPods(
|
||||
fileSystem: fileSystem,
|
||||
@ -173,13 +177,15 @@ void main() {
|
||||
});
|
||||
|
||||
group('Setup Podfile', () {
|
||||
testWithoutContext('creates objective-c Podfile when not present', () async {
|
||||
testUsingContext('creates objective-c Podfile when not present', () async {
|
||||
final FlutterProject projectUnderTest = setupProjectUnderTest();
|
||||
await cocoaPodsUnderTest.setupPodfile(projectUnderTest.ios);
|
||||
|
||||
expect(projectUnderTest.ios.podfile.readAsStringSync(), 'Objective-C iOS podfile template');
|
||||
});
|
||||
|
||||
testWithoutContext('creates swift Podfile if swift', () async {
|
||||
testUsingContext('creates swift Podfile if swift', () async {
|
||||
final FlutterProject projectUnderTest = setupProjectUnderTest();
|
||||
final FakeXcodeProjectInterpreter fakeXcodeProjectInterpreter = FakeXcodeProjectInterpreter(buildSettings: <String, String>{
|
||||
'SWIFT_VERSION': '5.0',
|
||||
});
|
||||
@ -198,14 +204,16 @@ void main() {
|
||||
expect(projectUnderTest.ios.podfile.readAsStringSync(), 'Swift iOS podfile template');
|
||||
});
|
||||
|
||||
testWithoutContext('creates macOS Podfile when not present', () async {
|
||||
testUsingContext('creates macOS Podfile when not present', () async {
|
||||
final FlutterProject projectUnderTest = setupProjectUnderTest();
|
||||
projectUnderTest.macos.xcodeProject.createSync(recursive: true);
|
||||
await cocoaPodsUnderTest.setupPodfile(projectUnderTest.macos);
|
||||
|
||||
expect(projectUnderTest.macos.podfile.readAsStringSync(), 'macOS podfile template');
|
||||
});
|
||||
|
||||
testWithoutContext('does not recreate Podfile when already present', () async {
|
||||
testUsingContext('does not recreate Podfile when already present', () async {
|
||||
final FlutterProject projectUnderTest = setupProjectUnderTest();
|
||||
projectUnderTest.ios.podfile..createSync()..writeAsStringSync('Existing Podfile');
|
||||
|
||||
final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.directory('project'));
|
||||
@ -214,7 +222,8 @@ void main() {
|
||||
expect(projectUnderTest.ios.podfile.readAsStringSync(), 'Existing Podfile');
|
||||
});
|
||||
|
||||
testWithoutContext('does not create Podfile when we cannot interpret Xcode projects', () async {
|
||||
testUsingContext('does not create Podfile when we cannot interpret Xcode projects', () async {
|
||||
final FlutterProject projectUnderTest = setupProjectUnderTest();
|
||||
final CocoaPods cocoaPodsUnderTest = CocoaPods(
|
||||
fileSystem: fileSystem,
|
||||
processManager: fakeProcessManager,
|
||||
@ -230,7 +239,8 @@ void main() {
|
||||
expect(projectUnderTest.ios.podfile.existsSync(), false);
|
||||
});
|
||||
|
||||
testWithoutContext('includes Pod config in xcconfig files, if not present', () async {
|
||||
testUsingContext('includes Pod config in xcconfig files, if not present', () async {
|
||||
final FlutterProject projectUnderTest = setupProjectUnderTest();
|
||||
projectUnderTest.ios.podfile..createSync()..writeAsStringSync('Existing Podfile');
|
||||
projectUnderTest.ios.xcodeConfigFor('Debug')
|
||||
..createSync(recursive: true)
|
||||
@ -252,7 +262,8 @@ void main() {
|
||||
expect(releaseContents, contains('Existing release config'));
|
||||
});
|
||||
|
||||
testWithoutContext('does not include Pod config in xcconfig files, if legacy non-option include present', () async {
|
||||
testUsingContext('does not include Pod config in xcconfig files, if legacy non-option include present', () async {
|
||||
final FlutterProject projectUnderTest = setupProjectUnderTest();
|
||||
projectUnderTest.ios.podfile..createSync()..writeAsStringSync('Existing Podfile');
|
||||
|
||||
const String legacyDebugInclude = '#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig';
|
||||
@ -280,6 +291,7 @@ void main() {
|
||||
|
||||
group('Update xcconfig', () {
|
||||
testUsingContext('includes Pod config in xcconfig files, if the user manually added Pod dependencies without using Flutter plugins', () async {
|
||||
final FlutterProject projectUnderTest = setupProjectUnderTest();
|
||||
fileSystem.file(fileSystem.path.join('project', 'foo', '.packages'))
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('\n');
|
||||
@ -315,7 +327,8 @@ void main() {
|
||||
podsIsInHomeDir();
|
||||
});
|
||||
|
||||
testWithoutContext('throwsToolExit if CocoaPods is not installed', () async {
|
||||
testUsingContext('throwsToolExit if CocoaPods is not installed', () async {
|
||||
final FlutterProject projectUnderTest = setupProjectUnderTest();
|
||||
pretendPodIsNotInstalled();
|
||||
projectUnderTest.ios.podfile.createSync();
|
||||
await expectLater(cocoaPodsUnderTest.processPods(
|
||||
@ -326,7 +339,8 @@ void main() {
|
||||
expect(fakeProcessManager, hasNoRemainingExpectations);
|
||||
});
|
||||
|
||||
testWithoutContext('throwsToolExit if CocoaPods install is broken', () async {
|
||||
testUsingContext('throwsToolExit if CocoaPods install is broken', () async {
|
||||
final FlutterProject projectUnderTest = setupProjectUnderTest();
|
||||
pretendPodIsBroken();
|
||||
projectUnderTest.ios.podfile.createSync();
|
||||
await expectLater(cocoaPodsUnderTest.processPods(
|
||||
@ -337,7 +351,8 @@ void main() {
|
||||
expect(fakeProcessManager, hasNoRemainingExpectations);
|
||||
});
|
||||
|
||||
testWithoutContext('exits if Podfile creates the Flutter engine symlink', () async {
|
||||
testUsingContext('exits if Podfile creates the Flutter engine symlink', () async {
|
||||
final FlutterProject projectUnderTest = setupProjectUnderTest();
|
||||
fileSystem.file(fileSystem.path.join('project', 'ios', 'Podfile'))
|
||||
..createSync()
|
||||
..writeAsStringSync('Existing Podfile');
|
||||
@ -353,7 +368,8 @@ void main() {
|
||||
expect(fakeProcessManager, hasNoRemainingExpectations);
|
||||
});
|
||||
|
||||
testWithoutContext('exits if iOS Podfile parses .flutter-plugins', () async {
|
||||
testUsingContext('exits if iOS Podfile parses .flutter-plugins', () async {
|
||||
final FlutterProject projectUnderTest = setupProjectUnderTest();
|
||||
fileSystem.file(fileSystem.path.join('project', 'ios', 'Podfile'))
|
||||
..createSync()
|
||||
..writeAsStringSync('plugin_pods = parse_KV_file(\'../.flutter-plugins\')');
|
||||
@ -365,7 +381,8 @@ void main() {
|
||||
expect(fakeProcessManager, hasNoRemainingExpectations);
|
||||
});
|
||||
|
||||
testWithoutContext('prints warning if macOS Podfile parses .flutter-plugins', () async {
|
||||
testUsingContext('prints warning if macOS Podfile parses .flutter-plugins', () async {
|
||||
final FlutterProject projectUnderTest = setupProjectUnderTest();
|
||||
pretendPodIsInstalled();
|
||||
pretendPodVersionIs('1.10.0');
|
||||
fakeProcessManager.addCommand(
|
||||
@ -388,7 +405,8 @@ void main() {
|
||||
expect(fakeProcessManager, hasNoRemainingExpectations);
|
||||
});
|
||||
|
||||
testWithoutContext('throws, if Podfile is missing.', () async {
|
||||
testUsingContext('throws, if Podfile is missing.', () async {
|
||||
final FlutterProject projectUnderTest = setupProjectUnderTest();
|
||||
await expectLater(cocoaPodsUnderTest.processPods(
|
||||
xcodeProject: projectUnderTest.ios,
|
||||
buildMode: BuildMode.debug,
|
||||
@ -396,7 +414,8 @@ void main() {
|
||||
expect(fakeProcessManager.hasRemainingExpectations, isFalse);
|
||||
});
|
||||
|
||||
testWithoutContext('throws, if specs repo is outdated.', () async {
|
||||
testUsingContext('throws, if specs repo is outdated.', () async {
|
||||
final FlutterProject projectUnderTest = setupProjectUnderTest();
|
||||
pretendPodIsInstalled();
|
||||
pretendPodVersionIs('1.10.0');
|
||||
fileSystem.file(fileSystem.path.join('project', 'ios', 'Podfile'))
|
||||
@ -440,7 +459,8 @@ Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by
|
||||
);
|
||||
});
|
||||
|
||||
testWithoutContext('ffi failure on ARM macOS prompts gem install', () async {
|
||||
testUsingContext('ffi failure on ARM macOS prompts gem install', () async {
|
||||
final FlutterProject projectUnderTest = setupProjectUnderTest();
|
||||
pretendPodIsInstalled();
|
||||
pretendPodVersionIs('1.10.0');
|
||||
fileSystem.file(fileSystem.path.join('project', 'ios', 'Podfile'))
|
||||
@ -481,7 +501,8 @@ Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by
|
||||
expect(usage.events, contains(const TestUsageEvent('pod-install-failure', 'arm-ffi')));
|
||||
});
|
||||
|
||||
testWithoutContext('ffi failure on x86 macOS does not prompt gem install', () async {
|
||||
testUsingContext('ffi failure on x86 macOS does not prompt gem install', () async {
|
||||
final FlutterProject projectUnderTest = setupProjectUnderTest();
|
||||
pretendPodIsInstalled();
|
||||
pretendPodVersionIs('1.10.0');
|
||||
fileSystem.file(fileSystem.path.join('project', 'ios', 'Podfile'))
|
||||
@ -524,7 +545,8 @@ Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by
|
||||
expect(buffer.isEmpty, true);
|
||||
});
|
||||
|
||||
testWithoutContext('run pod install, if Podfile.lock is missing', () async {
|
||||
testUsingContext('run pod install, if Podfile.lock is missing', () async {
|
||||
final FlutterProject projectUnderTest = setupProjectUnderTest();
|
||||
pretendPodIsInstalled();
|
||||
pretendPodVersionIs('1.10.0');
|
||||
projectUnderTest.ios.podfile
|
||||
@ -550,7 +572,8 @@ Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by
|
||||
expect(fakeProcessManager.hasRemainingExpectations, isFalse);
|
||||
});
|
||||
|
||||
testWithoutContext('runs iOS pod install, if Manifest.lock is missing', () async {
|
||||
testUsingContext('runs iOS pod install, if Manifest.lock is missing', () async {
|
||||
final FlutterProject projectUnderTest = setupProjectUnderTest();
|
||||
pretendPodIsInstalled();
|
||||
pretendPodVersionIs('1.10.0');
|
||||
projectUnderTest.ios.podfile
|
||||
@ -575,7 +598,8 @@ Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by
|
||||
expect(fakeProcessManager.hasRemainingExpectations, isFalse);
|
||||
});
|
||||
|
||||
testWithoutContext('runs macOS pod install, if Manifest.lock is missing', () async {
|
||||
testUsingContext('runs macOS pod install, if Manifest.lock is missing', () async {
|
||||
final FlutterProject projectUnderTest = setupProjectUnderTest();
|
||||
pretendPodIsInstalled();
|
||||
pretendPodVersionIs('1.10.0');
|
||||
projectUnderTest.macos.podfile
|
||||
@ -600,7 +624,8 @@ Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by
|
||||
expect(fakeProcessManager.hasRemainingExpectations, isFalse);
|
||||
});
|
||||
|
||||
testWithoutContext('runs pod install, if Manifest.lock different from Podspec.lock', () async {
|
||||
testUsingContext('runs pod install, if Manifest.lock different from Podspec.lock', () async {
|
||||
final FlutterProject projectUnderTest = setupProjectUnderTest();
|
||||
pretendPodIsInstalled();
|
||||
pretendPodVersionIs('1.10.0');
|
||||
projectUnderTest.ios.podfile
|
||||
@ -628,7 +653,8 @@ Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by
|
||||
expect(fakeProcessManager.hasRemainingExpectations, isFalse);
|
||||
});
|
||||
|
||||
testWithoutContext('runs pod install, if flutter framework changed', () async {
|
||||
testUsingContext('runs pod install, if flutter framework changed', () async {
|
||||
final FlutterProject projectUnderTest = setupProjectUnderTest();
|
||||
pretendPodIsInstalled();
|
||||
pretendPodVersionIs('1.10.0');
|
||||
projectUnderTest.ios.podfile
|
||||
@ -656,7 +682,8 @@ Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by
|
||||
expect(fakeProcessManager.hasRemainingExpectations, isFalse);
|
||||
});
|
||||
|
||||
testWithoutContext('runs pod install, if Podfile.lock is older than Podfile', () async {
|
||||
testUsingContext('runs pod install, if Podfile.lock is older than Podfile', () async {
|
||||
final FlutterProject projectUnderTest = setupProjectUnderTest();
|
||||
pretendPodIsInstalled();
|
||||
pretendPodVersionIs('1.10.0');
|
||||
projectUnderTest.ios.podfile
|
||||
@ -686,7 +713,8 @@ Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by
|
||||
expect(fakeProcessManager.hasRemainingExpectations, isFalse);
|
||||
});
|
||||
|
||||
testWithoutContext('skips pod install, if nothing changed', () async {
|
||||
testUsingContext('skips pod install, if nothing changed', () async {
|
||||
final FlutterProject projectUnderTest = setupProjectUnderTest();
|
||||
projectUnderTest.ios.podfile
|
||||
..createSync()
|
||||
..writeAsStringSync('Existing Podfile');
|
||||
@ -705,7 +733,8 @@ Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by
|
||||
expect(fakeProcessManager.hasRemainingExpectations, isFalse);
|
||||
});
|
||||
|
||||
testWithoutContext('a failed pod install deletes Pods/Manifest.lock', () async {
|
||||
testUsingContext('a failed pod install deletes Pods/Manifest.lock', () async {
|
||||
final FlutterProject projectUnderTest = setupProjectUnderTest();
|
||||
pretendPodIsInstalled();
|
||||
pretendPodVersionIs('1.10.0');
|
||||
projectUnderTest.ios.podfile
|
||||
|
@ -14,7 +14,7 @@ import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/base/time.dart';
|
||||
import 'package:flutter_tools/src/base/utils.dart';
|
||||
import 'package:flutter_tools/src/features.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
import 'package:flutter_tools/src/ios/xcodeproj.dart';
|
||||
import 'package:flutter_tools/src/plugins.dart';
|
||||
import 'package:flutter_tools/src/project.dart';
|
||||
@ -1307,7 +1307,7 @@ flutter:
|
||||
projectDir.childFile('pubspec.yaml')..createSync(recursive: true)..writeAsStringSync(yamlString);
|
||||
}
|
||||
|
||||
test('validatePubspecForPlugin works', () async {
|
||||
testUsingContext('validatePubspecForPlugin works', () async {
|
||||
const String pluginYaml = '''
|
||||
flutter:
|
||||
plugin:
|
||||
@ -1333,7 +1333,7 @@ flutter:
|
||||
], androidIdentifier: 'AndroidPackage', webFileName: 'lib/SomeFile.dart');
|
||||
});
|
||||
|
||||
test('createPlatformsYamlMap should create the correct map', () async {
|
||||
testUsingContext('createPlatformsYamlMap should create the correct map', () async {
|
||||
final YamlMap map = Plugin.createPlatformsYamlMap(<String>['ios', 'android', 'linux'], 'PluginClass', 'some.android.package');
|
||||
expect(map['ios'], <String, String> {
|
||||
'pluginClass' : 'PluginClass'
|
||||
@ -1347,7 +1347,7 @@ flutter:
|
||||
});
|
||||
});
|
||||
|
||||
test('createPlatformsYamlMap should create empty map', () async {
|
||||
testUsingContext('createPlatformsYamlMap should create empty map', () async {
|
||||
final YamlMap map = Plugin.createPlatformsYamlMap(<String>[], null, null);
|
||||
expect(map.isEmpty, true);
|
||||
});
|
||||
|
@ -8,6 +8,7 @@ import 'package:file/file.dart';
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/logger.dart';
|
||||
import 'package:flutter_tools/src/base/os.dart';
|
||||
import 'package:flutter_tools/src/build_info.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/convert.dart';
|
||||
@ -16,7 +17,7 @@ import 'package:flutter_tools/src/flutter_manifest.dart';
|
||||
import 'package:flutter_tools/src/ios/plist_parser.dart';
|
||||
import 'package:flutter_tools/src/ios/xcodeproj.dart';
|
||||
import 'package:flutter_tools/src/project.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
@ -809,10 +810,16 @@ void _testInMemory(String description, Future<void> Function() testMethod) {
|
||||
..writeAsStringSync('{"configVersion":2,"packages":[]}');
|
||||
// Transfer needed parts of the Flutter installation folder
|
||||
// to the in-memory file system used during testing.
|
||||
final Logger logger = BufferLogger.test();
|
||||
transfer(Cache(
|
||||
fileSystem: globals.fs,
|
||||
logger: globals.logger,
|
||||
osUtils: globals.os,
|
||||
logger: logger,
|
||||
osUtils: OperatingSystemUtils(
|
||||
fileSystem: globals.fs,
|
||||
logger: logger,
|
||||
platform: globals.platform,
|
||||
processManager: globals.processManager,
|
||||
),
|
||||
platform: globals.platform,
|
||||
).getArtifactDirectory('gradle_wrapper'), testFileSystem);
|
||||
transfer(globals.fs.directory(Cache.flutterRoot)
|
||||
@ -840,11 +847,6 @@ void _testInMemory(String description, Future<void> Function() testMethod) {
|
||||
],
|
||||
}));
|
||||
|
||||
final FlutterProjectFactory flutterProjectFactory = FlutterProjectFactory(
|
||||
fileSystem: testFileSystem,
|
||||
logger: globals.logger ?? BufferLogger.test(),
|
||||
);
|
||||
|
||||
testUsingContext(
|
||||
description,
|
||||
testMethod,
|
||||
@ -853,11 +855,14 @@ void _testInMemory(String description, Future<void> Function() testMethod) {
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
Cache: () => Cache(
|
||||
logger: globals.logger,
|
||||
fileSystem: globals.fs,
|
||||
fileSystem: testFileSystem,
|
||||
osUtils: globals.os,
|
||||
platform: globals.platform,
|
||||
),
|
||||
FlutterProjectFactory: () => flutterProjectFactory,
|
||||
FlutterProjectFactory: () => FlutterProjectFactory(
|
||||
fileSystem: testFileSystem,
|
||||
logger: globals.logger ?? BufferLogger.test(),
|
||||
),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ import 'package:flutter_tools/src/base/context.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/error_handling_io.dart';
|
||||
import 'package:flutter_tools/src/base/process.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
|
||||
import '../src/common.dart';
|
||||
import '../src/testbed.dart';
|
||||
|
@ -7,7 +7,7 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
import 'package:flutter_tools/src/test/flutter_web_goldens.dart';
|
||||
|
||||
import '../../src/common.dart';
|
||||
|
@ -9,7 +9,7 @@ import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_tools/src/test/flutter_web_goldens.dart';
|
||||
import 'package:flutter_tools/src/test/test_compiler.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:process/process.dart';
|
||||
|
||||
|
@ -9,7 +9,7 @@ import 'package:flutter_tools/src/compile.dart';
|
||||
import 'package:flutter_tools/src/isolated/devfs_web.dart';
|
||||
import 'package:matcher/matcher.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/testbed.dart';
|
||||
|
@ -51,10 +51,11 @@ void main() {
|
||||
.map(_asFile);
|
||||
for (final File file in files) {
|
||||
for (final String line in file.readAsLinesSync()) {
|
||||
if (line.startsWith(RegExp(r'import.*globals.dart'))
|
||||
&& !line.contains(r'as globals')) {
|
||||
if ((line.startsWith(RegExp(r'import.*globals.dart')) ||
|
||||
line.startsWith(RegExp(r'import.*globals_null_migrated.dart'))) &&
|
||||
!line.contains(r'as globals')) {
|
||||
final String relativePath = fileSystem.path.relative(file.path, from:flutterTools);
|
||||
fail('$relativePath imports globals.dart without a globals prefix.');
|
||||
fail('$relativePath imports globals_null_migrated.dart or globals.dart without a globals prefix.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import 'dart:io' as io;
|
||||
|
||||
import 'package:flutter_tools/src/base/io.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
|
||||
import '../src/common.dart';
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
import 'package:flutter_tools/src/android/android_builder.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/build_info.dart';
|
||||
|
@ -21,7 +21,7 @@ import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/commands/create.dart';
|
||||
import 'package:flutter_tools/src/convert.dart';
|
||||
import 'package:flutter_tools/src/doctor.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
import 'package:flutter_tools/src/runner/flutter_command.dart';
|
||||
import 'package:flutter_tools/src/runner/flutter_command_runner.dart';
|
||||
import 'package:flutter_tools/src/vmservice.dart';
|
||||
|
@ -31,7 +31,7 @@ import 'package:flutter_tools/src/persistent_tool_state.dart';
|
||||
import 'package:flutter_tools/src/project.dart';
|
||||
import 'package:flutter_tools/src/reporting/reporting.dart';
|
||||
import 'package:flutter_tools/src/version.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
|
@ -12,7 +12,7 @@ import 'package:flutter_tools/src/android/android_sdk.dart' show AndroidSdk;
|
||||
import 'package:flutter_tools/src/base/file_system.dart' hide IOSink;
|
||||
import 'package:flutter_tools/src/base/io.dart';
|
||||
import 'package:flutter_tools/src/build_info.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
import 'package:flutter_tools/src/ios/devices.dart';
|
||||
import 'package:flutter_tools/src/project.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
import 'package:flutter_tools/src/flutter_manifest.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
import 'package:yaml/yaml.dart';
|
||||
import 'common.dart';
|
||||
|
||||
|
@ -21,7 +21,7 @@ import 'package:flutter_tools/src/context_runner.dart';
|
||||
import 'package:flutter_tools/src/dart/pub.dart';
|
||||
import 'package:flutter_tools/src/reporting/reporting.dart';
|
||||
import 'package:flutter_tools/src/version.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
|
||||
import 'package:process/process.dart';
|
||||
|
||||
import 'context.dart';
|
||||
|
@ -5,32 +5,39 @@
|
||||
import 'dart:io';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
/// Count the number of libraries that import globals.dart in lib and test.
|
||||
/// Count the number of libraries that import globals_null_migrated.dart and globals.dart in lib and test.
|
||||
///
|
||||
/// This must be run from the flutter_tools project root directory.
|
||||
void main() {
|
||||
final Directory sources = Directory(path.join(Directory.current.path, 'lib'));
|
||||
final Directory tests = Directory(path.join(Directory.current.path, 'test'));
|
||||
final int sourceGlobals = countGlobalImports(sources);
|
||||
final int testGlobals = countGlobalImports(tests);
|
||||
print('lib/ contains $sourceGlobals libraries with global usage');
|
||||
print('test/ contains $testGlobals libraries with global usage');
|
||||
countGlobalImports(sources);
|
||||
countGlobalImports(tests);
|
||||
}
|
||||
|
||||
final RegExp globalImport = RegExp('import.*globals.dart\' as globals;');
|
||||
final RegExp globalImport = RegExp(r"import.*(?:globals|globals_null_migrated)\.dart' as globals;");
|
||||
final RegExp globalNullUnsafeImport = RegExp('import.*globals.dart\' as globals;');
|
||||
|
||||
int countGlobalImports(Directory directory) {
|
||||
void countGlobalImports(Directory directory) {
|
||||
int count = 0;
|
||||
int nullUnsafeImportCount = 0;
|
||||
for (final FileSystemEntity file in directory.listSync(recursive: true)) {
|
||||
if (!file.path.endsWith('.dart') || file is! File) {
|
||||
continue;
|
||||
}
|
||||
final bool hasImport = file.readAsLinesSync().any((String line) {
|
||||
final List<String> fileLines = file.readAsLinesSync();
|
||||
final bool hasImport = fileLines.any((String line) {
|
||||
return globalImport.hasMatch(line);
|
||||
});
|
||||
if (hasImport) {
|
||||
count += 1;
|
||||
}
|
||||
final bool hasUnsafeImport = fileLines.any((String line) {
|
||||
return globalNullUnsafeImport.hasMatch(line);
|
||||
});
|
||||
if (hasUnsafeImport) {
|
||||
nullUnsafeImportCount += 1;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
print('${path.basename(directory.path)} contains $count libraries with global usage ($nullUnsafeImportCount unsafe)');
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user