@@ -60,7 +60,7 @@ Pointer<T> Function<T extends NativeType>(String symbolName)?
60
60
final webcrypto_lookup_symbol = webcryptoDartDL.webcrypto_lookup_symbol;
61
61
62
62
// Return a function from Sym to lookup using `webcrypto_lookup_symbol`
63
- final lookup = < T extends NativeType > (String s) =>
63
+ Pointer < T > lookup <T extends NativeType >(String s) =>
64
64
webcrypto_lookup_symbol (symFromString (s).index).cast <T >();
65
65
66
66
// Initialize library
@@ -92,23 +92,12 @@ void initialize_dart_dl(
92
92
93
93
/// Find the `.dart_tool/` folder, returns `null` if unable to find it.
94
94
Uri ? _findDotDartTool () {
95
- // HACK: Because 'dart:isolate' is unavailable in Flutter we have no means
96
- // by which we can find the location of the package_config.json file.
97
- // Which we need, because the binary library created by:
95
+ // HACK: We have no good mechanism for finding the library created by:
98
96
// flutter pub run webcrypto:setup
99
- // is located relative to this path. As a workaround we use
100
- // `Platform.script` and traverse level-up until we find a
101
- // `.dart_tool/package_config.json` file.
97
+ // So we search relative to the script path and CWD.
102
98
103
99
// Find script directory
104
- Uri root;
105
- if (Platform .script.isScheme ('data' )) {
106
- // If `Platform.script` is a data: [Uri] then we are being called from
107
- // `package:test`, luckily this means that CWD is project root.
108
- root = Directory .current.uri;
109
- } else {
110
- root = Platform .script.resolve ('./' );
111
- }
100
+ Uri root = Platform .script.resolve ('./' );
112
101
113
102
// Traverse up until we see a `.dart_tool/package_config.json` file.
114
103
do {
@@ -117,5 +106,18 @@ Uri? _findDotDartTool() {
117
106
return root.resolve ('.dart_tool/' );
118
107
}
119
108
} while (root != (root = root.resolve ('..' )));
109
+
110
+ // If traversing from script directory didn't work, we can look starting from
111
+ // CWD, this typically happens if running as test.
112
+ root = Directory .current.uri;
113
+
114
+ // Traverse up until we see a `.dart_tool/package_config.json` file.
115
+ do {
116
+ if (File .fromUri (root.resolve ('.dart_tool/package_config.json' ))
117
+ .existsSync ()) {
118
+ return root.resolve ('.dart_tool/' );
119
+ }
120
+ } while (root != (root = root.resolve ('..' )));
121
+
120
122
return null ;
121
123
}
0 commit comments