Chromium Code Reviews| Index: lib/src/package_locations.dart |
| diff --git a/lib/src/package_locations.dart b/lib/src/package_locations.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..99f498e02358f83e9beb532cd1442516db1dca2f |
| --- /dev/null |
| +++ b/lib/src/package_locations.dart |
| @@ -0,0 +1,65 @@ |
| +// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +/// 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.
|
| +/// |
| +/// 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.
|
| +library pub.package_locations; |
| +// 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.
|
| + |
| +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.
|
| + |
| +import 'package_graph.dart'; |
| +import 'io.dart'; |
| +import 'log.dart' as log; |
| +import 'utils.dart' show ordered; |
| + |
| +/// 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.
|
| +/// |
| +/// 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.
|
| +/// unless [file] is provided, in which case that file is written to instead. |
| +/// |
| +/// If the file already exists, it is deleted before the new content is written. |
| +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.
|
| + if (file == null) file = graph.entrypoint.root.path(".packages"); |
| + 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.
|
| + deleteEntry(file); |
| + var content = _createPackagesMap(graph, file); |
| + try { |
| + print("WRITE FILE"); |
| + writeTextFile(file, content); |
| + print("WROTE FILE"); |
| + } 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.
|
| + print("DNWRITE: $error"); |
| + log.error(error, stackTrace); |
| + } |
| +} |
| + |
| +/// Template for header text put into `.packages` file. |
| +/// |
| +/// Contains the literal string `$now` which should be replaced by a timestamp. |
| +const _headerText = r""" |
| +Generate by pub on $now. |
| +This file contains a map from Dart package names to Dart package locations. |
| +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.
|
| +AUTO GENERATED - DO NOT EDIT |
| +"""; |
| + |
| +/// 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.
|
| +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.
|
| + var header = _headerText.replaceFirst(r"$now", new DateTime.now().toString()); |
| + |
| + 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.
|
| + |
| + var packages = packageGraph.packages; |
| + var uriMap = {}; |
| + for (var packageName in ordered(packages.keys)) { |
| + 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,
|
| + 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
|
| + } |
| + |
| + var text = new StringBuffer(); |
| + 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
|
| + return text.toString(); |
| +} |