Skip to content

Commit

Permalink
Prefer distribution/lib/Standard files when runEngineDistribution
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach committed Dec 2, 2024
1 parent 2894618 commit ff7bf8a
Showing 1 changed file with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.oracle.truffle.api.TruffleFile;
import com.oracle.truffle.api.source.Source;
import java.io.IOException;
import java.util.LinkedList;
import org.enso.common.LanguageInfo;
import org.enso.pkg.QualifiedName;
import org.enso.text.buffer.Rope;
Expand Down Expand Up @@ -68,7 +69,9 @@ ModuleSources ensureSource(QualifiedName name) throws IOException {
Source src = Source.newBuilder(LanguageInfo.ID, rope.characters(), name.toString()).build();
return new ModuleSources(file, rope, src);
} else if (file != null) {
Source src = Source.newBuilder(LanguageInfo.ID, file).build();
var b = Source.newBuilder(LanguageInfo.ID, file);
assert alternativeFile(b, file) : "Cannot find alternative for " + file;
var src = b.build();
org.enso.text.buffer.Rope lit = Rope.apply(src.getCharacters().toString());
return new ModuleSources(file, lit, src);
}
Expand All @@ -83,4 +86,48 @@ ModuleSources ensureSource(QualifiedName name) throws IOException {
String getPath() {
return file() == null ? null : file().getPath();
}

/**
* Special support for reassigning locations of sources when running development version. When
* {@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) {
var root = file;
var stack = new LinkedList<String>();
while (root != null) {
if ("0.0.0-dev".equals(root.getName())) {
break;
}
stack.addFirst(root.getName());
root = root.getParent();
}
if (root == null) {
return true;
}
var libName = root.getParent();
var libNamespace = libName.getParent();
var libVersion = libNamespace.getParent().getParent();
var builtDistribution = libVersion.getParent().getParent();
if ("built-distribution".equals(builtDistribution.getName())) {
var repositoryRoot = builtDistribution.getParent();
var distRoot = repositoryRoot.resolve("distribution").resolve("lib");
var newLibRoot =
distRoot
.resolve(libNamespace.getName())
.resolve(libName.getName())
.resolve(root.getName());
if (newLibRoot.isDirectory()) {
var newFile = newLibRoot;
for (var n : stack) {
newFile = newFile.resolve(n);
}
if (newFile.exists()) {
b.uri(newFile.toUri());
return true;
}
}
}
return false;
}
}

0 comments on commit ff7bf8a

Please sign in to comment.