-
Notifications
You must be signed in to change notification settings - Fork 1.7k
move logic that locates the dart SDK to the analyzer package #21783
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm happy to move our current code, just need some guidance as to where in the package it should live. |
This comment was originally written by @zoechi What about moving it to |
This comment was originally written by @zoechi Seems also related https://codereview.chromium.org/737033002/ |
Moving it to dart:io is an appealing option. If we want it to be in analyzer, then it probably belongs in the class DirectoryBasedDartSdk, probably as a replacement for the defaultSdkDirectory getter. Removed Priority-Unassigned label. |
+Library-IO That's an interesting idea - Removed Area-Analyzer label. |
This comment was originally written by @zoechi See also http://dartbug.com/16994 |
The logic currently in code_transformers may be useful to other packages that want to use the analyzer without using barback.
Something of this sort would be great:
import 'dart:convert' as convert;
import 'dart:io' show File, Link, Platform, Process;
import 'package:path/path.dart' as path;
/// Attempts to provide the current Dart SDK directory. Returns null if the SDK
/// cannot be found.
String get dartSdkDirectory {
bool isSdkDir(String dirname) =>
new File(path.join(dirname, 'lib', '_internal', 'libraries.dart'))
.existsSync();
String executable = Platform.executable;
if (path.split(executable).length == 1) {
// TODO: do something else in windows...
executable = Process
.runSync('which', ['dart'], stdoutEncoding: convert.UTF8).stdout.trim();
// In case Dart is symlinked (e.g. homebrew on Mac) follow symbolic links.
var link = new Link(executable);
if (link.existsSync()) {
executable = link.resolveSymbolicLinksSync();
}
var sdkDir = path.dirname(path.dirname(executable));
if (isSdkDir(sdkDir)) return sdkDir;
}
var dartDir = path.dirname(path.absolute(executable));
// If there's a sub-dir named dart-sdk then we're most likely executing from
// a dart enlistment build directory.
if (isSdkDir(path.join(dartDir, 'dart-sdk'))) {
return path.join(dartDir, 'dart-sdk');
}
// If we can find libraries.dart then it's the root of the SDK.
if (isSdkDir(dartDir)) return dartDir;
var parts = path.split(dartDir);
// If the dart executable is within the sdk dir then get the root.
if (parts.contains('dart-sdk')) {
var dartSdkDir = path.joinAll(parts.take(parts.indexOf('dart-sdk') + 1));
if (isSdkDir(dartSdkDir)) return dartSdkDir;
}
return null;
}
The text was updated successfully, but these errors were encountered: