From bf670324891a4db0c2282ac893dfba9b8578b72b Mon Sep 17 00:00:00 2001 From: Jamie Thompson Date: Fri, 21 Jun 2024 14:58:42 +0200 Subject: [PATCH] read last line, split-off with-compiler classpath --- dist/bin/common | 16 ++++++++++++---- dist/bin/scalac.bat | 27 ++++++++++++++++++--------- project/Build.scala | 4 +++- project/RepublishPlugin.scala | 8 +++++++- 4 files changed, 40 insertions(+), 15 deletions(-) diff --git a/dist/bin/common b/dist/bin/common index 1ff0ca66274c..63e598d70d7e 100644 --- a/dist/bin/common +++ b/dist/bin/common @@ -10,10 +10,13 @@ load_classpath () { command="$1" psep_pattern="$2" __CLASS_PATH="" - while IFS= read -r line; do + while IFS= read -r line || [ -n "$line" ]; do + # jna-5 only appropriate for some combinations if ! [[ ( -n ${conemu-} || -n ${msys-}) && "$line" == "*jna-5*" ]]; then - # jna-5 only appropriate for some combinations - __CLASS_PATH+="$PROG_HOME/maven2/$line$psep_pattern" + if [ -n "$__CLASS_PATH" ]; then + __CLASS_PATH+="$psep_pattern" + fi + __CLASS_PATH+="$PROG_HOME/maven2/$line" fi done < "$PROG_HOME/etc/$command.classpath" echo "$__CLASS_PATH" @@ -21,11 +24,16 @@ load_classpath () { compilerJavaClasspathArgs () { toolchain="$(load_classpath "scala" "$PSEP")" + toolchain_extra="$(load_classpath "with_compiler" "$PSEP")" + + if [ -n "$toolchain_extra" ]; then + toolchain+="$PSEP$toolchain_extra" + fi if [ -n "${jvm_cp_args-}" ]; then jvm_cp_args="$toolchain$jvm_cp_args" else - jvm_cp_args="$toolchain$PSEP" + jvm_cp_args="$toolchain" fi } diff --git a/dist/bin/scalac.bat b/dist/bin/scalac.bat index fe6d7e3fad4d..dbcbaf11b8e2 100644 --- a/dist/bin/scalac.bat +++ b/dist/bin/scalac.bat @@ -89,9 +89,16 @@ goto :eof @rem output parameter: _JVM_CP_ARGS :compilerJavaClasspathArgs -call :loadClasspathFromFile +set "CP_FILE=%_ETC_DIR%\scala.classpath" +call :loadClasspathFromFile %CP_FILE% +set "__TOOLCHAIN=%_CLASS_PATH_RESULT%" -set "__TOOLCHAIN=%_CLASS_PATH%" +set "CP_FILE=%_ETC_DIR%\with_compiler.classpath" +call :loadClasspathFromFile %CP_FILE% + +if defined _CLASS_PATH_RESULT ( + set "__TOOLCHAIN=%__TOOLCHAIN%%_PSEP%%_CLASS_PATH_RESULT%" +) if defined _SCALA_CPATH ( set "_JVM_CP_ARGS=%__TOOLCHAIN%%_SCALA_CPATH%" @@ -100,17 +107,19 @@ if defined _SCALA_CPATH ( ) goto :eof -@REM concatentate every line in "%_ETC_DIR%\scala.classpath" with _PSEP +@REM concatentate every line in "%_ARG_FILE%" with _PSEP +@REM arg 1 - file to read :loadClasspathFromFile -set _CLASS_PATH= -if exist "%_ETC_DIR%\scala.classpath" ( - for /f "usebackq delims=" %%i in ("%_ETC_DIR%\scala.classpath") do ( +set _ARG_FILE=%1 +set _CLASS_PATH_RESULT= +if exist "%_ARG_FILE%" ( + for /f "usebackq delims=" %%i in ("%_ARG_FILE%") do ( set "_LIB=%_PROG_HOME%\maven2\%%i" set "_LIB=!_LIB:/=\!" - if not defined _CLASS_PATH ( - set "_CLASS_PATH=!_LIB!" + if not defined _CLASS_PATH_RESULT ( + set "_CLASS_PATH_RESULT=!_LIB!" ) else ( - set "_CLASS_PATH=!_CLASS_PATH!%_PSEP%!_LIB!" + set "_CLASS_PATH_RESULT=!_CLASS_PATH_RESULT!%_PSEP%!_LIB!" ) ) ) diff --git a/project/Build.scala b/project/Build.scala index cdabcd3471f1..bd5c06a512e8 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -2129,7 +2129,9 @@ object Build { packResourceDir += (republishRepo.value / "maven2" -> "maven2"), packResourceDir += (republishRepo.value / "etc" -> "etc"), republishCommandLibs += - ("scala" -> List("scala3-interfaces", "scala3-compiler", "scala3-library", "tasty-core", "scala3-staging", "scala3-tasty-inspector")), + ("scala" -> List("scala3-interfaces", "scala3-compiler", "scala3-library", "tasty-core")), + republishCommandLibs += + ("with_compiler" -> List("scala3-staging", "scala3-tasty-inspector", "^!scala3-interfaces", "^!scala3-compiler", "^!scala3-library", "^!tasty-core")), republishCommandLibs += ("scaladoc" -> List("scala3-interfaces", "scala3-compiler", "scala3-library", "tasty-core", "scala3-tasty-inspector", "scaladoc")), Compile / pack := republishPack.value, diff --git a/project/RepublishPlugin.scala b/project/RepublishPlugin.scala index a0a8ce7dae74..e4bf40545a6b 100644 --- a/project/RepublishPlugin.scala +++ b/project/RepublishPlugin.scala @@ -215,7 +215,13 @@ object RepublishPlugin extends AutoPlugin { if (commandLibs.nonEmpty) { IO.createDirectory(republishDir / "etc") for ((command, libs) <- commandLibs) { - val entries = libs.map(fuzzyFind(classpaths, _)).reduce(_ ++ _).distinct + val (negated, actual) = libs.partition(_.startsWith("^!")) + val subtractions = negated.map(_.stripPrefix("^!")) + + def compose(libs: List[String]): List[String] = + libs.map(fuzzyFind(classpaths, _)).reduceOption(_ ++ _).map(_.distinct).getOrElse(Nil) + + val entries = compose(actual).diff(compose(subtractions)) IO.write(republishDir / "etc" / s"$command.classpath", entries.mkString("\n")) } }