Skip to content

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

Closed
sigmundch opened this issue Dec 3, 2014 · 8 comments
Closed

move logic that locates the dart SDK to the analyzer package #21783

sigmundch opened this issue Dec 3, 2014 · 8 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-duplicate Closed in favor of an existing report library-io

Comments

@sigmundch
Copy link
Member

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;
}

@sigmundch
Copy link
Member Author

I'm happy to move our current code, just need some guidance as to where in the package it should live.

@DartBot
Copy link

DartBot commented Dec 4, 2014

This comment was originally written by @zoechi


What about moving it to dart:io to make it even more widely available.
See also dart-archive/angular.dart#1270

@DartBot
Copy link

DartBot commented Dec 4, 2014

This comment was originally written by @zoechi


Seems also related https://codereview.chromium.org/737033002/

@bwilkerson
Copy link
Member

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.
Added Priority-Medium label.

@sigmundch
Copy link
Member Author

+Library-IO

That's an interesting idea - dart:io team - what are your thoughts?


Removed Area-Analyzer label.
Added Area-Library, Library-IO labels.

@sethladd
Copy link
Contributor

sethladd commented Dec 6, 2014

@DartBot
Copy link

DartBot commented Dec 6, 2014

This comment was originally written by @zoechi


See also http://dartbug.com/16994

@sigmundch
Copy link
Member Author

yeah - I think you are right, I'll mark 16994 as a duplicate of this, because that's basically what we want to do.


Added Duplicate label.
Marked as being merged into #16994.

@sigmundch sigmundch added Type-Defect area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-io closed-duplicate Closed in favor of an existing report labels Dec 9, 2014
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-duplicate Closed in favor of an existing report library-io
Projects
None yet
Development

No branches or pull requests

4 participants