Skip to content

Commit 0f1ace2

Browse files
authored
Use a relative path when generating unique IDs for elements (#52)
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
1 parent 79d7ee1 commit 0f1ace2

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 0.5.13
2+
3+
* Use a more efficient `Map` implementation for decoding existing info files.
4+
5+
* Use a relative path when generating unique IDs for elements in non-package
6+
sources.
7+
18
## 0.5.12
29

310
* Improved output of `dart2js_info_diff` by sorting the diffs by

lib/info.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ abstract class BasicInfo implements Info {
7373
// Instead, use the content of the code.
7474
_id = (this as ConstantInfo).code.hashCode;
7575
} else {
76-
_id = longName(this, useLibraryUri: true).hashCode;
76+
_id = longName(this, useLibraryUri: true, forId: true).hashCode;
7777
}
7878
while (!_ids.add(_id)) {
7979
_id++;

lib/src/util.dart

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Graph<Info> graphFromInfo(AllInfo info) {
5252

5353
/// Provide a unique long name associated with [info].
5454
// TODO(sigmund): guarantee that the name is actually unique.
55-
String longName(Info info, {bool useLibraryUri: false}) {
55+
String longName(Info info, {bool useLibraryUri: false, bool forId: false}) {
5656
var infoPath = [];
5757
while (info != null) {
5858
infoPath.add(info);
@@ -66,7 +66,25 @@ String longName(Info info, {bool useLibraryUri: false}) {
6666
// assert(!first || segment is LibraryInfo);
6767
// (today might not be true for for closure classes).
6868
if (segment is LibraryInfo) {
69-
sb.write(useLibraryUri ? segment.uri : segment.name);
69+
// TODO(kevmoo): Remove this when dart2js can be invoked with an app-root
70+
// custom URI
71+
if (useLibraryUri && forId && segment.uri.isScheme('file')) {
72+
assert(Uri.base.isScheme('file'));
73+
var currentBase = Uri.base.path;
74+
var segmentString = segment.uri.path;
75+
76+
// If longName is being called to calculate an element ID (forId = true)
77+
// then use a relative path for the longName calculation
78+
// This allows a more stable ID for cases when files are generated into
79+
// temp directories – e.g. with pkg:build_web_compilers
80+
if (segmentString.startsWith(currentBase)) {
81+
segmentString = segmentString.substring(currentBase.length);
82+
}
83+
84+
sb.write(segmentString);
85+
} else {
86+
sb.write(useLibraryUri ? segment.uri : segment.name);
87+
}
7088
sb.write('::');
7189
} else {
7290
first = false;

0 commit comments

Comments
 (0)