From 96d3bdd3ecba889def4187ebec37a1f90e33e7c5 Mon Sep 17 00:00:00 2001 From: Jonas Finnemann Jensen Date: Sat, 12 Sep 2020 01:32:13 +0200 Subject: [PATCH] Removed conditional dart:cli usage --- analysis_options.yaml | 3 +- lib/src/boringssl/lookup/finddotdarttool.dart | 25 ------------ .../boringssl/lookup/finddotdarttool_cli.dart | 40 ------------------- .../lookup/finddotdarttool_fallback.dart | 37 ----------------- lib/src/boringssl/lookup/utils.dart | 35 ++++++++++++++-- 5 files changed, 33 insertions(+), 107 deletions(-) delete mode 100644 lib/src/boringssl/lookup/finddotdarttool.dart delete mode 100644 lib/src/boringssl/lookup/finddotdarttool_cli.dart delete mode 100644 lib/src/boringssl/lookup/finddotdarttool_fallback.dart diff --git a/analysis_options.yaml b/analysis_options.yaml index 82206357..4636eff3 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -15,6 +15,5 @@ include: package:pedantic/analysis_options.yaml analyzer: exclude: - - lib/src/boringssl/lookup/finddotdarttool_cli.dart - # Cannot analyzer subprojects + # Cannot analyze subprojects - example/** diff --git a/lib/src/boringssl/lookup/finddotdarttool.dart b/lib/src/boringssl/lookup/finddotdarttool.dart deleted file mode 100644 index 1b91565d..00000000 --- a/lib/src/boringssl/lookup/finddotdarttool.dart +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2020 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/// This library supplies as [findDotDartTool] function that attempts to find -/// the `.dart_tool/` folder for the current _root package_. The function -/// returns `null` if unable to find it. -/// -/// This split into a library using `dart:cli` and `dart:isolate` when these -/// are available, otherwise the fallback strategy is to walk up from the -/// current script path. -library finddotdarttool; - -export 'finddotdarttool_fallback.dart' - if (dart.library.cli) 'finddotdarttool_cli.dart'; diff --git a/lib/src/boringssl/lookup/finddotdarttool_cli.dart b/lib/src/boringssl/lookup/finddotdarttool_cli.dart deleted file mode 100644 index 27c138ea..00000000 --- a/lib/src/boringssl/lookup/finddotdarttool_cli.dart +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2020 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -import 'dart:cli' as cli; -import 'dart:isolate' show Isolate; -import 'dart:io' show File; -import 'finddotdarttool_fallback.dart' as fallback; - -/// Find the `.dart_tool/` folder, returns `null` if unable to find it. -Uri findDotDartTool() { - // Find [Isolate.packageConfig] and check if contains: - // * `package_config.json`, or, - // * `.dart_tool/package_config.json`. - // If either is the case we know the path to `.dart_tool/`. - final packageConfig = cli.waitFor(Isolate.packageConfig); - if (packageConfig != null && - File.fromUri(packageConfig.resolve('package_config.json')).existsSync()) { - return packageConfig.resolve('./'); - } - if (packageConfig != null && - File.fromUri(packageConfig.resolve('.dart_tool/package_config.json')) - .existsSync()) { - return packageConfig.resolve('.dart_tool/'); - } - - // If [Isolate.packageConfig] isn't helpful we fallback to looking at the - // current script location and traverse up from there. - return fallback.findDotDartTool(); -} diff --git a/lib/src/boringssl/lookup/finddotdarttool_fallback.dart b/lib/src/boringssl/lookup/finddotdarttool_fallback.dart deleted file mode 100644 index e4ab6519..00000000 --- a/lib/src/boringssl/lookup/finddotdarttool_fallback.dart +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2020 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -import 'dart:io' show Platform, File; - -/// Find the `.dart_tool/` folder, returns `null` if unable to find it. -Uri findDotDartTool() { - // HACK: Because 'dart:isolate' is unavailable in Flutter we have no means - // by which we can find the location of the package_config.json file. - // Which we need, because the binary library created by: - // flutter pub run webcrypto:setup - // is located relative to this path. As a workaround we use - // `Platform.script` and traverse level-up until we find a - // `.dart_tool/package_config.json` file. - - // Find script directory - var root = Platform.script.resolve('./'); - // Traverse up until we see a `.dart_tool/package_config.json` file. - do { - if (File.fromUri(root.resolve('.dart_tool/package_config.json')) - .existsSync()) { - return root.resolve('.dart_tool/'); - } - } while (root != (root = root.resolve('..'))); - return null; -} diff --git a/lib/src/boringssl/lookup/utils.dart b/lib/src/boringssl/lookup/utils.dart index 97336d0f..2c37e3c2 100644 --- a/lib/src/boringssl/lookup/utils.dart +++ b/lib/src/boringssl/lookup/utils.dart @@ -12,8 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import 'dart:io' show Platform, File; -import 'finddotdarttool.dart'; +import 'dart:io' show Platform, Directory, File; import 'dart:ffi'; import 'symbols.generated.dart'; @@ -39,7 +38,7 @@ String get libraryFileName { /// /// Returns `null` if it could not be found. Pointer Function(Sym) lookupLibraryInDotDartTool() { - final dotDartTool = findDotDartTool(); + final dotDartTool = _findDotDartTool(); if (dotDartTool == null) { return null; } @@ -63,3 +62,33 @@ Pointer Function(Sym) lookupLibraryInDotDartTool() { } return null; } + +/// Find the `.dart_tool/` folder, returns `null` if unable to find it. +Uri _findDotDartTool() { + // HACK: Because 'dart:isolate' is unavailable in Flutter we have no means + // by which we can find the location of the package_config.json file. + // Which we need, because the binary library created by: + // flutter pub run webcrypto:setup + // is located relative to this path. As a workaround we use + // `Platform.script` and traverse level-up until we find a + // `.dart_tool/package_config.json` file. + + // Find script directory + Uri root; + if (Platform.script.isScheme('data')) { + // If `Platform.script` is a data: [Uri] then we are being called from + // `package:test`, luckily this means that CWD is project root. + root = Directory.current.uri; + } else { + root = Platform.script.resolve('./'); + } + + // Traverse up until we see a `.dart_tool/package_config.json` file. + do { + if (File.fromUri(root.resolve('.dart_tool/package_config.json')) + .existsSync()) { + return root.resolve('.dart_tool/'); + } + } while (root != (root = root.resolve('..'))); + return null; +}