Unverified Commit f3a389c4 authored by Paul Berry's avatar Paul Berry Committed by GitHub

Respect `--dart-sdk` parameter when running analyze.dart tests. (#95174)

parent 7e1e98c3
......@@ -25,8 +25,13 @@ final String flutterRoot = path.dirname(path.dirname(path.dirname(path.fromUri(P
final String flutter = path.join(flutterRoot, 'bin', Platform.isWindows ? 'flutter.bat' : 'flutter');
final String flutterPackages = path.join(flutterRoot, 'packages');
final String flutterExamples = path.join(flutterRoot, 'examples');
final String dart = path.join(flutterRoot, 'bin', 'cache', 'dart-sdk', 'bin', Platform.isWindows ? 'dart.exe' : 'dart');
final String pub = path.join(flutterRoot, 'bin', 'cache', 'dart-sdk', 'bin', Platform.isWindows ? 'pub.bat' : 'pub');
/// The path to the `dart` executable; set at the top of `main`
late final String dart;
/// The path to the `pub` executable; set at the top of `main`
late final String pub;
final String pubCache = path.join(flutterRoot, '.pub-cache');
/// When you call this, you can pass additional arguments to pass custom
......@@ -36,6 +41,12 @@ final String pubCache = path.join(flutterRoot, '.pub-cache');
/// For example:
/// bin/cache/dart-sdk/bin/dart dev/bots/analyze.dart --dart-sdk=/tmp/dart-sdk
Future<void> main(List<String> arguments) async {
final String dartSdk = path.join(
Directory.current.absolute.path,
_getDartSdkFromArguments(arguments) ?? path.join(flutterRoot, 'bin', 'cache', 'dart-sdk'),
);
dart = path.join(dartSdk, 'bin', Platform.isWindows ? 'dart.exe' : 'dart');
pub = path.join(dartSdk, 'bin', Platform.isWindows ? 'pub.bat' : 'pub');
print('$clock STARTING ANALYSIS');
try {
await run(arguments);
......@@ -45,6 +56,31 @@ Future<void> main(List<String> arguments) async {
print('$clock ${bold}Analysis successful.$reset');
}
/// Scans [arguments] for an argument of the form `--dart-sdk` or
/// `--dart-sdk=...` and returns the configured SDK, if any.
String? _getDartSdkFromArguments(List<String> arguments) {
String? result;
for (int i = 0; i < arguments.length; i += 1) {
if (arguments[i] == '--dart-sdk') {
if (result != null) {
exitWithError(<String>['The --dart-sdk argument must not be used more than once.']);
}
if (i + 1 < arguments.length) {
result = arguments[i + 1];
} else {
exitWithError(<String>['--dart-sdk must be followed by a path.']);
}
}
if (arguments[i].startsWith('--dart-sdk=')) {
if (result != null) {
exitWithError(<String>['The --dart-sdk argument must not be used more than once.']);
}
result = arguments[i].substring('--dart-sdk='.length);
}
}
return result;
}
Future<void> run(List<String> arguments) async {
bool assertsEnabled = false;
assert(() { assertsEnabled = true; return true; }());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment