Skip to content
Draft
Show file tree
Hide file tree
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
26 changes: 17 additions & 9 deletions src/org/rascalmpl/library/util/PathConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,12 @@ public PathConfig addLibLoc(ISourceLocation dir) throws IOException {
public PathConfig setBin(ISourceLocation bin) {
return new PathConfig(projectRoot, srcs, libs, bin, ignores, resources, messages);
}


private static boolean isLibraryLike(ISourceLocation root) {
var scheme = root.getScheme();
return scheme.equals("std") || scheme.equals("mvn") || scheme.equals("jar+file");
}

/**
* This will create a PathConfig by learning from the MANIFEST/RASCAL.MF file where the sources
* are, which libraries to reference and which classpath entries to add. If this PathConfig is
Expand Down Expand Up @@ -555,22 +560,23 @@ private static void buildNormalProjectConfig(ISourceLocation manifestRoot, Rasca
}
else {
assert mode == RascalConfigMode.COMPILER: "should be compiler";
// untill we go pom.xml first, you'll always get the rascal jar from our runtime
// until we go pom.xml first, you'll always get the rascal jar from our runtime
// not the one you requested in the pom.xml
libs.append(JarURIResolver.jarify(resolveCurrentRascalRuntimeJar()));
}
}


// This processes Rascal libraries we can find in maven dependencies,
// and we add them to the srcs unless a project is open with the same name, then we defer to its srcs
// to make it easier to edit projects in the IDE
for (var art : mavenClasspath) {
addArtifactToPathConfig(art, manifestRoot, mode, srcs, libs, messages);
}
if (isRoot || mode == RascalConfigMode.INTERPRETER) {
// we have to fill our own src folder
translateSources(manifestRoot, srcs, messages);
if (!isLibraryLike(manifestRoot)) {
// we have to fill our own src folder
translateSources(manifestRoot, srcs, messages);
}
}
else /* for clarity these conditions hold true: if (!isRoot && mode == RascalConfigMode.COMPILER)*/ {
// we have to write our own target folder to the lib path of the parent
Expand Down Expand Up @@ -700,7 +706,7 @@ private static void checkLSPVersionsMatch(ISourceLocation manifestRoot, IListWri
* some level of backward compatibility until everybody has moved to using pom.xml.
*
* If library dependencies exist for _open_ projects in the same IDE, via the `project://<artifactId>`
* correspondence with `mvn://<groupId>~<artifactId>~<version>`, then the target and source folders of
* correspondence with `mvn://<groupId>--<artifactId>--<version>`, then the target and source folders of
* those projects are added to the configuration instead of the jar files.
* For compiler configs this works differently than for interpreter configs.
* The latter adds source folders to the `srcs` while the former adds target folders to the `libs`.
Expand All @@ -720,7 +726,7 @@ private static void checkLSPVersionsMatch(ISourceLocation manifestRoot, IListWri
* or problems view in an IDE, an error LOG for a CI and stderr or stdout for console applications.
*
* @param manifest the source location of the folder which contains MANIFEST/RASCAL.MF.
* @param RascalConfigMode.INTERPRETER | RascalConfigMode.COMPILER
* @param mode RascalConfigMode.INTERPRETER | RascalConfigMode.COMPILER
* @return a PathConfig instance, fully informed to start initializing a Rascal compiler or interpreter, and including a list of revelant info, warning and error messages.
* @throws nothing, because all errors are collected in a messages field of the PathConfig.
*/
Expand All @@ -744,8 +750,10 @@ public static PathConfig fromSourceProjectRascalManifest(ISourceLocation manifes

if (manifestRoot.getScheme().equals("project")) {
target = URIUtil.correctLocation("target", projectName, "");
}
else {
} else if (isLibraryLike(manifestRoot)) {
// `std` and `mvn` resolve to this as well
target = URIUtil.unknownLocation();
} else {
target = URIUtil.getChildLocation(manifestRoot, "target/classes");
}

Expand Down
24 changes: 21 additions & 3 deletions test/org/rascalmpl/PathConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;

import java.io.IOException;

import java.net.URISyntaxException;
import org.junit.Before;
import org.junit.Test;
import org.rascalmpl.library.util.PathConfig;
import org.rascalmpl.library.util.PathConfig.RascalConfigMode;
import org.rascalmpl.uri.URIUtil;
import org.rascalmpl.uri.jar.JarURIResolver;
import org.rascalmpl.values.IRascalValueFactory;

public class PathConfigTest {
private static final IRascalValueFactory VF = IRascalValueFactory.getInstance();

private static final String PCFG_S = "pathConfig("+
"ignores=[|file:///path|],"+
"resources=[|file:///path|],"+
Expand Down Expand Up @@ -64,7 +68,21 @@ public void parsedEquals() throws IOException {
@Test
public void modifiedNotEquals() throws IOException {
var modPcfg = PathConfig.parse(PCFG_S);
modPcfg = modPcfg.addSourceLoc(IRascalValueFactory.getInstance().sourceLocation("unknown:///"));
modPcfg = modPcfg.addSourceLoc(VF.sourceLocation("unknown:///"));
assertNotEquals(pcfg, modPcfg);
}

@Test
public void stdConfig() throws IOException, URISyntaxException {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@toinehartman this is the test you wanted to remove right?

Copy link
Copy Markdown
Member Author

@toinehartman toinehartman Apr 2, 2026

Choose a reason for hiding this comment

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

After our discussion, I was thinking of nuking this PR altogether, instead fixing this where library modules are opened (in LSP).

var root = VF.sourceLocation(URIUtil.assumeCorrect("jar+file:///C:/path/to/.m2/repository/org/rascalmpl/rascal/0.41.0-RC63-SNAPSHOT/rascal-0.41.0-RC63-SNAPSHOT.jar!/org/rascalmpl/library"));
var pcfg = PathConfig.fromSourceProjectRascalManifest(root, RascalConfigMode.COMPILER, true);

var expectedPathConfig = PathConfig.parse("pathConfig(" +
" projectRoot = " + root +
" , libs = " + VF.list(JarURIResolver.jarify(PathConfig.resolveCurrentRascalRuntimeJar())) +
" , bin = |unknown:///|" +
")");

assertEquals(expectedPathConfig, pcfg);
}
}
Loading