Skip to content

Commit

Permalink
Removed conditional dart:cli usage
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasfj committed Sep 11, 2020
1 parent 014c7f9 commit 96d3bdd
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 107 deletions.
3 changes: 1 addition & 2 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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/**
25 changes: 0 additions & 25 deletions lib/src/boringssl/lookup/finddotdarttool.dart

This file was deleted.

40 changes: 0 additions & 40 deletions lib/src/boringssl/lookup/finddotdarttool_cli.dart

This file was deleted.

37 changes: 0 additions & 37 deletions lib/src/boringssl/lookup/finddotdarttool_fallback.dart

This file was deleted.

35 changes: 32 additions & 3 deletions lib/src/boringssl/lookup/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -39,7 +38,7 @@ String get libraryFileName {
///
/// Returns `null` if it could not be found.
Pointer<Void> Function(Sym) lookupLibraryInDotDartTool() {
final dotDartTool = findDotDartTool();
final dotDartTool = _findDotDartTool();
if (dotDartTool == null) {
return null;
}
Expand All @@ -63,3 +62,33 @@ Pointer<Void> 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;
}

0 comments on commit 96d3bdd

Please sign in to comment.