From 0cd3f3773a74853c672b1775136ea3b8b74f98ee Mon Sep 17 00:00:00 2001 From: Sung-Shik Jongmans Date: Tue, 17 Dec 2024 10:47:32 +0100 Subject: [PATCH] Realign messages to convey which `std` is used (and which isn't) --- .../interpreter/utils/RascalManifest.java | 15 +++--- .../rascalmpl/library/util/PathConfig.java | 54 +++++++++++-------- 2 files changed, 41 insertions(+), 28 deletions(-) diff --git a/src/org/rascalmpl/interpreter/utils/RascalManifest.java b/src/org/rascalmpl/interpreter/utils/RascalManifest.java index 447bc72aba5..9367bf726ab 100644 --- a/src/org/rascalmpl/interpreter/utils/RascalManifest.java +++ b/src/org/rascalmpl/interpreter/utils/RascalManifest.java @@ -68,13 +68,16 @@ public static String getRascalVersionNumber() { * This looks into the META-INF/MANIFEST.MF file for a Name and Specification-Version */ public String getManifestVersionNumber(ISourceLocation project) throws IOException { - Manifest mf = new Manifest(javaManifest(project)); + InputStream is = javaManifest(project); + if (is != null) { + Manifest mf = new Manifest(is); - String bundleName = mf.getMainAttributes().getValue("Name"); - if (bundleName != null && bundleName.equals("rascal")) { - String result = mf.getMainAttributes().getValue("Specification-Version"); - if (result != null) { - return result; + String bundleName = mf.getMainAttributes().getValue("Name"); + if (bundleName != null && bundleName.equals("rascal")) { + String result = mf.getMainAttributes().getValue("Specification-Version"); + if (result != null) { + return result; + } } } diff --git a/src/org/rascalmpl/library/util/PathConfig.java b/src/org/rascalmpl/library/util/PathConfig.java index fa54792c895..e2e853fa7ea 100644 --- a/src/org/rascalmpl/library/util/PathConfig.java +++ b/src/org/rascalmpl/library/util/PathConfig.java @@ -18,6 +18,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; +import java.util.function.Consumer; +import java.util.function.Predicate; import java.util.jar.Manifest; import org.rascalmpl.interpreter.Configuration; @@ -591,35 +594,42 @@ public static PathConfig fromSourceProjectRascalManifest(ISourceLocation manifes } try { - if (!projectName.equals("rascal") && rascalProject == null) { - // always add the standard library but not for the project named "rascal" - // which contains the (source of) the standard library, and if we already - // have a dependency on the rascal project we don't add it here either. - var rascalLib = resolveCurrentRascalRuntimeJar(); - messages.append(Messages.info("Effective rascal library: " + rascalLib, getPomXmlLocation(manifestRoot))); - } - else if (projectName.equals("rascal")) { - messages.append(Messages.info("detected rascal self-application", getPomXmlLocation(manifestRoot))); + var currentRascal = resolveCurrentRascalRuntimeJar(); + var currentRascalPhysical = reg.logicalToPhysical(currentRascal); + var currentRascalVersion = RascalManifest.getRascalVersionNumber(); + + // Checks if location `otherRascal` represents the same version of + // the project named "rascal" as location `currentRascal` + Predicate isCurrentRascal = otherRascal -> { + try { + var otherRascalPhysical = reg.logicalToPhysical(otherRascal); + var otherRascalVersion = new RascalManifest().getManifestVersionNumber(otherRascalPhysical); + return Objects.equals(currentRascalPhysical, otherRascalPhysical) + || Objects.equals(currentRascalVersion, otherRascalVersion); + } catch (IOException e) { + return false; + } + }; + + Consumer report = s -> messages.append(Messages.info(s, getPomXmlLocation(manifestRoot))); + report.accept("Using Rascal standard library at " + currentRascal + ". Version: " + currentRascalVersion + "."); + + // When this path config's project is `rascal`... + if (projectName.equals("rascal") && !isCurrentRascal.test(target)) { + report.accept("Ignoring Rascal standard library at " + target + " (self-application)"); } - else if (rascalProject != null) { - // The Rascal interpreter can not escape its own classpath, whether + + // When a dependency of this path config's project is `rascal`... + if (rascalProject != null && !isCurrentRascal.test(rascalProject)) { + report.accept("Ignoring Rascal standard library at " + rascalProject + " (dependency in POM)"); + + // Note: The Rascal interpreter can not escape its own classpath, whether // or not we configure a different version in the current project's // pom.xml or not. So that pom dependency is always ignored! - // We check this also in COMPILED mode, for the sake of consistency, // but it is not strictly necessary since the compiler can check and compile // against any standard library on the libs path, even if it's running // itself against a different rascal runtime and standard library. - - RascalManifest rmf = new RascalManifest(); - var builtinVersion = RascalManifest.getRascalVersionNumber(); - var dependentRascalProject = reg.logicalToPhysical(rascalProject); - var dependentVersion = rmf.getManifestVersionNumber(dependentRascalProject); - - if (!builtinVersion.equals(dependentVersion)) { - messages.append(Messages.info("Effective rascal version: " + builtinVersion, getPomXmlLocation(manifestRoot))); - messages.append(Messages.warning("Standard library in different rascal dependency is not used: " + dependentVersion, getPomXmlLocation(manifestRoot))); - } } ISourceLocation projectLoc = URIUtil.correctLocation("project", projectName, "");