Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer distribution/lib/Standard files when runEngineDistribution #11736

Merged
merged 2 commits into from
Dec 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
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
Comment on lines +92 to +93
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot find the -ea check anywhere. Is this doc up-to-date?

* distribution}/{@code lib} directories.
*/
private static boolean alternativeFile(Source.SourceBuilder b, TruffleFile file) {
var root = file;
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
var stack = new LinkedList<String>();
while (root != null) {
if ("0.0.0-dev".equals(root.getName())) {
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
break;
}
stack.addFirst(root.getName());
root = root.getParent();
}
if (root == null) {
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
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;
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
}
}
Loading