Skip to content

Commit

Permalink
read last line, split-off with-compiler classpath
Browse files Browse the repository at this point in the history
  • Loading branch information
bishabosha committed Jun 21, 2024
1 parent c004c74 commit 93e22c0
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
16 changes: 12 additions & 4 deletions dist/bin/common
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,30 @@ 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"
}

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
}

Expand Down
24 changes: 16 additions & 8 deletions dist/bin/scalac.bat
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,15 @@ goto :eof
@rem output parameter: _JVM_CP_ARGS
:compilerJavaClasspathArgs

call :loadClasspathFromFile
call :loadClasspathFromFile "scala"

set "__TOOLCHAIN=%_CLASS_PATH%"
set "__TOOLCHAIN=%_CLASS_PATH_RESULT%"

call :loadClasspathFromFile "with_compiler"

if defined _CLASS_PATH_RESULT (
set "__TOOLCHAIN=%__TOOLCHAIN%%_PSEP%%_CLASS_PATH_RESULT%"
)

if defined _SCALA_CPATH (
set "_JVM_CP_ARGS=%__TOOLCHAIN%%_SCALA_CPATH%"
Expand All @@ -101,16 +107,18 @@ if defined _SCALA_CPATH (
goto :eof

@REM concatentate every line in "%_ETC_DIR%\scala.classpath" 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 "%_ETC_DIR%\%_ARG_FILE%.classpath" (
for /f "usebackq delims=" %%i in ("%_ETC_DIR%\%_ARG_FILE%.classpath") 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!"
)
)
)
Expand Down
4 changes: 3 additions & 1 deletion project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion project/RepublishPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
}
Expand Down

0 comments on commit 93e22c0

Please sign in to comment.