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

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

Issue 2079303003: Track Source objects in PackageNames. (Closed) Base URL: git@github.com:dart-lang/pub.git@master
Patch Set: Code review changes Created 4 years, 6 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/lock_file.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 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:io'; 6 import 'dart:io';
7 7
8 import 'package:path/path.dart' as p; 8 import 'package:path/path.dart' as p;
9 import 'package:barback/barback.dart'; 9 import 'package:barback/barback.dart';
10 import 'package:pub_semver/pub_semver.dart'; 10 import 'package:pub_semver/pub_semver.dart';
11 11
12 import 'barback/asset_environment.dart'; 12 import 'barback/asset_environment.dart';
13 import 'entrypoint.dart'; 13 import 'entrypoint.dart';
14 import 'exceptions.dart'; 14 import 'exceptions.dart';
15 import 'executable.dart' as exe; 15 import 'executable.dart' as exe;
16 import 'io.dart'; 16 import 'io.dart';
17 import 'lock_file.dart'; 17 import 'lock_file.dart';
18 import 'log.dart' as log; 18 import 'log.dart' as log;
19 import 'package.dart'; 19 import 'package.dart';
20 import 'pubspec.dart'; 20 import 'pubspec.dart';
21 import 'sdk.dart' as sdk; 21 import 'sdk.dart' as sdk;
22 import 'solver/version_solver.dart'; 22 import 'solver/version_solver.dart';
23 import 'source/cached.dart'; 23 import 'source/cached.dart';
24 import 'source/git.dart';
25 import 'source/hosted.dart';
26 import 'source/path.dart';
24 import 'system_cache.dart'; 27 import 'system_cache.dart';
25 import 'utils.dart'; 28 import 'utils.dart';
26 29
27 /// Maintains the set of packages that have been globally activated. 30 /// Maintains the set of packages that have been globally activated.
28 /// 31 ///
29 /// These have been hand-chosen by the user to make their executables in bin/ 32 /// These have been hand-chosen by the user to make their executables in bin/
30 /// available to the entire system. This lets them access them even when the 33 /// available to the entire system. This lets them access them even when the
31 /// current working directory is not inside another entrypoint package. 34 /// current working directory is not inside another entrypoint package.
32 /// 35 ///
33 /// Only one version of a given package name can be globally activated at a 36 /// Only one version of a given package name can be globally activated at a
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 132
130 // Call this just to log what the current active package is, if any. 133 // Call this just to log what the current active package is, if any.
131 _describeActive(name); 134 _describeActive(name);
132 135
133 // Write a lockfile that points to the local package. 136 // Write a lockfile that points to the local package.
134 var fullPath = canonicalize(entrypoint.root.dir); 137 var fullPath = canonicalize(entrypoint.root.dir);
135 var id = cache.path.source.idFor(name, entrypoint.root.version, fullPath); 138 var id = cache.path.source.idFor(name, entrypoint.root.version, fullPath);
136 139
137 // TODO(rnystrom): Look in "bin" and display list of binaries that 140 // TODO(rnystrom): Look in "bin" and display list of binaries that
138 // user can run. 141 // user can run.
139 _writeLockFile(name, new LockFile([id], cache.sources)); 142 _writeLockFile(name, new LockFile([id]));
140 143
141 var binDir = p.join(_directory, name, 'bin'); 144 var binDir = p.join(_directory, name, 'bin');
142 if (dirExists(binDir)) deleteEntry(binDir); 145 if (dirExists(binDir)) deleteEntry(binDir);
143 146
144 _updateBinStubs(entrypoint.root, executables, 147 _updateBinStubs(entrypoint.root, executables,
145 overwriteBinStubs: overwriteBinStubs); 148 overwriteBinStubs: overwriteBinStubs);
146 } 149 }
147 150
148 /// Installs the package [dep] and its dependencies into the system cache. 151 /// Installs the package [dep] and its dependencies into the system cache.
149 Future _installInCache(PackageDep dep, List<String> executables, 152 Future _installInCache(PackageDep dep, List<String> executables,
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 var id = lockFile.packages[package]; 231 var id = lockFile.packages[package];
229 log.message('Activated ${_formatPackage(id)}.'); 232 log.message('Activated ${_formatPackage(id)}.');
230 } 233 }
231 234
232 /// Shows the user the currently active package with [name], if any. 235 /// Shows the user the currently active package with [name], if any.
233 void _describeActive(String name) { 236 void _describeActive(String name) {
234 try { 237 try {
235 var lockFile = new LockFile.load(_getLockFilePath(name), cache.sources); 238 var lockFile = new LockFile.load(_getLockFilePath(name), cache.sources);
236 var id = lockFile.packages[name]; 239 var id = lockFile.packages[name];
237 240
238 if (id.source == 'git') { 241 var source = id.source;
239 var url = cache.git.source.urlFromDescription(id.description); 242 if (source is GitSource) {
243 var url = source.urlFromDescription(id.description);
240 log.message('Package ${log.bold(name)} is currently active from Git ' 244 log.message('Package ${log.bold(name)} is currently active from Git '
241 'repository "${url}".'); 245 'repository "${url}".');
242 } else if (id.source == 'path') { 246 } else if (source is PathSource) {
243 var path = cache.path.source.pathFromDescription(id.description); 247 var path = source.pathFromDescription(id.description);
244 log.message('Package ${log.bold(name)} is currently active at path ' 248 log.message('Package ${log.bold(name)} is currently active at path '
245 '"$path".'); 249 '"$path".');
246 } else { 250 } else {
247 log.message('Package ${log.bold(name)} is currently active at version ' 251 log.message('Package ${log.bold(name)} is currently active at version '
248 '${log.bold(id.version)}.'); 252 '${log.bold(id.version)}.');
249 } 253 }
250 } on IOException { 254 } on IOException {
251 // If we couldn't read the lock file, it's not activated. 255 // If we couldn't read the lock file, it's not activated.
252 return null; 256 return null;
253 } 257 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 var source = cache.source(id.source); 309 var source = cache.source(id.source);
306 var entrypoint; 310 var entrypoint;
307 if (source is CachedSource) { 311 if (source is CachedSource) {
308 // For cached sources, the package itself is in the cache and the 312 // For cached sources, the package itself is in the cache and the
309 // lockfile is the one we just loaded. 313 // lockfile is the one we just loaded.
310 entrypoint = new Entrypoint.inMemory( 314 entrypoint = new Entrypoint.inMemory(
311 cache.load(id), lockFile, cache, isGlobal: true); 315 cache.load(id), lockFile, cache, isGlobal: true);
312 } else { 316 } else {
313 // For uncached sources (i.e. path), the ID just points to the real 317 // For uncached sources (i.e. path), the ID just points to the real
314 // directory for the package. 318 // directory for the package.
315 assert(id.source == "path");
316 entrypoint = new Entrypoint( 319 entrypoint = new Entrypoint(
317 cache.path.source.pathFromDescription(id.description), cache, 320 (id.source as PathSource).pathFromDescription(id.description), cache,
318 isGlobal: true); 321 isGlobal: true);
319 } 322 }
320 323
321 if (entrypoint.root.pubspec.environment.sdkVersion.allows(sdk.version)) { 324 if (entrypoint.root.pubspec.environment.sdkVersion.allows(sdk.version)) {
322 return entrypoint; 325 return entrypoint;
323 } 326 }
324 327
325 dataError("${log.bold(name)} ${entrypoint.root.version} doesn't support " 328 dataError("${log.bold(name)} ${entrypoint.root.version} doesn't support "
326 "Dart ${sdk.version}."); 329 "Dart ${sdk.version}.");
327 } 330 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 if (id == null) { 402 if (id == null) {
400 throw new FormatException("Pubspec for activated package $name didn't " 403 throw new FormatException("Pubspec for activated package $name didn't "
401 "contain an entry for itself."); 404 "contain an entry for itself.");
402 } 405 }
403 406
404 return id; 407 return id;
405 } 408 }
406 409
407 /// Returns formatted string representing the package [id]. 410 /// Returns formatted string representing the package [id].
408 String _formatPackage(PackageId id) { 411 String _formatPackage(PackageId id) {
409 if (id.source == 'git') { 412 var source = id.source;
410 var url = cache.sources.git.urlFromDescription(id.description); 413 if (source is GitSource) {
414 var url = source.urlFromDescription(id.description);
411 return '${log.bold(id.name)} ${id.version} from Git repository "$url"'; 415 return '${log.bold(id.name)} ${id.version} from Git repository "$url"';
412 } else if (id.source == 'path') { 416 } else if (source is PathSource) {
413 var path = cache.sources.path.pathFromDescription(id.description); 417 var path = source.pathFromDescription(id.description);
414 return '${log.bold(id.name)} ${id.version} at path "$path"'; 418 return '${log.bold(id.name)} ${id.version} at path "$path"';
415 } else { 419 } else {
416 return '${log.bold(id.name)} ${id.version}'; 420 return '${log.bold(id.name)} ${id.version}';
417 } 421 }
418 } 422 }
419 423
420 /// Repairs any corrupted globally-activated packages and their binstubs. 424 /// Repairs any corrupted globally-activated packages and their binstubs.
421 /// 425 ///
422 /// Returns a pair of two lists of strings. The first indicates which packages 426 /// Returns a pair of two lists of strings. The first indicates which packages
423 /// were successfully re-activated; the second indicates which failed. 427 /// were successfully re-activated; the second indicates which failed.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 packageExecutables, 472 packageExecutables,
469 overwriteBinStubs: true, 473 overwriteBinStubs: true,
470 snapshots: snapshots, 474 snapshots: snapshots,
471 suggestIfNotOnPath: false); 475 suggestIfNotOnPath: false);
472 successes.add(id.name); 476 successes.add(id.name);
473 } catch (error, stackTrace) { 477 } catch (error, stackTrace) {
474 var message = "Failed to reactivate " 478 var message = "Failed to reactivate "
475 "${log.bold(p.basenameWithoutExtension(entry))}"; 479 "${log.bold(p.basenameWithoutExtension(entry))}";
476 if (id != null) { 480 if (id != null) {
477 message += " ${id.version}"; 481 message += " ${id.version}";
478 if (id.source != "hosted") message += " from ${id.source}"; 482 if (id.source is! HostedSource) message += " from ${id.source}";
479 } 483 }
480 484
481 log.error(message, error, stackTrace); 485 log.error(message, error, stackTrace);
482 failures.add(p.basenameWithoutExtension(entry)); 486 failures.add(p.basenameWithoutExtension(entry));
483 487
484 tryDeleteEntry(entry); 488 tryDeleteEntry(entry);
485 } 489 }
486 } 490 }
487 } 491 }
488 492
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 } 791 }
788 792
789 /// Returns the value of the property named [name] in the bin stub script 793 /// Returns the value of the property named [name] in the bin stub script
790 /// [source]. 794 /// [source].
791 String _binStubProperty(String source, String name) { 795 String _binStubProperty(String source, String name) {
792 var pattern = new RegExp(quoteRegExp(name) + r": ([a-zA-Z0-9_-]+)"); 796 var pattern = new RegExp(quoteRegExp(name) + r": ([a-zA-Z0-9_-]+)");
793 var match = pattern.firstMatch(source); 797 var match = pattern.firstMatch(source);
794 return match == null ? null : match[1]; 798 return match == null ? null : match[1];
795 } 799 }
796 } 800 }
OLDNEW
« no previous file with comments | « lib/src/entrypoint.dart ('k') | lib/src/lock_file.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698