From 41868a75f6aa5e64d867c9062fd78c1882bc795b Mon Sep 17 00:00:00 2001 From: Toine Hartman Date: Thu, 2 Apr 2026 13:53:14 +0200 Subject: [PATCH] Fix library-like compiler path configs. --- .../rascalmpl/library/util/PathConfig.java | 26 ++++++++++++------- test/org/rascalmpl/PathConfigTest.java | 24 ++++++++++++++--- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/src/org/rascalmpl/library/util/PathConfig.java b/src/org/rascalmpl/library/util/PathConfig.java index e62238a0575..7d7bbc90f3f 100644 --- a/src/org/rascalmpl/library/util/PathConfig.java +++ b/src/org/rascalmpl/library/util/PathConfig.java @@ -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 @@ -555,13 +560,12 @@ 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 @@ -569,8 +573,10 @@ private static void buildNormalProjectConfig(ISourceLocation manifestRoot, Rasca 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 @@ -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://` - * correspondence with `mvn://~~`, then the target and source folders of + * correspondence with `mvn://----`, 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`. @@ -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. */ @@ -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"); } diff --git a/test/org/rascalmpl/PathConfigTest.java b/test/org/rascalmpl/PathConfigTest.java index ec9c40338ef..7acfdbfd206 100644 --- a/test/org/rascalmpl/PathConfigTest.java +++ b/test/org/rascalmpl/PathConfigTest.java @@ -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|],"+ @@ -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 { + 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); + } }