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

Unified Diff: lib/src/lock_file.dart

Issue 1282083002: Generate the package spec from the lockfile. (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/global_packages.dart ('k') | lib/src/package_locations.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/lock_file.dart
diff --git a/lib/src/lock_file.dart b/lib/src/lock_file.dart
index d79a42e2309c39e2b8a2473a3ccc7f0ce9c4c1fc..7c6d2221dd10f3df3a8a7b99d35bb7a101532dd3 100644
--- a/lib/src/lock_file.dart
+++ b/lib/src/lock_file.dart
@@ -7,6 +7,7 @@ library pub.lock_file;
import 'dart:collection';
import 'package:path/path.dart' as p;
+import 'package:package_config/packages_file.dart' as packages_file;
import 'package:pub_semver/pub_semver.dart';
import 'package:source_span/source_span.dart';
import 'package:yaml/yaml.dart';
@@ -152,6 +153,31 @@ class LockFile {
return new LockFile._(packages, _sources);
}
+ /// Returns the contents of the `.packages` file generated from this lockfile.
+ ///
+ /// If [entrypoint] is passed, a relative entry is added for its "lib/"
+ /// directory.
+ String packagesFile([String entrypoint]) {
+ var header = """
+Generated by pub on ${new DateTime.now()}.
+This file contains a map from Dart package names to Dart package locations.
+Dart tools, including the Dart VM and Dart analyzer, rely on the content.
Bob Nystrom 2015/08/07 23:51:25 I don't think it's worth putting this in every fil
nweiz 2015/08/08 00:52:57 Done.
+AUTO GENERATED - DO NOT EDIT
+""";
+
+ var map = new Map.fromIterable(ordered(packages.keys), value: (name) {
+ var id = packages[name];
+ var source = _sources[id.source];
+ return p.toUri(p.join(source.getDirectory(id), "lib"));
Bob Nystrom 2015/08/07 23:51:25 What do you think about making this path relative
nweiz 2015/08/08 00:52:57 It does that for path dependencies. For cached dep
+ });
+
+ if (entrypoint != null) map[entrypoint] = Uri.parse("lib/");
+
+ var text = new StringBuffer();
+ packages_file.write(text, map, comment: header);
+ return text.toString();
+ }
+
/// Returns the serialized YAML text of the lock file.
///
/// [packageDir] is the containing directory of the root package, used to
« no previous file with comments | « lib/src/global_packages.dart ('k') | lib/src/package_locations.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698