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

Side by Side Diff: lib/src/options.dart

Issue 1223113005: simplify computing of runtime file locations (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 5 months 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
« no previous file with comments | « lib/src/codegen/html_codegen.dart ('k') | lib/src/utils.dart » ('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 /// Set of flags and options passed to the compiler 5 /// Set of flags and options passed to the compiler
6 library dev_compiler.src.options; 6 library dev_compiler.src.options;
7 7
8 import 'dart:io'; 8 import 'dart:io';
9 import 'dart:mirrors' show reflectClass, LibraryMirror;
9 10
10 import 'package:args/args.dart'; 11 import 'package:args/args.dart';
11 import 'package:cli_util/cli_util.dart' show getSdkDir; 12 import 'package:cli_util/cli_util.dart' show getSdkDir;
12 import 'package:logging/logging.dart' show Level; 13 import 'package:logging/logging.dart' show Level;
13 import 'package:path/path.dart' as path; 14 import 'package:path/path.dart' as path;
14 import 'package:yaml/yaml.dart';
15 15
16 import 'package:dev_compiler/strong_mode.dart' show StrongModeOptions; 16 import 'package:dev_compiler/strong_mode.dart' show StrongModeOptions;
17 17
18 /// Options used to set up Source URI resolution in the analysis context. 18 /// Options used to set up Source URI resolution in the analysis context.
19 class SourceResolverOptions { 19 class SourceResolverOptions {
20 /// Whether to resolve 'package:' uris using the multi-package resolver. 20 /// Whether to resolve 'package:' uris using the multi-package resolver.
21 final bool useMultiPackage; 21 final bool useMultiPackage;
22 22
23 /// Custom URI mappings, such as "dart:foo" -> "path/to/foo.dart" 23 /// Custom URI mappings, such as "dart:foo" -> "path/to/foo.dart"
24 final Map<String, String> customUrlMappings; 24 final Map<String, String> customUrlMappings;
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 logLevel = Level.LEVELS.firstWhere((l) => l.name == levelName, 143 logLevel = Level.LEVELS.firstWhere((l) => l.name == levelName,
144 orElse: () => logLevel); 144 orElse: () => logLevel);
145 } 145 }
146 var useColors = stdioType(stdout) == StdioType.TERMINAL; 146 var useColors = stdioType(stdout) == StdioType.TERMINAL;
147 var sdkPath = args['dart-sdk']; 147 var sdkPath = args['dart-sdk'];
148 if (sdkPath == null && !args['mock-sdk']) { 148 if (sdkPath == null && !args['mock-sdk']) {
149 sdkPath = getSdkDir(argv).path; 149 sdkPath = getSdkDir(argv).path;
150 } 150 }
151 var runtimeDir = args['runtime-dir']; 151 var runtimeDir = args['runtime-dir'];
152 if (runtimeDir == null) { 152 if (runtimeDir == null) {
153 runtimeDir = _computeRuntimeDir(); 153 // Figure out this library's path
154 LibraryMirror thisLibrary = reflectClass(CompilerOptions).owner;
155 var thisUri = thisLibrary.uri;
156 assert(thisUri.scheme == 'package');
157 var libDir = path.dirname(path.dirname(thisLibrary.uri.path));
158 var packageRoot = Platform.packageRoot;
159 if (packageRoot == '') packageRoot = 'packages';
160 runtimeDir = path.join(packageRoot, libDir, 'runtime');
154 } 161 }
155 var outputDir = args['out']; 162 var outputDir = args['out'];
156 if (outputDir == null && serverMode) { 163 if (outputDir == null && serverMode) {
157 outputDir = Directory.systemTemp.createTempSync("dev_compiler_out_").path; 164 outputDir = Directory.systemTemp.createTempSync("dev_compiler_out_").path;
158 } 165 }
159 var dumpInfo = args['dump-info']; 166 var dumpInfo = args['dump-info'];
160 if (dumpInfo == null) dumpInfo = serverMode; 167 if (dumpInfo == null) dumpInfo = serverMode;
161 168
162 var customUrlMappings = <String, String>{}; 169 var customUrlMappings = <String, String>{};
163 for (var mapping in args['url-mapping']) { 170 for (var mapping in args['url-mapping']) {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 defaultsTo: '8080') 260 defaultsTo: '8080')
254 ..addFlag('force-compile', 261 ..addFlag('force-compile',
255 help: 'Compile code with static errors', defaultsTo: false) 262 help: 'Compile code with static errors', defaultsTo: false)
256 ..addOption('log', abbr: 'l', help: 'Logging level (defaults to severe)') 263 ..addOption('log', abbr: 'l', help: 'Logging level (defaults to severe)')
257 ..addFlag('dump-info', 264 ..addFlag('dump-info',
258 abbr: 'i', help: 'Dump summary information', defaultsTo: null) 265 abbr: 'i', help: 'Dump summary information', defaultsTo: null)
259 ..addOption('dump-info-file', 266 ..addOption('dump-info-file',
260 abbr: 'f', 267 abbr: 'f',
261 help: 'Dump info json file (requires dump-info)', 268 help: 'Dump info json file (requires dump-info)',
262 defaultsTo: null)); 269 defaultsTo: null));
263
264 /// Tries to find the `lib/runtime/` directory of the dev_compiler package. This
265 /// works when running devc from it's sources or from a snapshot that is
266 /// 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:
267 String _computeRuntimeDir() {
268 var scriptUri = Platform.script;
269 var scriptPath = scriptUri.path;
270 var file = path.basename(scriptPath);
271 var dir = path.dirname(scriptPath);
272 var lastdir = path.basename(dir);
273 dir = path.dirname(dir);
274
275 // Both the source devc.dart and the snapshot generated by pub global activate
276 // are under a bin folder.
277 if (lastdir != 'bin') return null;
278
279 // And both under a project directory containing a pubspec.lock file.
280 var lockfile = path.join(dir, 'pubspec.lock');
281 if (!new File(lockfile).existsSync()) return null;
282
283 // If running from sources we found it!
284 if (file == 'devc.dart') return path.join(dir, 'lib', 'runtime');
285
286 // If running from a pub global snapshot, we need to read the lock file to
287 // find where the actual sources are located in the pub cache.
288 if (file == 'devc.dart.snapshot') {
289 // Note: this depends on implementation details of pub.
290 var yaml = loadYaml(new File(lockfile).readAsStringSync());
291 var info = yaml['packages']['dev_compiler'];
292 if (info == null) return null;
293
294 var cacheDir;
295 if (info['source'] == 'hosted') {
296 cacheDir = path.join(
297 'hosted', 'pub.dartlang.org', 'dev_compiler-${info["version"]}');
298 } else if (info['source'] == 'git') {
299 var ref = info['description']['resolved-ref'];
300 cacheDir = path.join('git', 'dev_compiler-${ref}');
301 }
302
303 // We should be under "/path/to/pub-cache/global_packages/dev_compiler".
304 // The pub-cache directory is two levels up, but we verify that the layout
305 // looks correct.
306 if (path.basename(dir) != 'dev_compiler') return null;
307 dir = path.dirname(dir);
308 if (path.basename(dir) != 'global_packages') return null;
309 dir = path.dirname(dir);
310 return path.join(dir, cacheDir, 'lib', 'runtime');
311 }
312 return null;
313 }
OLDNEW
« no previous file with comments | « lib/src/codegen/html_codegen.dart ('k') | lib/src/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698