Index: lib/src/options.dart |
diff --git a/lib/src/options.dart b/lib/src/options.dart |
index b6c2cdf562e093da4598cc134b8a09f0f10ceaad..09eeb72866405d43a180caf500f1bd1cc653364e 100644 |
--- a/lib/src/options.dart |
+++ b/lib/src/options.dart |
@@ -6,12 +6,12 @@ |
library dev_compiler.src.options; |
import 'dart:io'; |
+import 'dart:mirrors' show reflectClass, LibraryMirror; |
import 'package:args/args.dart'; |
import 'package:cli_util/cli_util.dart' show getSdkDir; |
import 'package:logging/logging.dart' show Level; |
import 'package:path/path.dart' as path; |
-import 'package:yaml/yaml.dart'; |
import 'package:dev_compiler/strong_mode.dart' show StrongModeOptions; |
@@ -150,7 +150,14 @@ CompilerOptions parseOptions(List<String> argv) { |
} |
var runtimeDir = args['runtime-dir']; |
if (runtimeDir == null) { |
- runtimeDir = _computeRuntimeDir(); |
+ // Figure out this library's path |
+ LibraryMirror thisLibrary = reflectClass(CompilerOptions).owner; |
+ var thisUri = thisLibrary.uri; |
+ assert(thisUri.scheme == 'package'); |
+ var libDir = path.dirname(path.dirname(thisLibrary.uri.path)); |
+ var packageRoot = Platform.packageRoot; |
+ if (packageRoot == '') packageRoot = 'packages'; |
+ runtimeDir = path.join(packageRoot, libDir, 'runtime'); |
} |
var outputDir = args['out']; |
if (outputDir == null && serverMode) { |
@@ -260,54 +267,3 @@ final ArgParser argParser = StrongModeOptions.addArguments(new ArgParser() |
abbr: 'f', |
help: 'Dump info json file (requires dump-info)', |
defaultsTo: null)); |
- |
-/// Tries to find the `lib/runtime/` directory of the dev_compiler package. This |
-/// works when running devc from it's sources or from a snapshot that is |
-/// activated via `pub global activate`. |
vsm
2015/07/14 23:52:30
Will this still work in the `pub global activate`
Jennifer Messerly
2015/07/15 00:29:41
It should, but folks will need to add an explicit
vsm
2015/07/15 00:45:29
Hmm, how do you add an explicit dep in this case?
Jennifer Messerly
2015/07/15 15:30:43
For checking/compiling: yes
For running --server:
|
-String _computeRuntimeDir() { |
- var scriptUri = Platform.script; |
- var scriptPath = scriptUri.path; |
- var file = path.basename(scriptPath); |
- var dir = path.dirname(scriptPath); |
- var lastdir = path.basename(dir); |
- dir = path.dirname(dir); |
- |
- // Both the source devc.dart and the snapshot generated by pub global activate |
- // are under a bin folder. |
- if (lastdir != 'bin') return null; |
- |
- // And both under a project directory containing a pubspec.lock file. |
- var lockfile = path.join(dir, 'pubspec.lock'); |
- if (!new File(lockfile).existsSync()) return null; |
- |
- // If running from sources we found it! |
- if (file == 'devc.dart') return path.join(dir, 'lib', 'runtime'); |
- |
- // If running from a pub global snapshot, we need to read the lock file to |
- // find where the actual sources are located in the pub cache. |
- if (file == 'devc.dart.snapshot') { |
- // Note: this depends on implementation details of pub. |
- var yaml = loadYaml(new File(lockfile).readAsStringSync()); |
- var info = yaml['packages']['dev_compiler']; |
- if (info == null) return null; |
- |
- var cacheDir; |
- if (info['source'] == 'hosted') { |
- cacheDir = path.join( |
- 'hosted', 'pub.dartlang.org', 'dev_compiler-${info["version"]}'); |
- } else if (info['source'] == 'git') { |
- var ref = info['description']['resolved-ref']; |
- cacheDir = path.join('git', 'dev_compiler-${ref}'); |
- } |
- |
- // We should be under "/path/to/pub-cache/global_packages/dev_compiler". |
- // The pub-cache directory is two levels up, but we verify that the layout |
- // looks correct. |
- if (path.basename(dir) != 'dev_compiler') return null; |
- dir = path.dirname(dir); |
- if (path.basename(dir) != 'global_packages') return null; |
- dir = path.dirname(dir); |
- return path.join(dir, cacheDir, 'lib', 'runtime'); |
- } |
- return null; |
-} |