Migrate flutter_tools to use package:platform (#7642)
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
import 'io.dart';
|
||||
import 'platform.dart';
|
||||
|
||||
const int kDefaultObservatoryPort = 8100;
|
||||
const int kDefaultDiagnosticPort = 8101;
|
||||
@@ -13,9 +13,9 @@ const int kDefaultDrivePort = 8183;
|
||||
/// Return the absolute path of the user's home directory
|
||||
String get homeDirPath {
|
||||
if (_homeDirPath == null) {
|
||||
_homeDirPath = Platform.isWindows
|
||||
? Platform.environment['USERPROFILE']
|
||||
: Platform.environment['HOME'];
|
||||
_homeDirPath = platform.isWindows
|
||||
? platform.environment['USERPROFILE']
|
||||
: platform.environment['HOME'];
|
||||
if (_homeDirPath != null)
|
||||
_homeDirPath = path.absolute(_homeDirPath);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import 'package:path/path.dart' as path;
|
||||
|
||||
import 'context.dart';
|
||||
import 'file_system.dart';
|
||||
import 'io.dart';
|
||||
import 'platform.dart';
|
||||
|
||||
class Config {
|
||||
Config([File configFile]) {
|
||||
@@ -46,7 +46,7 @@ class Config {
|
||||
}
|
||||
|
||||
String _userHomeDir() {
|
||||
String envKey = Platform.operatingSystem == 'windows' ? 'APPDATA' : 'HOME';
|
||||
String value = Platform.environment[envKey];
|
||||
String envKey = platform.operatingSystem == 'windows' ? 'APPDATA' : 'HOME';
|
||||
String value = platform.environment[envKey];
|
||||
return value == null ? '.' : value;
|
||||
}
|
||||
|
||||
@@ -11,16 +11,20 @@
|
||||
/// access with mockable (or in-memory) file systems, making our tests hermetic
|
||||
/// vis-a-vis file system access.
|
||||
///
|
||||
/// To ensure that all file system access within Flutter tools goes through the
|
||||
/// proper APIs, we forbid direct imports of `dart:io` (via a test), forcing
|
||||
/// all callers to instead import this file, which exports the blessed subset
|
||||
/// of `dart:io` that is legal to use in Flutter tools.
|
||||
/// We also use `package:platform` to provide an abstraction away from the
|
||||
/// static methods in the `dart:io` `Platform` class (see `platform.dart`). As
|
||||
/// such, do not export Platform from this file!
|
||||
///
|
||||
/// Because of the nature of this file, it is important that **no file APIs
|
||||
/// 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.
|
||||
/// To ensure that all file system and platform API access within Flutter tools
|
||||
/// goes through the proper APIs, we forbid direct imports of `dart:io` (via a
|
||||
/// test), forcing all callers to instead import this file, which exports the
|
||||
/// blessed subset of `dart:io` that is legal to use in Flutter tools.
|
||||
///
|
||||
/// 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 'package:meta/meta.dart';
|
||||
@@ -28,7 +32,10 @@ import 'package:meta/meta.dart';
|
||||
export 'dart:io'
|
||||
show
|
||||
BytesBuilder,
|
||||
// Directory NO! Use `file_system.dart`
|
||||
exitCode,
|
||||
// File NO! Use `file_system.dart`
|
||||
// FileSystemEntity NO! Use `file_system.dart`
|
||||
GZIP,
|
||||
InternetAddress,
|
||||
IOException,
|
||||
@@ -40,13 +47,15 @@ export 'dart:io'
|
||||
HttpRequest,
|
||||
HttpServer,
|
||||
HttpStatus,
|
||||
// Link NO! Use `file_system.dart`
|
||||
pid,
|
||||
Platform,
|
||||
// Platform NO! use `platform.dart`
|
||||
Process,
|
||||
ProcessException,
|
||||
ProcessResult,
|
||||
ProcessSignal,
|
||||
ProcessStartMode,
|
||||
// RandomAccessFile NO! Use `file_system.dart`
|
||||
ServerSocket,
|
||||
stderr,
|
||||
stdin,
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'dart:convert' show ASCII;
|
||||
import 'package:stack_trace/stack_trace.dart';
|
||||
|
||||
import 'io.dart';
|
||||
import 'platform.dart';
|
||||
|
||||
final AnsiTerminal terminal = new AnsiTerminal();
|
||||
|
||||
@@ -202,7 +203,7 @@ enum _LogType {
|
||||
class AnsiTerminal {
|
||||
AnsiTerminal() {
|
||||
// TODO(devoncarew): This detection does not work for Windows.
|
||||
String term = Platform.environment['TERM'];
|
||||
String term = platform.environment['TERM'];
|
||||
supportsColor = term != null && term != 'dumb';
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import 'package:path/path.dart' as path;
|
||||
import 'context.dart';
|
||||
import 'file_system.dart';
|
||||
import 'io.dart';
|
||||
import 'platform.dart';
|
||||
import 'process.dart';
|
||||
import 'process_manager.dart';
|
||||
|
||||
@@ -18,7 +19,7 @@ OperatingSystemUtils get os => context[OperatingSystemUtils];
|
||||
|
||||
abstract class OperatingSystemUtils {
|
||||
factory OperatingSystemUtils() {
|
||||
if (Platform.isWindows) {
|
||||
if (platform.isWindows) {
|
||||
return new _WindowsUtils();
|
||||
} else {
|
||||
return new _PosixUtils();
|
||||
@@ -27,8 +28,9 @@ abstract class OperatingSystemUtils {
|
||||
|
||||
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 isWindows => operatingSystem == 'windows';
|
||||
bool get isLinux => operatingSystem == 'linux';
|
||||
@@ -46,7 +48,7 @@ abstract class OperatingSystemUtils {
|
||||
void unzip(File file, Directory targetDirectory);
|
||||
|
||||
/// Returns the name of the [binaryName] executable.
|
||||
///
|
||||
///
|
||||
/// No-op on most OS.
|
||||
/// On Windows it returns [binaryName].[winExtension], if [winExtension] is
|
||||
/// specified, or [binaryName].exe otherwise.
|
||||
|
||||
13
packages/flutter_tools/lib/src/base/platform.dart
Normal file
13
packages/flutter_tools/lib/src/base/platform.dart
Normal file
@@ -0,0 +1,13 @@
|
||||
// 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';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
import 'file_system.dart';
|
||||
import 'io.dart';
|
||||
import 'platform.dart';
|
||||
|
||||
bool get isRunningOnBot {
|
||||
// https://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables
|
||||
// CHROME_HEADLESS is one property set on Flutter's Chrome Infra bots.
|
||||
return
|
||||
Platform.environment['TRAVIS'] == 'true' ||
|
||||
Platform.environment['CONTINUOUS_INTEGRATION'] == 'true' ||
|
||||
Platform.environment['CHROME_HEADLESS'] == '1';
|
||||
platform.environment['TRAVIS'] == 'true' ||
|
||||
platform.environment['CONTINUOUS_INTEGRATION'] == 'true' ||
|
||||
platform.environment['CHROME_HEADLESS'] == '1';
|
||||
}
|
||||
|
||||
String hex(List<int> bytes) {
|
||||
|
||||
Reference in New Issue
Block a user