Commit 417c2f25 authored by Todd Volkert's avatar Todd Volkert Committed by GitHub

Migrate flutter_tools to use package:platform (#7642)

parent 600c75cb
...@@ -14,6 +14,7 @@ import '../lib/src/base/file_system.dart'; ...@@ -14,6 +14,7 @@ import '../lib/src/base/file_system.dart';
import '../lib/src/base/io.dart'; import '../lib/src/base/io.dart';
import '../lib/src/base/logger.dart'; import '../lib/src/base/logger.dart';
import '../lib/src/base/os.dart'; import '../lib/src/base/os.dart';
import '../lib/src/base/platform.dart';
import '../lib/src/cache.dart'; import '../lib/src/cache.dart';
import '../lib/src/flx.dart'; import '../lib/src/flx.dart';
import '../lib/src/globals.dart'; import '../lib/src/globals.dart';
...@@ -38,6 +39,7 @@ Future<Null> main(List<String> args) async { ...@@ -38,6 +39,7 @@ Future<Null> main(List<String> args) async {
executableContext.setVariable(Logger, new StdoutLogger()); executableContext.setVariable(Logger, new StdoutLogger());
executableContext.runInZone(() { executableContext.runInZone(() {
// Initialize the context with some defaults. // Initialize the context with some defaults.
context.putIfAbsent(Platform, () => new LocalPlatform());
context.putIfAbsent(FileSystem, () => new LocalFileSystem()); context.putIfAbsent(FileSystem, () => new LocalFileSystem());
context.putIfAbsent(ProcessManager, () => new LocalProcessManager()); context.putIfAbsent(ProcessManager, () => new LocalProcessManager());
context.putIfAbsent(Logger, () => new StdoutLogger()); context.putIfAbsent(Logger, () => new StdoutLogger());
...@@ -63,7 +65,7 @@ Future<Null> run(List<String> args) async { ...@@ -63,7 +65,7 @@ Future<Null> run(List<String> args) async {
printError('Missing option! All options must be specified.'); printError('Missing option! All options must be specified.');
exit(1); exit(1);
} }
Cache.flutterRoot = Platform.environment['FLUTTER_ROOT']; Cache.flutterRoot = platform.environment['FLUTTER_ROOT'];
String outputPath = argResults[_kOptionOutput]; String outputPath = argResults[_kOptionOutput];
try { try {
await assemble( await assemble(
......
...@@ -15,6 +15,7 @@ import 'src/base/file_system.dart'; ...@@ -15,6 +15,7 @@ import 'src/base/file_system.dart';
import 'src/base/io.dart'; import 'src/base/io.dart';
import 'src/base/logger.dart'; import 'src/base/logger.dart';
import 'src/base/os.dart'; import 'src/base/os.dart';
import 'src/base/platform.dart';
import 'src/base/process.dart'; import 'src/base/process.dart';
import 'src/base/utils.dart'; import 'src/base/utils.dart';
import 'src/cache.dart'; import 'src/cache.dart';
...@@ -100,6 +101,7 @@ Future<Null> main(List<String> args) async { ...@@ -100,6 +101,7 @@ Future<Null> main(List<String> args) async {
// in those locations as well to see if you need a similar update there. // in those locations as well to see if you need a similar update there.
// Seed these context entries first since others depend on them // Seed these context entries first since others depend on them
context.putIfAbsent(Platform, () => new LocalPlatform());
context.putIfAbsent(FileSystem, () => new LocalFileSystem()); context.putIfAbsent(FileSystem, () => new LocalFileSystem());
context.putIfAbsent(ProcessManager, () => new LocalProcessManager()); context.putIfAbsent(ProcessManager, () => new LocalProcessManager());
context.putIfAbsent(Logger, () => new StdoutLogger()); context.putIfAbsent(Logger, () => new StdoutLogger());
......
...@@ -8,8 +8,8 @@ import 'package:pub_semver/pub_semver.dart'; ...@@ -8,8 +8,8 @@ import 'package:pub_semver/pub_semver.dart';
import '../base/common.dart'; import '../base/common.dart';
import '../base/context.dart'; import '../base/context.dart';
import '../base/file_system.dart'; import '../base/file_system.dart';
import '../base/io.dart';
import '../base/os.dart'; import '../base/os.dart';
import '../base/platform.dart';
import '../globals.dart'; import '../globals.dart';
AndroidSdk get androidSdk => context[AndroidSdk]; AndroidSdk get androidSdk => context[AndroidSdk];
...@@ -64,15 +64,15 @@ class AndroidSdk { ...@@ -64,15 +64,15 @@ class AndroidSdk {
static AndroidSdk locateAndroidSdk() { static AndroidSdk locateAndroidSdk() {
String androidHomeDir; String androidHomeDir;
if (Platform.environment.containsKey(kAndroidHome)) { if (platform.environment.containsKey(kAndroidHome)) {
androidHomeDir = Platform.environment[kAndroidHome]; androidHomeDir = platform.environment[kAndroidHome];
} else if (Platform.isLinux) { } else if (platform.isLinux) {
if (homeDirPath != null) if (homeDirPath != null)
androidHomeDir = path.join(homeDirPath, 'Android', 'Sdk'); androidHomeDir = path.join(homeDirPath, 'Android', 'Sdk');
} else if (Platform.isMacOS) { } else if (platform.isMacOS) {
if (homeDirPath != null) if (homeDirPath != null)
androidHomeDir = path.join(homeDirPath, 'Library', 'Android', 'sdk'); androidHomeDir = path.join(homeDirPath, 'Library', 'Android', 'sdk');
} else if (Platform.isWindows) { } else if (platform.isWindows) {
if (homeDirPath != null) if (homeDirPath != null)
androidHomeDir = path.join(homeDirPath, 'AppData', 'Local', 'Android', 'sdk'); androidHomeDir = path.join(homeDirPath, 'AppData', 'Local', 'Android', 'sdk');
} }
......
...@@ -6,6 +6,7 @@ import 'dart:async'; ...@@ -6,6 +6,7 @@ import 'dart:async';
import '../base/io.dart'; import '../base/io.dart';
import '../base/os.dart'; import '../base/os.dart';
import '../base/platform.dart';
import '../base/process_manager.dart'; import '../base/process_manager.dart';
import '../doctor.dart'; import '../doctor.dart';
import '../globals.dart'; import '../globals.dart';
...@@ -30,8 +31,8 @@ class AndroidWorkflow extends DoctorValidator implements Workflow { ...@@ -30,8 +31,8 @@ class AndroidWorkflow extends DoctorValidator implements Workflow {
String sdkVersionText; String sdkVersionText;
if (androidSdk == null) { if (androidSdk == null) {
if (Platform.environment.containsKey(kAndroidHome)) { if (platform.environment.containsKey(kAndroidHome)) {
String androidHomeDir = Platform.environment[kAndroidHome]; String androidHomeDir = platform.environment[kAndroidHome];
messages.add(new ValidationMessage.error( messages.add(new ValidationMessage.error(
'$kAndroidHome = $androidHomeDir\n' '$kAndroidHome = $androidHomeDir\n'
'but Android Studio / Android SDK not found at this location.' 'but Android Studio / Android SDK not found at this location.'
...@@ -56,8 +57,8 @@ class AndroidWorkflow extends DoctorValidator implements Workflow { ...@@ -56,8 +57,8 @@ class AndroidWorkflow extends DoctorValidator implements Workflow {
)); ));
} }
if (Platform.environment.containsKey(kAndroidHome)) { if (platform.environment.containsKey(kAndroidHome)) {
String androidHomeDir = Platform.environment[kAndroidHome]; String androidHomeDir = platform.environment[kAndroidHome];
messages.add(new ValidationMessage('$kAndroidHome = $androidHomeDir')); messages.add(new ValidationMessage('$kAndroidHome = $androidHomeDir'));
} }
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
import 'package:path/path.dart' as path; import 'package:path/path.dart' as path;
import 'io.dart'; import 'platform.dart';
const int kDefaultObservatoryPort = 8100; const int kDefaultObservatoryPort = 8100;
const int kDefaultDiagnosticPort = 8101; const int kDefaultDiagnosticPort = 8101;
...@@ -13,9 +13,9 @@ const int kDefaultDrivePort = 8183; ...@@ -13,9 +13,9 @@ const int kDefaultDrivePort = 8183;
/// Return the absolute path of the user's home directory /// Return the absolute path of the user's home directory
String get homeDirPath { String get homeDirPath {
if (_homeDirPath == null) { if (_homeDirPath == null) {
_homeDirPath = Platform.isWindows _homeDirPath = platform.isWindows
? Platform.environment['USERPROFILE'] ? platform.environment['USERPROFILE']
: Platform.environment['HOME']; : platform.environment['HOME'];
if (_homeDirPath != null) if (_homeDirPath != null)
_homeDirPath = path.absolute(_homeDirPath); _homeDirPath = path.absolute(_homeDirPath);
} }
......
...@@ -8,7 +8,7 @@ import 'package:path/path.dart' as path; ...@@ -8,7 +8,7 @@ import 'package:path/path.dart' as path;
import 'context.dart'; import 'context.dart';
import 'file_system.dart'; import 'file_system.dart';
import 'io.dart'; import 'platform.dart';
class Config { class Config {
Config([File configFile]) { Config([File configFile]) {
...@@ -46,7 +46,7 @@ class Config { ...@@ -46,7 +46,7 @@ class Config {
} }
String _userHomeDir() { String _userHomeDir() {
String envKey = Platform.operatingSystem == 'windows' ? 'APPDATA' : 'HOME'; String envKey = platform.operatingSystem == 'windows' ? 'APPDATA' : 'HOME';
String value = Platform.environment[envKey]; String value = platform.environment[envKey];
return value == null ? '.' : value; return value == null ? '.' : value;
} }
...@@ -11,16 +11,20 @@ ...@@ -11,16 +11,20 @@
/// access with mockable (or in-memory) file systems, making our tests hermetic /// access with mockable (or in-memory) file systems, making our tests hermetic
/// vis-a-vis file system access. /// vis-a-vis file system access.
/// ///
/// To ensure that all file system access within Flutter tools goes through the /// We also use `package:platform` to provide an abstraction away from the
/// proper APIs, we forbid direct imports of `dart:io` (via a test), forcing /// static methods in the `dart:io` `Platform` class (see `platform.dart`). As
/// all callers to instead import this file, which exports the blessed subset /// such, do not export Platform from this file!
/// of `dart:io` that is legal to use in Flutter tools.
/// ///
/// Because of the nature of this file, it is important that **no file APIs /// To ensure that all file system and platform API access within Flutter tools
/// be exported from `dart:io` in this file**! Moreover, be careful about any /// goes through the proper APIs, we forbid direct imports of `dart:io` (via a
/// additional exports that you add to this file, as doing so will increase the /// test), forcing all callers to instead import this file, which exports the
/// API surface that we have to test in Flutter tools, and the APIs in `dart:io` /// blessed subset of `dart:io` that is legal to use in Flutter tools.
/// can sometimes be hard to use in tests. ///
/// Because of the nature of this file, it is important that **platform and file
/// APIs not be exported from `dart:io` in this file**! Moreover, be careful
/// about any additional exports that you add to this file, as doing so will
/// increase the API surface that we have to test in Flutter tools, and the APIs
/// in `dart:io` can sometimes be hard to use in tests.
import 'dart:io' as io show exit, exitCode; import 'dart:io' as io show exit, exitCode;
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
...@@ -28,7 +32,10 @@ import 'package:meta/meta.dart'; ...@@ -28,7 +32,10 @@ import 'package:meta/meta.dart';
export 'dart:io' export 'dart:io'
show show
BytesBuilder, BytesBuilder,
// Directory NO! Use `file_system.dart`
exitCode, exitCode,
// File NO! Use `file_system.dart`
// FileSystemEntity NO! Use `file_system.dart`
GZIP, GZIP,
InternetAddress, InternetAddress,
IOException, IOException,
...@@ -40,13 +47,15 @@ export 'dart:io' ...@@ -40,13 +47,15 @@ export 'dart:io'
HttpRequest, HttpRequest,
HttpServer, HttpServer,
HttpStatus, HttpStatus,
// Link NO! Use `file_system.dart`
pid, pid,
Platform, // Platform NO! use `platform.dart`
Process, Process,
ProcessException, ProcessException,
ProcessResult, ProcessResult,
ProcessSignal, ProcessSignal,
ProcessStartMode, ProcessStartMode,
// RandomAccessFile NO! Use `file_system.dart`
ServerSocket, ServerSocket,
stderr, stderr,
stdin, stdin,
......
...@@ -8,6 +8,7 @@ import 'dart:convert' show ASCII; ...@@ -8,6 +8,7 @@ import 'dart:convert' show ASCII;
import 'package:stack_trace/stack_trace.dart'; import 'package:stack_trace/stack_trace.dart';
import 'io.dart'; import 'io.dart';
import 'platform.dart';
final AnsiTerminal terminal = new AnsiTerminal(); final AnsiTerminal terminal = new AnsiTerminal();
...@@ -202,7 +203,7 @@ enum _LogType { ...@@ -202,7 +203,7 @@ enum _LogType {
class AnsiTerminal { class AnsiTerminal {
AnsiTerminal() { AnsiTerminal() {
// TODO(devoncarew): This detection does not work for Windows. // TODO(devoncarew): This detection does not work for Windows.
String term = Platform.environment['TERM']; String term = platform.environment['TERM'];
supportsColor = term != null && term != 'dumb'; supportsColor = term != null && term != 'dumb';
} }
......
...@@ -10,6 +10,7 @@ import 'package:path/path.dart' as path; ...@@ -10,6 +10,7 @@ import 'package:path/path.dart' as path;
import 'context.dart'; import 'context.dart';
import 'file_system.dart'; import 'file_system.dart';
import 'io.dart'; import 'io.dart';
import 'platform.dart';
import 'process.dart'; import 'process.dart';
import 'process_manager.dart'; import 'process_manager.dart';
...@@ -18,7 +19,7 @@ OperatingSystemUtils get os => context[OperatingSystemUtils]; ...@@ -18,7 +19,7 @@ OperatingSystemUtils get os => context[OperatingSystemUtils];
abstract class OperatingSystemUtils { abstract class OperatingSystemUtils {
factory OperatingSystemUtils() { factory OperatingSystemUtils() {
if (Platform.isWindows) { if (platform.isWindows) {
return new _WindowsUtils(); return new _WindowsUtils();
} else { } else {
return new _PosixUtils(); return new _PosixUtils();
...@@ -27,8 +28,9 @@ abstract class OperatingSystemUtils { ...@@ -27,8 +28,9 @@ abstract class OperatingSystemUtils {
OperatingSystemUtils._private(); OperatingSystemUtils._private();
String get operatingSystem => Platform.operatingSystem;
// TODO(tvolkert): Remove these and migrate callers to Platform
String get operatingSystem => platform.operatingSystem;
bool get isMacOS => operatingSystem == 'macos'; bool get isMacOS => operatingSystem == 'macos';
bool get isWindows => operatingSystem == 'windows'; bool get isWindows => operatingSystem == 'windows';
bool get isLinux => operatingSystem == 'linux'; bool get isLinux => operatingSystem == 'linux';
...@@ -46,7 +48,7 @@ abstract class OperatingSystemUtils { ...@@ -46,7 +48,7 @@ abstract class OperatingSystemUtils {
void unzip(File file, Directory targetDirectory); void unzip(File file, Directory targetDirectory);
/// Returns the name of the [binaryName] executable. /// Returns the name of the [binaryName] executable.
/// ///
/// No-op on most OS. /// No-op on most OS.
/// On Windows it returns [binaryName].[winExtension], if [winExtension] is /// On Windows it returns [binaryName].[winExtension], if [winExtension] is
/// specified, or [binaryName].exe otherwise. /// specified, or [binaryName].exe otherwise.
......
// Copyright 2016 The Chromium 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:platform/platform.dart';
import 'context.dart';
export 'package:platform/platform.dart';
const Platform _kLocalPlatform = const LocalPlatform();
Platform get platform => context == null ? _kLocalPlatform : context[Platform];
...@@ -10,15 +10,15 @@ import 'package:crypto/crypto.dart'; ...@@ -10,15 +10,15 @@ import 'package:crypto/crypto.dart';
import 'package:path/path.dart' as path; import 'package:path/path.dart' as path;
import 'file_system.dart'; import 'file_system.dart';
import 'io.dart'; import 'platform.dart';
bool get isRunningOnBot { bool get isRunningOnBot {
// https://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables // https://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables
// CHROME_HEADLESS is one property set on Flutter's Chrome Infra bots. // CHROME_HEADLESS is one property set on Flutter's Chrome Infra bots.
return return
Platform.environment['TRAVIS'] == 'true' || platform.environment['TRAVIS'] == 'true' ||
Platform.environment['CONTINUOUS_INTEGRATION'] == 'true' || platform.environment['CONTINUOUS_INTEGRATION'] == 'true' ||
Platform.environment['CHROME_HEADLESS'] == '1'; platform.environment['CHROME_HEADLESS'] == '1';
} }
String hex(List<int> bytes) { String hex(List<int> bytes) {
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
import 'package:path/path.dart' as path; import 'package:path/path.dart' as path;
import 'base/context.dart'; import 'base/context.dart';
import 'base/io.dart'; import 'base/platform.dart';
import 'base/utils.dart'; import 'base/utils.dart';
import 'globals.dart'; import 'globals.dart';
...@@ -106,9 +106,9 @@ TargetPlatform getTargetPlatformForName(String platform) { ...@@ -106,9 +106,9 @@ TargetPlatform getTargetPlatformForName(String platform) {
} }
HostPlatform getCurrentHostPlatform() { HostPlatform getCurrentHostPlatform() {
if (Platform.isMacOS) if (platform.isMacOS)
return HostPlatform.darwin_x64; return HostPlatform.darwin_x64;
if (Platform.isLinux) if (platform.isLinux)
return HostPlatform.linux_x64; return HostPlatform.linux_x64;
printError('Unsupported host platform, defaulting to Linux'); printError('Unsupported host platform, defaulting to Linux');
......
...@@ -10,10 +10,10 @@ import 'package:path/path.dart' as path; ...@@ -10,10 +10,10 @@ import 'package:path/path.dart' as path;
import 'base/context.dart'; import 'base/context.dart';
import 'base/file_system.dart'; import 'base/file_system.dart';
import 'base/io.dart';
import 'base/logger.dart'; import 'base/logger.dart';
import 'base/net.dart'; import 'base/net.dart';
import 'base/os.dart'; import 'base/os.dart';
import 'base/platform.dart';
import 'globals.dart'; import 'globals.dart';
/// A wrapper around the `bin/cache/` directory. /// A wrapper around the `bin/cache/` directory.
...@@ -84,7 +84,7 @@ class Cache { ...@@ -84,7 +84,7 @@ class Cache {
static String get dartSdkVersion { static String get dartSdkVersion {
if (_dartSdkVersion == null) { if (_dartSdkVersion == null) {
_dartSdkVersion = Platform.version; _dartSdkVersion = platform.version;
} }
return _dartSdkVersion; return _dartSdkVersion;
} }
...@@ -265,9 +265,9 @@ class FlutterEngine { ...@@ -265,9 +265,9 @@ class FlutterEngine {
if (cache.includeAllPlatforms) if (cache.includeAllPlatforms)
dirs.addAll(<String>['ios', 'ios-profile', 'ios-release', 'linux-x64']); dirs.addAll(<String>['ios', 'ios-profile', 'ios-release', 'linux-x64']);
else if (Platform.isMacOS) else if (platform.isMacOS)
dirs.addAll(<String>['ios', 'ios-profile', 'ios-release']); dirs.addAll(<String>['ios', 'ios-profile', 'ios-release']);
else if (Platform.isLinux) else if (platform.isLinux)
dirs.add('linux-x64'); dirs.add('linux-x64');
return dirs; return dirs;
...@@ -279,9 +279,9 @@ class FlutterEngine { ...@@ -279,9 +279,9 @@ class FlutterEngine {
return <List<String>>[] return <List<String>>[]
..addAll(_osxToolsDirs) ..addAll(_osxToolsDirs)
..addAll(_linuxToolsDirs); ..addAll(_linuxToolsDirs);
else if (Platform.isMacOS) else if (platform.isMacOS)
return _osxToolsDirs; return _osxToolsDirs;
else if (Platform.isLinux) else if (platform.isLinux)
return _linuxToolsDirs; return _linuxToolsDirs;
else else
return <List<String>>[]; return <List<String>>[];
......
...@@ -11,6 +11,7 @@ import '../base/common.dart'; ...@@ -11,6 +11,7 @@ import '../base/common.dart';
import '../base/file_system.dart'; import '../base/file_system.dart';
import '../base/io.dart'; import '../base/io.dart';
import '../base/logger.dart'; import '../base/logger.dart';
import '../base/platform.dart';
import '../base/process_manager.dart'; import '../base/process_manager.dart';
import '../base/os.dart'; import '../base/os.dart';
import '../cache.dart'; import '../cache.dart';
...@@ -190,7 +191,7 @@ class TestCommand extends FlutterCommand { ...@@ -190,7 +191,7 @@ class TestCommand extends FlutterCommand {
} }
testArgs.addAll(files); testArgs.addAll(files);
final String shellPath = tools.getHostToolPath(HostTool.SkyShell) ?? Platform.environment['SKY_SHELL']; final String shellPath = tools.getHostToolPath(HostTool.SkyShell) ?? platform.environment['SKY_SHELL'];
if (!fs.isFileSync(shellPath)) if (!fs.isFileSync(shellPath))
throwToolExit('Cannot find Flutter shell at $shellPath'); throwToolExit('Cannot find Flutter shell at $shellPath');
loader.installHook(shellPath: shellPath, collector: collector, debuggerMode: argResults['start-paused']); loader.installHook(shellPath: shellPath, collector: collector, debuggerMode: argResults['start-paused']);
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
import 'package:path/path.dart' as path; import 'package:path/path.dart' as path;
import '../base/io.dart'; import '../base/platform.dart';
import '../cache.dart'; import '../cache.dart';
/// Locate the Dart SDK. /// Locate the Dart SDK.
...@@ -16,5 +16,5 @@ String get dartSdkPath { ...@@ -16,5 +16,5 @@ String get dartSdkPath {
/// ==> `pub.bat`. The default SDK location can be overridden with a specified /// ==> `pub.bat`. The default SDK location can be overridden with a specified
/// [sdkLocation]. /// [sdkLocation].
String sdkBinaryName(String name, { String sdkLocation }) { String sdkBinaryName(String name, { String sdkLocation }) {
return path.absolute(path.join(sdkLocation ?? dartSdkPath, 'bin', Platform.isWindows ? '$name.bat' : name)); return path.absolute(path.join(sdkLocation ?? dartSdkPath, 'bin', platform.isWindows ? '$name.bat' : name));
} }
...@@ -163,6 +163,8 @@ abstract class Device { ...@@ -163,6 +163,8 @@ abstract class Device {
// supported by Flutter, and, if not, why. // supported by Flutter, and, if not, why.
String supportMessage() => isSupported() ? "Supported" : "Unsupported"; String supportMessage() => isSupported() ? "Supported" : "Unsupported";
// TODO(tvolkert): Rename to `targetPlatform`, and remove the "as p"
// aliases on the `platform.dart` imports where applicable.
TargetPlatform get platform; TargetPlatform get platform;
String get sdkNameAndVersion; String get sdkNameAndVersion;
......
...@@ -3,16 +3,16 @@ ...@@ -3,16 +3,16 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:async'; import 'dart:async';
import 'dart:convert' show UTF8;
import 'package:archive/archive.dart'; import 'package:archive/archive.dart';
import 'dart:convert' show UTF8;
import 'package:path/path.dart' as path; import 'package:path/path.dart' as path;
import 'android/android_workflow.dart'; import 'android/android_workflow.dart';
import 'base/common.dart'; import 'base/common.dart';
import 'base/context.dart'; import 'base/context.dart';
import 'base/file_system.dart'; import 'base/file_system.dart';
import 'base/io.dart'; import 'base/platform.dart';
import 'device.dart'; import 'device.dart';
import 'globals.dart'; import 'globals.dart';
import 'ios/ios_workflow.dart'; import 'ios/ios_workflow.dart';
...@@ -27,7 +27,7 @@ const Map<String, String> _osNames = const <String, String>{ ...@@ -27,7 +27,7 @@ const Map<String, String> _osNames = const <String, String>{
}; };
String osName() { String osName() {
String os = Platform.operatingSystem; String os = platform.operatingSystem;
return _osNames.containsKey(os) ? _osNames[os] : os; return _osNames.containsKey(os) ? _osNames[os] : os;
} }
...@@ -182,7 +182,7 @@ class ValidationResult { ...@@ -182,7 +182,7 @@ class ValidationResult {
if (type == ValidationType.missing) if (type == ValidationType.missing)
return '[x]'; return '[x]';
else if (type == ValidationType.installed) else if (type == ValidationType.installed)
return Platform.isWindows ? '[√]' : '[✓]'; return platform.isWindows ? '[√]' : '[✓]';
else else
return '[-]'; return '[-]';
} }
...@@ -217,7 +217,7 @@ class _FlutterValidator extends DoctorValidator { ...@@ -217,7 +217,7 @@ class _FlutterValidator extends DoctorValidator {
messages.add(new ValidationMessage('Engine revision ${version.engineRevisionShort}')); messages.add(new ValidationMessage('Engine revision ${version.engineRevisionShort}'));
messages.add(new ValidationMessage('Tools Dart version ${version.dartSdkVersion}')); messages.add(new ValidationMessage('Tools Dart version ${version.dartSdkVersion}'));
if (Platform.isWindows) { if (platform.isWindows) {
valid = ValidationType.missing; valid = ValidationType.missing;
messages.add(new ValidationMessage.error( messages.add(new ValidationMessage.error(
...@@ -254,9 +254,9 @@ abstract class IntelliJValidator extends DoctorValidator { ...@@ -254,9 +254,9 @@ abstract class IntelliJValidator extends DoctorValidator {
}; };
static Iterable<DoctorValidator> get installedValidators { static Iterable<DoctorValidator> get installedValidators {
if (Platform.isLinux || Platform.isWindows) if (platform.isLinux || platform.isWindows)
return IntelliJValidatorOnLinuxAndWindows.installed; return IntelliJValidatorOnLinuxAndWindows.installed;
if (Platform.isMacOS) if (platform.isMacOS)
return IntelliJValidatorOnMac.installed; return IntelliJValidatorOnMac.installed;
return <DoctorValidator>[]; return <DoctorValidator>[];
} }
......
...@@ -9,6 +9,7 @@ import '../application_package.dart'; ...@@ -9,6 +9,7 @@ import '../application_package.dart';
import '../base/file_system.dart'; import '../base/file_system.dart';
import '../base/io.dart'; import '../base/io.dart';
import '../base/os.dart'; import '../base/os.dart';
import '../base/platform.dart' as p;
import '../base/process.dart'; import '../base/process.dart';
import '../base/process_manager.dart'; import '../base/process_manager.dart';
import '../build_info.dart'; import '../build_info.dart';
...@@ -28,7 +29,7 @@ class IOSDevices extends PollingDeviceDiscovery { ...@@ -28,7 +29,7 @@ class IOSDevices extends PollingDeviceDiscovery {
IOSDevices() : super('IOSDevices'); IOSDevices() : super('IOSDevices');
@override @override
bool get supportsPlatform => Platform.isMacOS; bool get supportsPlatform => p.platform.isMacOS;
@override @override
List<Device> pollingGetDevices() => IOSDevice.getAttachedDevices(); List<Device> pollingGetDevices() => IOSDevice.getAttachedDevices();
...@@ -125,7 +126,7 @@ class IOSDevice extends Device { ...@@ -125,7 +126,7 @@ class IOSDevice extends Device {
try { try {
command = runCheckedSync(<String>['which', command]).trim(); command = runCheckedSync(<String>['which', command]).trim();
} catch (e) { } catch (e) {
if (Platform.isMacOS) { if (p.platform.isMacOS) {
printError('$command not found. $macInstructions'); printError('$command not found. $macInstructions');
} else { } else {
printError('Cannot control iOS devices or simulators. $command is not available on your platform.'); printError('Cannot control iOS devices or simulators. $command is not available on your platform.');
...@@ -314,7 +315,7 @@ class IOSDevice extends Device { ...@@ -314,7 +315,7 @@ class IOSDevice extends Device {
} }
Future<bool> pushFile(ApplicationPackage app, String localFile, String targetFile) async { Future<bool> pushFile(ApplicationPackage app, String localFile, String targetFile) async {
if (Platform.isMacOS) { if (p.platform.isMacOS) {
runSync(<String>[ runSync(<String>[
pusherPath, pusherPath,
'-t', '-t',
......
...@@ -6,6 +6,7 @@ import 'dart:async'; ...@@ -6,6 +6,7 @@ import 'dart:async';
import '../base/io.dart'; import '../base/io.dart';
import '../base/os.dart'; import '../base/os.dart';
import '../base/platform.dart';
import '../base/process.dart'; import '../base/process.dart';
import '../doctor.dart'; import '../doctor.dart';
import 'mac.dart'; import 'mac.dart';
...@@ -16,7 +17,7 @@ class IOSWorkflow extends DoctorValidator implements Workflow { ...@@ -16,7 +17,7 @@ class IOSWorkflow extends DoctorValidator implements Workflow {
IOSWorkflow() : super('iOS toolchain - develop for iOS devices'); IOSWorkflow() : super('iOS toolchain - develop for iOS devices');
@override @override
bool get appliesToHostPlatform => Platform.isMacOS; bool get appliesToHostPlatform => platform.isMacOS;
// We need xcode (+simctl) to list simulator devices, and idevice_id to list real devices. // We need xcode (+simctl) to list simulator devices, and idevice_id to list real devices.
@override @override
......
...@@ -11,6 +11,7 @@ import '../application_package.dart'; ...@@ -11,6 +11,7 @@ import '../application_package.dart';
import '../base/context.dart'; import '../base/context.dart';
import '../base/file_system.dart'; import '../base/file_system.dart';
import '../base/io.dart'; import '../base/io.dart';
import '../base/platform.dart';
import '../base/process.dart'; import '../base/process.dart';
import '../base/process_manager.dart'; import '../base/process_manager.dart';
import '../build_info.dart'; import '../build_info.dart';
...@@ -220,7 +221,7 @@ final RegExp _xcodeVersionRegExp = new RegExp(r'Xcode (\d+)\..*'); ...@@ -220,7 +221,7 @@ final RegExp _xcodeVersionRegExp = new RegExp(r'Xcode (\d+)\..*');
final String _xcodeRequirement = 'Xcode 7.0 or greater is required to develop for iOS.'; final String _xcodeRequirement = 'Xcode 7.0 or greater is required to develop for iOS.';
bool _checkXcodeVersion() { bool _checkXcodeVersion() {
if (!Platform.isMacOS) if (!platform.isMacOS)
return false; return false;
try { try {
String version = runCheckedSync(<String>['xcodebuild', '-version']); String version = runCheckedSync(<String>['xcodebuild', '-version']);
......
...@@ -13,6 +13,7 @@ import '../base/common.dart'; ...@@ -13,6 +13,7 @@ import '../base/common.dart';
import '../base/context.dart'; import '../base/context.dart';
import '../base/file_system.dart'; import '../base/file_system.dart';
import '../base/io.dart'; import '../base/io.dart';
import '../base/platform.dart' as p;
import '../base/process.dart'; import '../base/process.dart';
import '../base/process_manager.dart'; import '../base/process_manager.dart';
import '../build_info.dart'; import '../build_info.dart';
...@@ -31,7 +32,7 @@ class IOSSimulators extends PollingDeviceDiscovery { ...@@ -31,7 +32,7 @@ class IOSSimulators extends PollingDeviceDiscovery {
IOSSimulators() : super('IOSSimulators'); IOSSimulators() : super('IOSSimulators');
@override @override
bool get supportsPlatform => Platform.isMacOS; bool get supportsPlatform => p.platform.isMacOS;
@override @override
List<Device> pollingGetDevices() => IOSSimulatorUtils.instance.getAttachedDevices(); List<Device> pollingGetDevices() => IOSSimulatorUtils.instance.getAttachedDevices();
...@@ -359,7 +360,7 @@ class IOSSimulator extends Device { ...@@ -359,7 +360,7 @@ class IOSSimulator extends Device {
@override @override
bool isSupported() { bool isSupported() {
if (!Platform.isMacOS) { if (!p.platform.isMacOS) {
_supportMessage = "Not supported on a non Mac host"; _supportMessage = "Not supported on a non Mac host";
return false; return false;
} }
...@@ -532,7 +533,7 @@ class IOSSimulator extends Device { ...@@ -532,7 +533,7 @@ class IOSSimulator extends Device {
Future<bool> pushFile( Future<bool> pushFile(
ApplicationPackage app, String localFile, String targetFile) async { ApplicationPackage app, String localFile, String targetFile) async {
if (Platform.isMacOS) { if (p.platform.isMacOS) {
String simulatorHomeDirectory = _getSimulatorAppHomeDirectory(app); String simulatorHomeDirectory = _getSimulatorAppHomeDirectory(app);
runCheckedSync(<String>['cp', localFile, path.join(simulatorHomeDirectory, targetFile)]); runCheckedSync(<String>['cp', localFile, path.join(simulatorHomeDirectory, targetFile)]);
return true; return true;
......
...@@ -12,8 +12,8 @@ import '../android/android_sdk.dart'; ...@@ -12,8 +12,8 @@ import '../android/android_sdk.dart';
import '../base/common.dart'; import '../base/common.dart';
import '../base/context.dart'; import '../base/context.dart';
import '../base/file_system.dart'; import '../base/file_system.dart';
import '../base/io.dart';
import '../base/logger.dart'; import '../base/logger.dart';
import '../base/platform.dart';
import '../base/process.dart'; import '../base/process.dart';
import '../base/process_manager.dart'; import '../base/process_manager.dart';
import '../cache.dart'; import '../cache.dart';
...@@ -117,12 +117,12 @@ class FlutterCommandRunner extends CommandRunner<Null> { ...@@ -117,12 +117,12 @@ class FlutterCommandRunner extends CommandRunner<Null> {
} }
static String get _defaultFlutterRoot { static String get _defaultFlutterRoot {
if (Platform.environment.containsKey(kFlutterRootEnvironmentVariableName)) if (platform.environment.containsKey(kFlutterRootEnvironmentVariableName))
return Platform.environment[kFlutterRootEnvironmentVariableName]; return platform.environment[kFlutterRootEnvironmentVariableName];
try { try {
if (Platform.script.scheme == 'data') if (platform.script.scheme == 'data')
return '../..'; // we're running as a test return '../..'; // we're running as a test
String script = Platform.script.toFilePath(); String script = platform.script.toFilePath();
if (path.basename(script) == kSnapshotFileName) if (path.basename(script) == kSnapshotFileName)
return path.dirname(path.dirname(path.dirname(script))); return path.dirname(path.dirname(path.dirname(script)));
if (path.basename(script) == kFlutterToolsScriptFileName) if (path.basename(script) == kFlutterToolsScriptFileName)
...@@ -179,7 +179,7 @@ class FlutterCommandRunner extends CommandRunner<Null> { ...@@ -179,7 +179,7 @@ class FlutterCommandRunner extends CommandRunner<Null> {
// enginePath's initialiser uses it). // enginePath's initialiser uses it).
Cache.flutterRoot = path.normalize(path.absolute(globalResults['flutter-root'])); Cache.flutterRoot = path.normalize(path.absolute(globalResults['flutter-root']));
if (Platform.environment['FLUTTER_ALREADY_LOCKED'] != 'true') if (platform.environment['FLUTTER_ALREADY_LOCKED'] != 'true')
await Cache.lock(); await Cache.lock();
if (globalResults['suppress-analytics']) if (globalResults['suppress-analytics'])
...@@ -219,7 +219,7 @@ class FlutterCommandRunner extends CommandRunner<Null> { ...@@ -219,7 +219,7 @@ class FlutterCommandRunner extends CommandRunner<Null> {
} }
String _findEnginePath(ArgResults globalResults) { String _findEnginePath(ArgResults globalResults) {
String engineSourcePath = globalResults['local-engine-src-path'] ?? Platform.environment[kFlutterEngineEnvironmentVariableName]; String engineSourcePath = globalResults['local-engine-src-path'] ?? platform.environment[kFlutterEngineEnvironmentVariableName];
if (engineSourcePath == null && globalResults['local-engine'] != null) { if (engineSourcePath == null && globalResults['local-engine'] != null) {
try { try {
......
...@@ -22,6 +22,7 @@ dependencies: ...@@ -22,6 +22,7 @@ dependencies:
mustache: ^0.2.5 mustache: ^0.2.5
package_config: '>=0.1.5 <2.0.0' package_config: '>=0.1.5 <2.0.0'
path: ^1.4.0 path: ^1.4.0
platform: 1.0.1
process: 1.0.1 process: 1.0.1
pub_semver: ^1.0.0 pub_semver: ^1.0.0
stack_trace: ^1.4.0 stack_trace: ^1.4.0
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter_tools/src/base/context.dart'; import 'package:flutter_tools/src/base/context.dart';
import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/logger.dart'; import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/commands/daemon.dart'; import 'package:flutter_tools/src/commands/daemon.dart';
import 'package:flutter_tools/src/device.dart'; import 'package:flutter_tools/src/device.dart';
import 'package:flutter_tools/src/doctor.dart'; import 'package:flutter_tools/src/doctor.dart';
...@@ -32,9 +32,10 @@ void main() { ...@@ -32,9 +32,10 @@ void main() {
setUp(() { setUp(() {
appContext = new AppContext(); appContext = new AppContext();
notifyingLogger = new NotifyingLogger(); notifyingLogger = new NotifyingLogger();
appContext.setVariable(Platform, new LocalPlatform());
appContext.setVariable(Logger, notifyingLogger); appContext.setVariable(Logger, notifyingLogger);
appContext.setVariable(Doctor, new Doctor()); appContext.setVariable(Doctor, new Doctor());
if (Platform.isMacOS) if (platform.isMacOS)
appContext.setVariable(XCode, new XCode()); appContext.setVariable(XCode, new XCode());
appContext.setVariable(DeviceManager, new MockDeviceManager()); appContext.setVariable(DeviceManager, new MockDeviceManager());
}); });
......
...@@ -2,15 +2,15 @@ ...@@ -2,15 +2,15 @@
// 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 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/dart/dependencies.dart'; import 'package:flutter_tools/src/dart/dependencies.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:path/path.dart' as path; import 'package:path/path.dart' as path;
import 'package:test/test.dart'; import 'package:test/test.dart';
import 'src/context.dart'; import 'src/context.dart';
void main() { void main() {
group('DartDependencySetBuilder', () { group('DartDependencySetBuilder', () {
final String basePath = path.dirname(Platform.script.path); final String basePath = path.dirname(platform.script.path);
final String dataPath = path.join(basePath, 'data', 'dart_dependencies_test'); final String dataPath = path.join(basePath, 'data', 'dart_dependencies_test');
testUsingContext('good', () { testUsingContext('good', () {
final String testPath = path.join(dataPath, 'good'); final String testPath = path.join(dataPath, 'good');
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// 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 'package:flutter_tools/src/base/io.dart'; import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/dart/dependencies.dart'; import 'package:flutter_tools/src/dart/dependencies.dart';
import 'package:flutter_tools/src/dependency_checker.dart'; import 'package:flutter_tools/src/dependency_checker.dart';
import 'package:path/path.dart' as path; import 'package:path/path.dart' as path;
...@@ -12,7 +12,7 @@ import 'src/context.dart'; ...@@ -12,7 +12,7 @@ import 'src/context.dart';
void main() { void main() {
group('DependencyChecker', () { group('DependencyChecker', () {
final String basePath = path.dirname(Platform.script.path); final String basePath = path.dirname(platform.script.path);
final String dataPath = path.join(basePath, 'data', 'dart_dependencies_test'); final String dataPath = path.join(basePath, 'data', 'dart_dependencies_test');
testUsingContext('good', () { testUsingContext('good', () {
final String testPath = path.join(dataPath, 'good'); final String testPath = path.join(dataPath, 'good');
......
...@@ -3,12 +3,12 @@ ...@@ -3,12 +3,12 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart'; import 'package:flutter_tools/src/base/platform.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
void main() { void main() {
setUp(() { setUp(() {
String flutterRoot = Platform.environment['FLUTTER_ROOT']; String flutterRoot = platform.environment['FLUTTER_ROOT'];
assert(fs.currentDirectory.path == '$flutterRoot/packages/flutter_tools'); assert(fs.currentDirectory.path == '$flutterRoot/packages/flutter_tools');
}); });
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/os.dart'; import 'package:flutter_tools/src/base/os.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:path/path.dart' as path; import 'package:path/path.dart' as path;
import 'package:test/test.dart'; import 'package:test/test.dart';
...@@ -28,7 +28,7 @@ void main() { ...@@ -28,7 +28,7 @@ void main() {
os.makeExecutable(file); os.makeExecutable(file);
// Skip this test on windows. // Skip this test on windows.
if (!Platform.isWindows) { if (!platform.isWindows) {
String mode = file.statSync().modeString(); String mode = file.statSync().modeString();
// rwxr--r-- // rwxr--r--
expect(mode.substring(0, 3), endsWith('x')); expect(mode.substring(0, 3), endsWith('x'));
......
...@@ -7,9 +7,9 @@ import 'dart:async'; ...@@ -7,9 +7,9 @@ import 'dart:async';
import 'package:flutter_tools/src/base/config.dart'; import 'package:flutter_tools/src/base/config.dart';
import 'package:flutter_tools/src/base/context.dart'; import 'package:flutter_tools/src/base/context.dart';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/logger.dart'; import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/os.dart'; import 'package:flutter_tools/src/base/os.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/device.dart'; import 'package:flutter_tools/src/device.dart';
import 'package:flutter_tools/src/devfs.dart'; import 'package:flutter_tools/src/devfs.dart';
...@@ -42,6 +42,7 @@ void testUsingContext(String description, dynamic testMethod(), { ...@@ -42,6 +42,7 @@ void testUsingContext(String description, dynamic testMethod(), {
// Initialize the test context with some default mocks. // Initialize the test context with some default mocks.
// Seed these context entries first since others depend on them // Seed these context entries first since others depend on them
testContext.putIfAbsent(Platform, () => new LocalPlatform());
testContext.putIfAbsent(FileSystem, () => new LocalFileSystem()); testContext.putIfAbsent(FileSystem, () => new LocalFileSystem());
testContext.putIfAbsent(ProcessManager, () => new LocalProcessManager()); testContext.putIfAbsent(ProcessManager, () => new LocalProcessManager());
testContext.putIfAbsent(Logger, () => new BufferLogger()); testContext.putIfAbsent(Logger, () => new BufferLogger());
...@@ -68,7 +69,7 @@ void testUsingContext(String description, dynamic testMethod(), { ...@@ -68,7 +69,7 @@ void testUsingContext(String description, dynamic testMethod(), {
testContext.putIfAbsent(SimControl, () => new MockSimControl()); testContext.putIfAbsent(SimControl, () => new MockSimControl());
testContext.putIfAbsent(Usage, () => new MockUsage()); testContext.putIfAbsent(Usage, () => new MockUsage());
final String basePath = path.dirname(Platform.script.path); final String basePath = path.dirname(platform.script.path);
final String flutterRoot = final String flutterRoot =
path.normalize(path.join(basePath, '..', '..', '..')); path.normalize(path.join(basePath, '..', '..', '..'));
try { try {
...@@ -148,7 +149,7 @@ class MockOperatingSystemUtils extends Mock implements OperatingSystemUtils { ...@@ -148,7 +149,7 @@ class MockOperatingSystemUtils extends Mock implements OperatingSystemUtils {
// That way it wouldn't really matter what the mock returns here. // That way it wouldn't really matter what the mock returns here.
@override @override
String getExecutableName(String binaryName, { String winExtension }) { String getExecutableName(String binaryName, { String winExtension }) {
if (!Platform.isWindows) if (!platform.isWindows)
return binaryName; return binaryName;
winExtension ??= 'exe'; winExtension ??= 'exe';
if (path.extension(binaryName).isEmpty && winExtension.isNotEmpty) if (path.extension(binaryName).isEmpty && winExtension.isNotEmpty)
......
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