Skip to content

Commit

Permalink
Use a relative path when generating unique IDs for elements (#52)
Browse files Browse the repository at this point in the history
This does not affect the canonical URI for a library, but it does
ensure the IDs for libraries and their members are more stable when
using build systems that rely on temporary directories, like pkg:build

This accomplishes most of the desired behavior from
7fe8659#diff-49250e8c7ce346ad217448560050bf76

which was reverted in
2e1c17e#diff-49250e8c7ce346ad217448560050bf76
  • Loading branch information
kevmoo authored Oct 15, 2018
1 parent 79d7ee1 commit 0f1ace2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.5.13

* Use a more efficient `Map` implementation for decoding existing info files.

* Use a relative path when generating unique IDs for elements in non-package
sources.

## 0.5.12

* Improved output of `dart2js_info_diff` by sorting the diffs by
Expand Down
2 changes: 1 addition & 1 deletion lib/info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ abstract class BasicInfo implements Info {
// Instead, use the content of the code.
_id = (this as ConstantInfo).code.hashCode;
} else {
_id = longName(this, useLibraryUri: true).hashCode;
_id = longName(this, useLibraryUri: true, forId: true).hashCode;
}
while (!_ids.add(_id)) {
_id++;
Expand Down
22 changes: 20 additions & 2 deletions lib/src/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Graph<Info> graphFromInfo(AllInfo info) {

/// Provide a unique long name associated with [info].
// TODO(sigmund): guarantee that the name is actually unique.
String longName(Info info, {bool useLibraryUri: false}) {
String longName(Info info, {bool useLibraryUri: false, bool forId: false}) {
var infoPath = [];
while (info != null) {
infoPath.add(info);
Expand All @@ -66,7 +66,25 @@ String longName(Info info, {bool useLibraryUri: false}) {
// assert(!first || segment is LibraryInfo);
// (today might not be true for for closure classes).
if (segment is LibraryInfo) {
sb.write(useLibraryUri ? segment.uri : segment.name);
// TODO(kevmoo): Remove this when dart2js can be invoked with an app-root
// custom URI
if (useLibraryUri && forId && segment.uri.isScheme('file')) {
assert(Uri.base.isScheme('file'));
var currentBase = Uri.base.path;
var segmentString = segment.uri.path;

// If longName is being called to calculate an element ID (forId = true)
// then use a relative path for the longName calculation
// This allows a more stable ID for cases when files are generated into
// temp directories – e.g. with pkg:build_web_compilers
if (segmentString.startsWith(currentBase)) {
segmentString = segmentString.substring(currentBase.length);
}

sb.write(segmentString);
} else {
sb.write(useLibraryUri ? segment.uri : segment.name);
}
sb.write('::');
} else {
first = false;
Expand Down

0 comments on commit 0f1ace2

Please sign in to comment.