Skip to content

Commit

Permalink
Use alternativeFile whenever the version is 0.0.0-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach committed Dec 3, 2024
1 parent ff7bf8a commit 9596d54
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.enso.common.LanguageInfo;
import org.enso.pkg.QualifiedName;
import org.enso.text.buffer.Rope;
import org.enso.version.BuildVersion;

/**
* Keeps information about various kinds of sources associated with a {@link Module}. All the record
Expand Down Expand Up @@ -70,7 +71,7 @@ ModuleSources ensureSource(QualifiedName name) throws IOException {
return new ModuleSources(file, rope, src);
} else if (file != null) {
var b = Source.newBuilder(LanguageInfo.ID, file);
assert alternativeFile(b, file) : "Cannot find alternative for " + file;
alternativeFile(b, file);
var src = b.build();
org.enso.text.buffer.Rope lit = Rope.apply(src.getCharacters().toString());
return new ModuleSources(file, lit, src);
Expand All @@ -92,18 +93,23 @@ String getPath() {
* {@code -ea} is enabled, then we try to locate library files under the {@code
* distribution}/{@code lib} directories.
*/
private static boolean alternativeFile(Source.SourceBuilder b, TruffleFile file) {
private static void alternativeFile(Source.SourceBuilder b, TruffleFile file) {
if (!BuildVersion.defaultDevEnsoVersion().equals(BuildVersion.ensoVersion())) {
// no changes when not running development version
return;
}
var root = file;
var stack = new LinkedList<String>();
while (root != null) {
if ("0.0.0-dev".equals(root.getName())) {
if (BuildVersion.defaultDevEnsoVersion().equals(root.getName())) {
break;
}
stack.addFirst(root.getName());
root = root.getParent();
}
if (root == null) {
return true;
// give up when we cannot find a root
return;
}
var libName = root.getParent();
var libNamespace = libName.getParent();
Expand All @@ -124,10 +130,8 @@ private static boolean alternativeFile(Source.SourceBuilder b, TruffleFile file)
}
if (newFile.exists()) {
b.uri(newFile.toUri());
return true;
}
}
}
return false;
}
}

0 comments on commit 9596d54

Please sign in to comment.