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 all commits
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,9 +3,11 @@
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;
import org.enso.version.BuildVersion;

/**
* Keeps information about various kinds of sources associated with a {@link Module}. All the record
Expand Down Expand Up @@ -68,7 +70,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);
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 @@ -83,4 +87,51 @@ 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 void alternativeFile(Source.SourceBuilder b, TruffleFile file) {
if (!BuildVersion.defaultDevEnsoVersion().equals(BuildVersion.ensoVersion())) {
// no changes when not running development version
return;
}
var root = file;
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
var stack = new LinkedList<String>();
while (root != null) {
if (BuildVersion.defaultDevEnsoVersion().equals(root.getName())) {
break;
}
stack.addFirst(root.getName());
root = root.getParent();
}
if (root == null) {
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
// give up when we cannot find a root
return;
}
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
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());
}
}
}
}
}
Loading