Skip to content

Commit

Permalink
download native launchers and overwrite scripts
Browse files Browse the repository at this point in the history
TODO: add overrides for windows
  • Loading branch information
bishabosha committed May 17, 2024
1 parent 72fd2bb commit 28995e1
Show file tree
Hide file tree
Showing 9 changed files with 217 additions and 119 deletions.
5 changes: 5 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ val `scaladoc-js-main` = Build.`scaladoc-js-main`
val `scaladoc-js-contributors` = Build.`scaladoc-js-contributors`
val `scala3-bench-run` = Build.`scala3-bench-run`
val dist = Build.dist
val `dist-mac-x64` = Build.`dist-mac-x64`
val `dist-mac-aarch64` = Build.`dist-mac-aarch64`
val `dist-win-x64` = Build.`dist-win-x64`
val `dist-linux-x64` = Build.`dist-linux-x64`
val `dist-linux-aarch64` = Build.`dist-linux-aarch64`
val `community-build` = Build.`community-build`
val `sbt-community-build` = Build.`sbt-community-build`
val `scala3-presentation-compiler` = Build.`scala3-presentation-compiler`
Expand Down
3 changes: 3 additions & 0 deletions dist/bin-native-overrides/cli-common-platform
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

SCALA_CLI_CMD_BASH=("\"$PROG_HOME/bin/scala-cli\"")
56 changes: 1 addition & 55 deletions dist/bin/cli-common
Original file line number Diff line number Diff line change
Expand Up @@ -71,44 +71,7 @@ if [[ ${cygwin-} || ${mingw-} || ${msys-} ]]; then
esac
fi

# Resolve JAVA_HOME from javac command path
if [ -z "$JAVA_HOME" ]; then
javaExecutable="`which javac`"
if [ -n "$javaExecutable" -a -f "$javaExecutable" -a ! "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
# readlink(1) is not available as standard on Solaris 10.
readLink=`which readlink`
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
javaExecutable="`readlink -f \"$javaExecutable\"`"
javaHome="`dirname \"$javaExecutable\"`"
javaHome=`expr "$javaHome" : '\(.*\)/bin'`
JAVA_HOME="$javaHome"
export JAVA_HOME
fi
fi
fi

if [ -z "${JAVACMD-}" ] ; then
if [ -n "${JAVA_HOME-}" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
else
JAVACMD="`which java`"
fi
fi

if [ ! -x "$JAVACMD" ] ; then
echo "Error: JAVA_HOME is not defined correctly."
echo " We cannot execute $JAVACMD"
exit 1
fi

if [ -z "$JAVA_HOME" ] ; then
echo "Warning: JAVA_HOME environment variable is not set."
fi
source "$PROG_HOME/bin/cli-common-platform"

CLASSPATH_SUFFIX=""
# Path separator used in EXTRA_CLASSPATH
Expand Down Expand Up @@ -136,23 +99,6 @@ fi
# * The code below is for Dotty
# *-------------------------------------------------*/

find_lib () {
for lib in "$PROG_HOME"/lib/$1 ; do
if [[ -f "$lib" ]]; then
if [ -n "$CYGPATHCMD" ]; then
"$CYGPATHCMD" -am "$lib"
elif [[ $mingw || $msys ]]; then
echo "$lib" | sed 's|/|\\\\|g'
else
echo "$lib"
fi
return
fi
done
}

SCALA_CLI_JAR="$PROG_HOME/etc/scala-cli.jar"

declare -a scala_args

addScala () {
Expand Down
5 changes: 5 additions & 0 deletions dist/bin/cli-common-platform
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

source "$PROG_HOME/bin/common-java"

SCALA_CLI_CMD_BASH=("\"$JAVACMD\"" "-jar \"$PROG_HOME/bin/scala-cli.jar\"")
39 changes: 1 addition & 38 deletions dist/bin/common
Original file line number Diff line number Diff line change
Expand Up @@ -67,44 +67,7 @@ if [[ ${cygwin-} || ${mingw-} || ${msys-} ]]; then
esac
fi

# Resolve JAVA_HOME from javac command path
if [ -z "$JAVA_HOME" ]; then
javaExecutable="`which javac`"
if [ -n "$javaExecutable" -a -f "$javaExecutable" -a ! "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
# readlink(1) is not available as standard on Solaris 10.
readLink=`which readlink`
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
javaExecutable="`readlink -f \"$javaExecutable\"`"
javaHome="`dirname \"$javaExecutable\"`"
javaHome=`expr "$javaHome" : '\(.*\)/bin'`
JAVA_HOME="$javaHome"
export JAVA_HOME
fi
fi
fi

if [ -z "${JAVACMD-}" ] ; then
if [ -n "${JAVA_HOME-}" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
else
JAVACMD="`which java`"
fi
fi

if [ ! -x "$JAVACMD" ] ; then
echo "Error: JAVA_HOME is not defined correctly."
echo " We cannot execute $JAVACMD"
exit 1
fi

if [ -z "$JAVA_HOME" ] ; then
echo "Warning: JAVA_HOME environment variable is not set."
fi
source "$PROG_HOME/bin/common-java"

CLASSPATH_SUFFIX=""
# Path separator used in EXTRA_CLASSPATH
Expand Down
40 changes: 40 additions & 0 deletions dist/bin/common-java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash

# Resolve JAVA_HOME from javac command path
if [ -z "$JAVA_HOME" ]; then
javaExecutable="`which javac`"
if [ -n "$javaExecutable" -a -f "$javaExecutable" -a ! "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
# readlink(1) is not available as standard on Solaris 10.
readLink=`which readlink`
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
javaExecutable="`readlink -f \"$javaExecutable\"`"
javaHome="`dirname \"$javaExecutable\"`"
javaHome=`expr "$javaHome" : '\(.*\)/bin'`
JAVA_HOME="$javaHome"
export JAVA_HOME
fi
fi
fi

if [ -z "${JAVACMD-}" ] ; then
if [ -n "${JAVA_HOME-}" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
else
JAVACMD="`which java`"
fi
fi

if [ ! -x "$JAVACMD" ] ; then
echo "Error: JAVA_HOME is not defined correctly."
echo " We cannot execute $JAVACMD"
exit 1
fi

if [ -z "$JAVA_HOME" ] ; then
echo "Warning: JAVA_HOME environment variable is not set."
fi
5 changes: 3 additions & 2 deletions dist/bin/scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ done

# exec here would prevent onExit from being called, leaving terminal in unusable state
[ -z "${ConEmuPID-}" -o -n "${cygwin-}" ] && export MSYSTEM= PWD= # workaround for #12405
eval "\"$JAVACMD\"" \
"-jar \"$SCALA_CLI_JAR\"" \

# SCALA_CLI_CMD_BASH is an array, set by cli-common-platform
eval "${SCALA_CLI_CMD_BASH[@]}" \
"--prog-name scala" \
"--cli-default-scala-version \"$SCALA_VERSION\"" \
"-r \"$MVN_REPOSITORY\"" \
Expand Down
61 changes: 51 additions & 10 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2092,22 +2092,63 @@ object Build {
packMain := Map(),
publishArtifact := false,
packGenerateMakefile := false,
packArchiveName := "scala3-" + dottyVersion,
republishRepo := target.value / "republish",
republishLaunchers := {
val cliV = scalaCliLauncherVersion
Seq(
("scala-cli.jar", cliV, url(s"https://github.com/VirtusLab/scala-cli/releases/download/v$cliV/scala-cli.jar"))
)
},
packResourceDir += (republishRepo.value / "bin" -> "bin"),
packResourceDir += (republishRepo.value / "maven2" -> "maven2"),
Compile / pack := (Compile / pack).dependsOn(republish).value,
)

lazy val dist = project.asDist(Bootstrapped)
.settings(
packResourceDir += (baseDirectory.value / "bin" -> "bin"),
packResourceDir += (republishRepo.value / "maven2" -> "maven2"),
packResourceDir += (republishRepo.value / "etc" -> "etc"),
packArchiveName := "scala3-" + dottyVersion,
republishBinDir := baseDirectory.value / "bin",
republishLaunchers +=
("scala-cli.jar" -> s"https://github.com/VirtusLab/scala-cli/releases/download/v$scalaCliLauncherVersion/scala-cli.jar")
)

lazy val `dist-mac-x64` = project.in(file("dist/mac-x64")).asDist(Bootstrapped)
.settings(
republishBinDir := (dist / republishBinDir).value,
packArchiveName := (dist / packArchiveName).value + "-x86_64-apple-darwin",
republishBinOverrides += (dist / baseDirectory).value / "bin-native-overrides",
republishLaunchers +=
("scala-cli" -> s"gz+https://github.com/VirtusLab/scala-cli/releases/download/v$scalaCliLauncherVersion/scala-cli-x86_64-apple-darwin.gz")
)

lazy val `dist-mac-aarch64` = project.in(file("dist/mac-aarch64")).asDist(Bootstrapped)
.settings(
republishBinDir := (dist / republishBinDir).value,
packArchiveName := (dist / packArchiveName).value + "-aarch64-apple-darwin",
republishBinOverrides += (dist / baseDirectory).value / "bin-native-overrides",
republishLaunchers +=
("scala-cli" -> s"gz+https://github.com/VirtusLab/scala-cli/releases/download/v$scalaCliLauncherVersion/scala-cli-aarch64-apple-darwin.gz")
)

lazy val `dist-win-x64` = project.in(file("dist/win-x64")).asDist(Bootstrapped)
.settings(
republishBinDir := (dist / republishBinDir).value,
packArchiveName := (dist / packArchiveName).value + "-x86_64-pc-win32",
republishBinOverrides += (dist / baseDirectory).value / "bin-native-overrides",
republishLaunchers +=
("scala-cli.exe" -> s"zip+https://github.com/VirtusLab/scala-cli/releases/download/v$scalaCliLauncherVersion/scala-cli-x86_64-pc-win32.zip!/scala-cli.exe")
)

lazy val `dist-linux-x64` = project.in(file("dist/linux-x64")).asDist(Bootstrapped)
.settings(
republishBinDir := (dist / republishBinDir).value,
packArchiveName := (dist / packArchiveName).value + "-x86_64-pc-linux",
republishBinOverrides += (dist / baseDirectory).value / "bin-native-overrides",
republishLaunchers +=
("scala-cli" -> s"gz+https://github.com/VirtusLab/scala-cli/releases/download/v$scalaCliLauncherVersion/scala-cli-x86_64-pc-linux.gz")
)

lazy val `dist-linux-aarch64` = project.in(file("dist/linux-aarch64")).asDist(Bootstrapped)
.settings(
republishBinDir := (dist / republishBinDir).value,
packArchiveName := (dist / packArchiveName).value + "-aarch64-pc-linux",
republishBinOverrides += (dist / baseDirectory).value / "bin-native-overrides",
republishLaunchers +=
("scala-cli" -> s"gz+https://github.com/VirtusLab/scala-cli/releases/download/v$scalaCliLauncherVersion/scala-cli-aarch64-pc-linux.gz")
)

private def customMimaReportBinaryIssues(issueFilterLocation: String) = mimaReportBinaryIssues := {
Expand Down

0 comments on commit 28995e1

Please sign in to comment.