From 59a8ef3a21df2c2bd36bdff031392230c9aea9f4 Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Mon, 11 May 2020 12:59:29 -0700 Subject: [PATCH] Remove direct uses of LocalPlatform (#56605) When `const LocalPlatform` is used immediately and not passed as a dependency it does not have utility over the static properties from `dart:io`. Remove these uses to reduce the noise around how the instantiable `Platform` class is used. --- dev/devicelab/lib/framework/manifest.dart | 8 +++----- dev/snippets/lib/main.dart | 6 ++---- dev/tools/gen_keycodes/lib/utils.dart | 5 ++--- .../test/commands.shard/hermetic/attach_test.dart | 4 ++-- 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/dev/devicelab/lib/framework/manifest.dart b/dev/devicelab/lib/framework/manifest.dart index 04b48b74ee..1c5095d8d0 100644 --- a/dev/devicelab/lib/framework/manifest.dart +++ b/dev/devicelab/lib/framework/manifest.dart @@ -2,15 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'dart:io'; + import 'package:meta/meta.dart'; -import 'package:platform/platform.dart'; import 'package:yaml/yaml.dart'; import 'utils.dart'; -Platform get platform => _platform ??= const LocalPlatform(); -Platform _platform; - /// Loads manifest data from `manifest.yaml` file or from [yaml], if present. Manifest loadTaskManifest([ String yaml ]) { final dynamic manifestYaml = yaml == null @@ -73,7 +71,7 @@ class ManifestTask { (String str) => str.split('/')[0] ) ); - String hostPlatform = platform.operatingSystem; + String hostPlatform = Platform.operatingSystem; if (hostPlatform == 'macos') { hostPlatform = 'mac'; // package:platform uses 'macos' while manifest.yaml uses 'mac' } diff --git a/dev/snippets/lib/main.dart b/dev/snippets/lib/main.dart index 5dd69d78e0..e0539440fc 100644 --- a/dev/snippets/lib/main.dart +++ b/dev/snippets/lib/main.dart @@ -2,11 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:io' hide Platform; +import 'dart:io'; import 'package:args/args.dart'; import 'package:path/path.dart' as path; -import 'package:platform/platform.dart'; import 'configuration.dart'; import 'snippets.dart'; @@ -35,8 +34,7 @@ String getChannelName() { /// Generates snippet dartdoc output for a given input, and creates any sample /// applications needed by the snippet. void main(List argList) { - const Platform platform = LocalPlatform(); - final Map environment = platform.environment; + final Map environment = Platform.environment; final ArgParser parser = ArgParser(); final List snippetTypes = SnippetType.values.map((SnippetType type) => getEnumName(type)).toList(); diff --git a/dev/tools/gen_keycodes/lib/utils.dart b/dev/tools/gen_keycodes/lib/utils.dart index 2c2b3c0f8c..95f990f031 100644 --- a/dev/tools/gen_keycodes/lib/utils.dart +++ b/dev/tools/gen_keycodes/lib/utils.dart @@ -2,14 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:io' hide Platform; +import 'dart:io'; import 'package:path/path.dart' as path; -import 'package:platform/platform.dart' show LocalPlatform; /// The location of the Flutter root directory, based on the known location of /// this script. -final Directory flutterRoot = Directory(path.dirname(const LocalPlatform().script.toFilePath())).parent.parent.parent.parent; +final Directory flutterRoot = Directory(path.dirname(Platform.script.toFilePath())).parent.parent.parent.parent; /// Converts `FOO_BAR` to `fooBar`. String shoutingToLowerCamel(String shouting) { diff --git a/packages/flutter_tools/test/commands.shard/hermetic/attach_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/attach_test.dart index 4ca55e4fe7..f5e8649f82 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/attach_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/attach_test.dart @@ -3,13 +3,13 @@ // found in the LICENSE file. import 'dart:async'; +import 'dart:io'; import 'package:file/memory.dart'; import 'package:flutter_tools/src/base/common.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/platform.dart'; import 'package:flutter_tools/src/base/terminal.dart'; import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/commands/attach.dart'; @@ -392,7 +392,7 @@ void main() { }, overrides: { FileSystem: () => testFileSystem, ProcessManager: () => FakeProcessManager.any(), - }, skip: const LocalPlatform().isWindows); // mDNS does not work on Windows. + }, skip: Platform.isWindows); // mDNS does not work on Windows. group('forwarding to given port', () { const int devicePort = 499;