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

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

Issue 1096723002: Make pub generate .packages file. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add test. Created 5 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
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.
4
5 /// Keeps track of used package locations, and can create a package dictionary.
nweiz 2015/06/10 22:33:59 "used package locations" -> "the locations of pack
Lasse Reichstein Nielsen 2015/06/11 11:21:02 Reworded.
6 ///
7 /// A package dictionary is currently a `.packages` file.
nweiz 2015/06/10 22:33:58 What do you mean by "currently"?
Lasse Reichstein Nielsen 2015/06/11 11:21:01 Too specualtive, yes. Removed.
8 library pub.package_locations;
9 // TODO(lrn): Also move packages/ directory management to this library.
nweiz 2015/06/10 22:33:58 Nit: Move this above the library tag.
Lasse Reichstein Nielsen 2015/06/11 11:21:02 Done.
10
11 import 'package:package_config/packages_file.dart' as pkgfile;
nweiz 2015/06/10 22:33:58 We tend to use full words for identifiers except i
Lasse Reichstein Nielsen 2015/06/11 11:21:02 Done.
12
13 import 'package_graph.dart';
14 import 'io.dart';
15 import 'log.dart' as log;
16 import 'utils.dart' show ordered;
17
18 /// Creates a `.packages` file with the location of the packges in `graph`.
nweiz 2015/06/10 22:33:58 "location" -> "locations", "packges" -> "packages"
Lasse Reichstein Nielsen 2015/06/11 11:21:01 Done.
19 ///
20 /// The file is written next to the entry-point of [graph],
nweiz 2015/06/10 22:33:58 "next to" -> "in the root directory of", "entry-po
Lasse Reichstein Nielsen 2015/06/11 11:21:02 Done.
21 /// unless [file] is provided, in which case that file is written to instead.
22 ///
23 /// If the file already exists, it is deleted before the new content is written.
24 void writePackagesMap(PackageGraph graph, {String file}) {
nweiz 2015/06/10 22:33:58 [file] isn't used in this patch and I don't see an
Lasse Reichstein Nielsen 2015/06/11 11:21:01 Done.
25 if (file == null) file = graph.entrypoint.root.path(".packages");
26 print("WRITE!: $file");
nweiz 2015/06/10 22:33:58 Remove this as well as debugging prints below.
Lasse Reichstein Nielsen 2015/06/11 11:21:02 Done.
27 deleteEntry(file);
28 var content = _createPackagesMap(graph, file);
29 try {
30 print("WRITE FILE");
31 writeTextFile(file, content);
32 print("WROTE FILE");
33 } catch (error, stackTrace) {
nweiz 2015/06/10 22:33:58 This should be a fatal error.
Lasse Reichstein Nielsen 2015/06/11 11:21:02 How do you make it fatal? Not catching it?
nweiz 2015/06/12 23:48:08 Yeah, that's all that I mean.
Lasse Reichstein Nielsen 2015/06/23 14:54:33 Done.
Lasse Reichstein Nielsen 2015/06/23 14:54:33 Done.
34 print("DNWRITE: $error");
35 log.error(error, stackTrace);
36 }
37 }
38
39 /// Template for header text put into `.packages` file.
40 ///
41 /// Contains the literal string `$now` which should be replaced by a timestamp.
42 const _headerText = r"""
43 Generate by pub on $now.
44 This file contains a map from Dart package names to Dart package locations.
45 Dart tools, including Dart VM and Dart analyzer, rely on the content.
nweiz 2015/06/10 22:33:58 "Dart VM" -> "the Dart VM".
Lasse Reichstein Nielsen 2015/06/11 11:21:01 Done.
46 AUTO GENERATED - DO NOT EDIT
47 """;
48
49 /// Creates `.packages` file content from the packages in a package graph.
nweiz 2015/06/10 22:33:58 "Creates" -> "Returns the contents of the"
Lasse Reichstein Nielsen 2015/06/11 11:21:02 Done.
50 String _createPackagesMap(PackageGraph packageGraph, File packagesFile) {
nweiz 2015/06/10 22:33:58 "packagesFile" is a string.
Lasse Reichstein Nielsen 2015/06/11 11:21:01 Acknowledged.
51 var header = _headerText.replaceFirst(r"$now", new DateTime.now().toString());
52
53 Uri fileUri = new Uri.file(packagesFile);
nweiz 2015/06/10 22:33:58 Nit: don't type-annotate local variables, and move
Lasse Reichstein Nielsen 2015/06/11 11:21:01 Done.
54
55 var packages = packageGraph.packages;
56 var uriMap = {};
57 for (var packageName in ordered(packages.keys)) {
58 var location = packages[packageName].path("lib/");
nweiz 2015/06/10 22:33:59 Don't include a trailing "/" here.
Lasse Reichstein Nielsen 2015/06/11 11:21:02 Done. The result will have the trailing / anyway,
59 uriMap[packageName] = new Uri.directory(location);
nweiz 2015/06/10 22:33:59 I don't think [Uri.directory] exists. Regardless,
Lasse Reichstein Nielsen 2015/06/11 11:21:02 It exists/will exist in v1.11, but using path.toUr
60 }
61
62 var text = new StringBuffer();
63 pkgfile.write(text, uriMap, baseUri: fileUri, comment: header);
nweiz 2015/06/10 22:33:58 We shouldn't pass [baseUri] here. Most types of de
Lasse Reichstein Nielsen 2015/06/11 11:21:02 Sounds fair. Omitting baseUri should avoid any rel
64 return text.toString();
65 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698