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

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

Issue 1276673006: Make Source.getDirectory synchronous. (Closed) Base URL: git@github.com:dart-lang/pub.git@master
Patch Set: Created 5 years, 4 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/entrypoint.dart ('k') | lib/src/source.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 library pub.global_packages; 5 library pub.global_packages;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import 'package:path/path.dart' as p; 10 import 'package:path/path.dart' as p;
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 log.message('Deactivated package ${_formatPackage(id)}.'); 275 log.message('Deactivated package ${_formatPackage(id)}.');
276 276
277 deleteEntry(dir); 277 deleteEntry(dir);
278 278
279 return true; 279 return true;
280 } 280 }
281 281
282 /// Finds the active package with [name]. 282 /// Finds the active package with [name].
283 /// 283 ///
284 /// Returns an [Entrypoint] loaded with the active package if found. 284 /// Returns an [Entrypoint] loaded with the active package if found.
285 Future<Entrypoint> find(String name) async { 285 Entrypoint find(String name) {
286 var lockFilePath = _getLockFilePath(name); 286 var lockFilePath = _getLockFilePath(name);
287 var lockFile; 287 var lockFile;
288 try { 288 try {
289 lockFile = new LockFile.load(lockFilePath, cache.sources); 289 lockFile = new LockFile.load(lockFilePath, cache.sources);
290 } on IOException { 290 } on IOException {
291 var oldLockFilePath = p.join(_directory, '$name.lock'); 291 var oldLockFilePath = p.join(_directory, '$name.lock');
292 try { 292 try {
293 // TODO(nweiz): This looks for Dart 1.6's old lockfile location. 293 // TODO(nweiz): This looks for Dart 1.6's old lockfile location.
294 // Remove it when Dart 1.6 is old enough that we don't think anyone 294 // Remove it when Dart 1.6 is old enough that we don't think anyone
295 // will have these lockfiles anymore (issue 20703). 295 // will have these lockfiles anymore (issue 20703).
296 lockFile = new LockFile.load(oldLockFilePath, cache.sources); 296 lockFile = new LockFile.load(oldLockFilePath, cache.sources);
297 } on IOException { 297 } on IOException {
298 // If we couldn't read the lock file, it's not activated. 298 // If we couldn't read the lock file, it's not activated.
299 dataError("No active package ${log.bold(name)}."); 299 dataError("No active package ${log.bold(name)}.");
300 } 300 }
301 301
302 // Move the old lockfile to its new location. 302 // Move the old lockfile to its new location.
303 ensureDir(p.dirname(lockFilePath)); 303 ensureDir(p.dirname(lockFilePath));
304 new File(oldLockFilePath).renameSync(lockFilePath); 304 new File(oldLockFilePath).renameSync(lockFilePath);
305 } 305 }
306 306
307 // Load the package from the cache. 307 // Load the package from the cache.
308 var id = lockFile.packages[name]; 308 var id = lockFile.packages[name];
309 lockFile.packages.remove(name); 309 lockFile.packages.remove(name);
310 310
311 var source = cache.sources[id.source]; 311 var source = cache.sources[id.source];
312 if (source is CachedSource) { 312 if (source is CachedSource) {
313 // For cached sources, the package itself is in the cache and the 313 // For cached sources, the package itself is in the cache and the
314 // lockfile is the one we just loaded. 314 // lockfile is the one we just loaded.
315 var dir = await cache.sources[id.source].getDirectory(id); 315 var dir = cache.sources[id.source].getDirectory(id);
316 var package = new Package.load(name, dir, cache.sources); 316 var package = new Package.load(name, dir, cache.sources);
317 return new Entrypoint.inMemory(package, lockFile, cache); 317 return new Entrypoint.inMemory(package, lockFile, cache);
318 } 318 }
319 319
320 // For uncached sources (i.e. path), the ID just points to the real 320 // For uncached sources (i.e. path), the ID just points to the real
321 // directory for the package. 321 // directory for the package.
322 assert(id.source == "path"); 322 assert(id.source == "path");
323 return new Entrypoint(PathSource.pathFromDescription(id.description), 323 return new Entrypoint(PathSource.pathFromDescription(id.description),
324 cache); 324 cache);
325 } 325 }
326 326
327 /// Runs [package]'s [executable] with [args]. 327 /// Runs [package]'s [executable] with [args].
328 /// 328 ///
329 /// If [executable] is available in its precompiled form, that will be 329 /// If [executable] is available in its precompiled form, that will be
330 /// recompiled if the SDK has been upgraded since it was first compiled and 330 /// recompiled if the SDK has been upgraded since it was first compiled and
331 /// then run. Otherwise, it will be run from source. 331 /// then run. Otherwise, it will be run from source.
332 /// 332 ///
333 /// If [checked] is true, the program is run in checked mode. If [mode] is 333 /// If [checked] is true, the program is run in checked mode. If [mode] is
334 /// passed, it's used as the barback mode; it defaults to 334 /// passed, it's used as the barback mode; it defaults to
335 /// [BarbackMode.RELEASE]. 335 /// [BarbackMode.RELEASE].
336 /// 336 ///
337 /// Returns the exit code from the executable. 337 /// Returns the exit code from the executable.
338 Future<int> runExecutable(String package, String executable, 338 Future<int> runExecutable(String package, String executable,
339 Iterable<String> args, {bool checked: false, BarbackMode mode}) { 339 Iterable<String> args, {bool checked: false, BarbackMode mode}) {
340 if (mode == null) mode = BarbackMode.RELEASE; 340 if (mode == null) mode = BarbackMode.RELEASE;
341 341
342 var binDir = p.join(_directory, package, 'bin'); 342 var binDir = p.join(_directory, package, 'bin');
343 if (mode != BarbackMode.RELEASE || 343 if (mode != BarbackMode.RELEASE ||
344 !fileExists(p.join(binDir, '$executable.dart.snapshot'))) { 344 !fileExists(p.join(binDir, '$executable.dart.snapshot'))) {
345 return find(package).then((entrypoint) { 345 return exe.runExecutable(find(package), package, executable, args,
346 return exe.runExecutable(entrypoint, package, executable, args, 346 isGlobal: true, checked: checked, mode: mode);
347 isGlobal: true, checked: checked, mode: mode);
348 });
349 } 347 }
350 348
351 // Unless the user overrides the verbosity, we want to filter out the 349 // Unless the user overrides the verbosity, we want to filter out the
352 // normal pub output shown while loading the environment. 350 // normal pub output shown while loading the environment.
353 if (log.verbosity == log.Verbosity.NORMAL) { 351 if (log.verbosity == log.Verbosity.NORMAL) {
354 log.verbosity = log.Verbosity.WARNING; 352 log.verbosity = log.Verbosity.WARNING;
355 } 353 }
356 354
357 var snapshotPath = p.join(binDir, '$executable.dart.snapshot'); 355 var snapshotPath = p.join(binDir, '$executable.dart.snapshot');
358 return exe.runSnapshot(snapshotPath, args, 356 return exe.runSnapshot(snapshotPath, args,
359 checked: checked, 357 checked: checked,
360 packagesFile: _getPackagesFilePath(package), 358 packagesFile: _getPackagesFilePath(package),
361 recompile: () { 359 recompile: () async {
362 log.fine("$package:$executable is out of date and needs to be " 360 log.fine("$package:$executable is out of date and needs to be "
363 "recompiled."); 361 "recompiled.");
364 return find(package) 362 var graph = await find(package).loadPackageGraph();
365 .then((entrypoint) => entrypoint.loadPackageGraph()) 363 await _precompileExecutables(graph.entrypoint, package);
366 .then((graph) => _precompileExecutables(graph.entrypoint, package));
367 }); 364 });
368 } 365 }
369 366
370 /// Gets the path to the lock file for an activated cached package with 367 /// Gets the path to the lock file for an activated cached package with
371 /// [name]. 368 /// [name].
372 String _getLockFilePath(String name) => 369 String _getLockFilePath(String name) =>
373 p.join(_directory, name, "pubspec.lock"); 370 p.join(_directory, name, "pubspec.lock");
374 371
375 /// Gets the path to the .packages file for an activated cached package with 372 /// Gets the path to the .packages file for an activated cached package with
376 /// [name]. 373 /// [name].
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 451
455 var successes = []; 452 var successes = [];
456 var failures = []; 453 var failures = [];
457 if (dirExists(_directory)) { 454 if (dirExists(_directory)) {
458 for (var entry in listDir(_directory)) { 455 for (var entry in listDir(_directory)) {
459 var id; 456 var id;
460 try { 457 try {
461 id = _loadPackageId(entry); 458 id = _loadPackageId(entry);
462 log.message("Reactivating ${log.bold(id.name)} ${id.version}..."); 459 log.message("Reactivating ${log.bold(id.name)} ${id.version}...");
463 460
464 var entrypoint = await find(id.name); 461 var entrypoint = find(id.name);
465
466 var graph = await entrypoint.loadPackageGraph(); 462 var graph = await entrypoint.loadPackageGraph();
467 var snapshots = await _precompileExecutables(entrypoint, id.name); 463 var snapshots = await _precompileExecutables(entrypoint, id.name);
468 var packageExecutables = executables.remove(id.name); 464 var packageExecutables = executables.remove(id.name);
469 if (packageExecutables == null) packageExecutables = []; 465 if (packageExecutables == null) packageExecutables = [];
470 _updateBinStubs(graph.packages[id.name], packageExecutables, 466 _updateBinStubs(graph.packages[id.name], packageExecutables,
471 overwriteBinStubs: true, snapshots: snapshots, 467 overwriteBinStubs: true, snapshots: snapshots,
472 suggestIfNotOnPath: false); 468 suggestIfNotOnPath: false);
473 successes.add(id.name); 469 successes.add(id.name);
474 } catch (error, stackTrace) { 470 } catch (error, stackTrace) {
475 var message = "Failed to reactivate " 471 var message = "Failed to reactivate "
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 } 784 }
789 785
790 /// Returns the value of the property named [name] in the bin stub script 786 /// Returns the value of the property named [name] in the bin stub script
791 /// [source]. 787 /// [source].
792 String _binStubProperty(String source, String name) { 788 String _binStubProperty(String source, String name) {
793 var pattern = new RegExp(quoteRegExp(name) + r": ([a-zA-Z0-9_-]+)"); 789 var pattern = new RegExp(quoteRegExp(name) + r": ([a-zA-Z0-9_-]+)");
794 var match = pattern.firstMatch(source); 790 var match = pattern.firstMatch(source);
795 return match == null ? null : match[1]; 791 return match == null ? null : match[1];
796 } 792 }
797 } 793 }
OLDNEW
« no previous file with comments | « lib/src/entrypoint.dart ('k') | lib/src/source.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698