Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(296)

Side by Side Diff: pkg/code_transformers/lib/src/dart_sdk.dart

Issue 795433002: Fix code_transformers to consider dart symlinks (typical in brew installations) (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/code_transformers/CHANGELOG.md ('k') | pkg/code_transformers/pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library code_transformers.src.dart_sdk; 5 library code_transformers.src.dart_sdk;
6 6
7 import 'dart:convert' as convert; 7 import 'dart:convert' as convert;
8 import 'dart:io' show File, Platform, Process; 8 import 'dart:io' show File, Platform, Process;
9 import 'package:path/path.dart' as path; 9 import 'package:path/path.dart' as path;
10 import 'package:analyzer/src/generated/engine.dart'; 10 import 'package:analyzer/src/generated/engine.dart';
11 import 'package:analyzer/src/generated/java_io.dart'; 11 import 'package:analyzer/src/generated/java_io.dart';
12 import 'package:analyzer/src/generated/sdk.dart'; 12 import 'package:analyzer/src/generated/sdk.dart';
13 import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk; 13 import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk;
14 import 'package:analyzer/src/generated/source.dart'; 14 import 'package:analyzer/src/generated/source.dart';
15 15
16 16
17 /// Attempts to provide the current Dart SDK directory. 17 /// Attempts to provide the current Dart SDK directory.
18 /// 18 ///
19 /// This will return null if the SDK cannot be found 19 /// This will return null if the SDK cannot be found
20 /// 20 ///
21 /// Note that this may not be correct when executing outside of `pub`. 21 /// Note that this may not be correct when executing outside of `pub`.
22 String get dartSdkDirectory { 22 String get dartSdkDirectory {
23 23
24 bool isSdkDir(String dirname) => 24 bool isSdkDir(String dirname) =>
25 new File(path.join(dirname, 'lib', '_internal', 'libraries.dart')) 25 new File(path.join(dirname, 'lib', '_internal', 'libraries.dart'))
26 .existsSync(); 26 .existsSync();
27 27
28 if (path.split(Platform.executable).length == 1) { 28 String executable = Platform.executable;
29 if (path.split(executable).length == 1) {
29 // TODO(blois): make this cross-platform. 30 // TODO(blois): make this cross-platform.
30 // HACK: A single part, hope it's on the path. 31 // HACK: A single part, hope it's on the path.
31 var result = Process.runSync('which', ['dart'], 32 executable = Process.runSync('which', ['dart'],
32 stdoutEncoding: convert.UTF8); 33 stdoutEncoding: convert.UTF8).stdout.trim();
33 34 // In case Dart is symlinked (e.g. homebrew on Mac) follow symbolic links.
34 var sdkDir = path.dirname(path.dirname(result.stdout)); 35 var link = new Link(executable);
36 if (link.existsSync()) {
37 executable = link.resolveSymbolicLinksSync();
38 }
39 var sdkDir = path.dirname(path.dirname(executable));
35 if (isSdkDir(sdkDir)) return sdkDir; 40 if (isSdkDir(sdkDir)) return sdkDir;
36 } 41 }
37 var dartDir = path.dirname(path.absolute(Platform.executable)); 42
43 var dartDir = path.dirname(path.absolute(executable));
38 // If there's a sub-dir named dart-sdk then we're most likely executing from 44 // If there's a sub-dir named dart-sdk then we're most likely executing from
39 // a dart enlistment build directory. 45 // a dart enlistment build directory.
40 if (isSdkDir(path.join(dartDir, 'dart-sdk'))) { 46 if (isSdkDir(path.join(dartDir, 'dart-sdk'))) {
41 return path.join(dartDir, 'dart-sdk'); 47 return path.join(dartDir, 'dart-sdk');
42 } 48 }
43 // If we can find libraries.dart then it's the root of the SDK. 49 // If we can find libraries.dart then it's the root of the SDK.
44 if (isSdkDir(dartDir)) return dartDir; 50 if (isSdkDir(dartDir)) return dartDir;
45 51
46 var parts = path.split(dartDir); 52 var parts = path.split(dartDir);
47 // If the dart executable is within the sdk dir then get the root. 53 // If the dart executable is within the sdk dir then get the root.
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 UriKind get uriKind => UriKind.DART_URI; 229 UriKind get uriKind => UriKind.DART_URI;
224 230
225 bool get isInSystemLibrary => true; 231 bool get isInSystemLibrary => true;
226 232
227 Source resolveRelative(Uri relativeUri) => 233 Source resolveRelative(Uri relativeUri) =>
228 throw new UnsupportedError('not expecting relative urls in dart: mocks'); 234 throw new UnsupportedError('not expecting relative urls in dart: mocks');
229 235
230 Uri resolveRelativeUri(Uri relativeUri) => 236 Uri resolveRelativeUri(Uri relativeUri) =>
231 throw new UnsupportedError('not expecting relative urls in dart: mocks'); 237 throw new UnsupportedError('not expecting relative urls in dart: mocks');
232 } 238 }
OLDNEW
« no previous file with comments | « pkg/code_transformers/CHANGELOG.md ('k') | pkg/code_transformers/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698