Skip to content

Commit 585ec67

Browse files
authored
Merge pull request #2524 from dotty-staging/package
Fix #2516: Support Packaging and Distribution
2 parents b74fca1 + b8b6ee4 commit 585ec67

File tree

6 files changed

+280
-0
lines changed

6 files changed

+280
-0
lines changed

build.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ val `scala-library` = Build.`scala-library`
1818
val `scala-compiler` = Build.`scala-compiler`
1919
val `scala-reflect` = Build.`scala-reflect`
2020
val scalap = Build.scalap
21+
val dist = Build.dist
2122

2223
val `sbt-dotty` = Build.`sbt-dotty`
2324

dist/bin/common

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#!/usr/bin/env bash
2+
3+
#/*--------------------------------------------------------------------------
4+
# * Credits: This script is based on the script generated by sbt-pack.
5+
# *--------------------------------------------------------------------------*/
6+
7+
cygwin=false
8+
mingw=false
9+
darwin=false
10+
case "`uname`" in
11+
CYGWIN*) cygwin=true
12+
;;
13+
MINGW*) mingw=true
14+
;;
15+
Darwin*) darwin=true
16+
if [ -z "$JAVA_VERSION" ] ; then
17+
JAVA_VERSION="CurrentJDK"
18+
else
19+
echo "Using Java version: $JAVA_VERSION" 1>&2
20+
fi
21+
if [ -z "$JAVA_HOME" ] ; then
22+
JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/${JAVA_VERSION}/Home
23+
fi
24+
JAVA_OPTS="$JAVA_OPTS -Xdock:name=\"${PROG_NAME}\" -Xdock:icon=\"$PROG_HOME/icon-mac.png\" -Dapple.laf.useScreenMenuBar=true"
25+
JAVACMD="`which java`"
26+
;;
27+
esac
28+
29+
# Resolve JAVA_HOME from javac command path
30+
if [ -z "$JAVA_HOME" ]; then
31+
javaExecutable="`which javac`"
32+
if [ -n "$javaExecutable" -a -f "$javaExecutable" -a ! "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
33+
# readlink(1) is not available as standard on Solaris 10.
34+
readLink=`which readlink`
35+
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
36+
javaExecutable="`readlink -f \"$javaExecutable\"`"
37+
javaHome="`dirname \"$javaExecutable\"`"
38+
javaHome=`expr "$javaHome" : '\(.*\)/bin'`
39+
JAVA_HOME="$javaHome"
40+
export JAVA_HOME
41+
fi
42+
fi
43+
fi
44+
45+
46+
if [ -z "$JAVACMD" ] ; then
47+
if [ -n "$JAVA_HOME" ] ; then
48+
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
49+
# IBM's JDK on AIX uses strange locations for the executables
50+
JAVACMD="$JAVA_HOME/jre/sh/java"
51+
else
52+
JAVACMD="$JAVA_HOME/bin/java"
53+
fi
54+
else
55+
JAVACMD="`which java`"
56+
fi
57+
fi
58+
59+
if [ ! -x "$JAVACMD" ] ; then
60+
echo "Error: JAVA_HOME is not defined correctly."
61+
echo " We cannot execute $JAVACMD"
62+
exit 1
63+
fi
64+
65+
if [ -z "$JAVA_HOME" ] ; then
66+
echo "Warning: JAVA_HOME environment variable is not set."
67+
fi
68+
69+
CLASSPATH_SUFFIX=""
70+
# Path separator used in EXTRA_CLASSPATH
71+
PSEP=":"
72+
73+
# For Cygwin, switch paths to Windows-mixed format before running java
74+
if $cygwin; then
75+
[ -n "$PROG_HOME" ] &&
76+
PROG_HOME=`cygpath -am "$PROG_HOME"`
77+
[ -n "$JAVA_HOME" ] &&
78+
JAVA_HOME=`cygpath -am "$JAVA_HOME"`
79+
CLASSPATH_SUFFIX=";"
80+
PSEP=";"
81+
fi
82+
83+
# For Migwn, ensure paths are in UNIX format before anything is touched
84+
if $mingw ; then
85+
[ -n "$PROG_HOME" ] &&
86+
PROG_HOME="`(cd "$PROG_HOME"; pwd -W | sed 's|/|\\\\|g')`"
87+
[ -n "$JAVA_HOME" ] &&
88+
JAVA_HOME="`(cd "$JAVA_HOME"; pwd -W | sed 's|/|\\\\|g')`"
89+
CLASSPATH_SUFFIX=";"
90+
PSEP=";"
91+
fi
92+
93+
#/*--------------------------------------------------
94+
# * The code below is for Dotty
95+
# *-------------------------------------------------*/
96+
97+
for filename in $PROG_HOME/lib/*.jar; do
98+
[[ $filename =~ .*dotty-compiler.*.jar ]] && DOTTY_COMP=$filename
99+
[[ $filename =~ .*dotty-interfaces.*.jar ]] && DOTTY_INTF=$filename
100+
[[ $filename =~ .*dotty-library.*.jar ]] && DOTTY_LIB=$filename
101+
[[ $filename =~ .*scala-asm.*.jar ]] && SCALA_ASM=$filename
102+
[[ $filename =~ .*scala-library.*.jar ]] && SCALA_LIB=$filename
103+
[[ $filename =~ .*scala-xml.*.jar ]] && SCALA_XML=$filename
104+
[[ $filename =~ .*sbt-interface.*.jar ]] && SBT_INTF=$filename
105+
done

dist/bin/dotc

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#!/usr/bin/env bash
2+
3+
if [ -z "$PROG_HOME" ] ; then
4+
## resolve links - $0 may be a link to PROG_HOME
5+
PRG="$0"
6+
7+
# need this for relative symlinks
8+
while [ -h "$PRG" ] ; do
9+
ls=`ls -ld "$PRG"`
10+
link=`expr "$ls" : '.*-> \(.*\)$'`
11+
if expr "$link" : '/.*' > /dev/null; then
12+
PRG="$link"
13+
else
14+
PRG="`dirname "$PRG"`/$link"
15+
fi
16+
done
17+
18+
saveddir=`pwd`
19+
20+
PROG_HOME=`dirname "$PRG"`/..
21+
22+
# make it fully qualified
23+
PROG_HOME=`cd "$PROG_HOME" && pwd`
24+
25+
cd "$saveddir"
26+
fi
27+
28+
source "$PROG_HOME/bin/common"
29+
30+
default_java_opts="-Xmx768m -Xms768m"
31+
bootcp=true
32+
33+
CompilerMain=dotty.tools.dotc.Main
34+
FromTasty=dotty.tools.dotc.FromTasty
35+
ReplMain=dotty.tools.dotc.repl.Main
36+
37+
PROG_NAME=$CompilerMain
38+
39+
addJava () {
40+
java_args+=("$1")
41+
}
42+
addScala () {
43+
scala_args+=("$1")
44+
}
45+
addResidual () {
46+
residual_args+=("$1")
47+
}
48+
49+
classpathArgs () {
50+
# echo "dotty-compiler: $DOTTY_COMP"
51+
# echo "dotty-interface: $DOTTY_INTF"
52+
# echo "dotty-library: $DOTTY_LIB"
53+
# echo "scala-asm: $SCALA_ASM"
54+
# echo "scala-lib: $SCALA_LIB"
55+
# echo "scala-xml: $SCALA_XML"
56+
# echo "sbt-intface: $SBT_INTF"
57+
58+
toolchain=""
59+
toolchain+="$SCALA_LIB$PSEP"
60+
toolchain+="$DOTTY_LIB$PSEP"
61+
toolchain+="$SCALA_ASM$PSEP"
62+
toolchain+="$SBT_INTF$PSEP"
63+
toolchain+="$DOTTY_INTF$PSEP"
64+
toolchain+="$DOTTY_LIB$PSEP"
65+
toolchain+="$DOTTY_COMP"
66+
67+
if [[ -n "$bootcp" ]]; then
68+
jvm_cp_args="-Xbootclasspath/a:$toolchain"
69+
else
70+
jvm_cp_args="-classpath $toolchain"
71+
fi
72+
}
73+
74+
while [[ $# -gt 0 ]]; do
75+
case "$1" in
76+
--) shift; for arg; do addResidual "$arg"; done; set -- ;;
77+
-h|-help) help=true && shift ;;
78+
-v|-verbose) verbose=true && shift ;;
79+
-debug) debug=true && shift ;;
80+
-q|-quiet) quiet=true && shift ;;
81+
82+
# Optimize for short-running applications, see https://github.com/lampepfl/dotty/issues/222
83+
-Oshort) addJava "-XX:+TieredCompilation -XX:TieredStopAtLevel=1" && shift ;;
84+
-repl) PROG_NAME="$ReplMain" && shift ;;
85+
-tasty) PROG_NAME="$FromTasty" && shift ;;
86+
-compile) PROG_NAME="$CompilerMain" && shift ;;
87+
-run) PROG_NAME="$ReplMain" && shift ;;
88+
-bootcp) bootcp=true && shift ;;
89+
-nobootcp) unset bootcp && shift ;;
90+
-colors) colors=true && shift ;;
91+
-no-colors) unset colors && shift ;;
92+
93+
# break out -D and -J options and add them to JAVA_OPTS as well
94+
# so they reach the JVM in time to do some good. The -D options
95+
# will be available as system properties.
96+
-D*) addJava "$1" && addScala "$1" && shift ;;
97+
-J*) addJava "${1:2}" && addScala "$1" && shift ;;
98+
*) addResidual "$1" && shift ;;
99+
esac
100+
done
101+
102+
classpathArgs
103+
104+
eval exec "\"$JAVACMD\"" \
105+
${JAVA_OPTS:-$default_java_opts} \
106+
"${java_args[@]}" \
107+
"$jvm_cp_args" \
108+
-Dscala.usejavacp=true \
109+
"$PROG_NAME" \
110+
"${scala_args[@]}" \
111+
"${residual_args[@]}"
112+
exit $?

dist/bin/dotr

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env bash
2+
3+
# Try to autodetect real location of the script
4+
5+
if [ -z "$PROG_HOME" ] ; then
6+
## resolve links - $0 may be a link to PROG_HOME
7+
PRG="$0"
8+
9+
# need this for relative symlinks
10+
while [ -h "$PRG" ] ; do
11+
ls=`ls -ld "$PRG"`
12+
link=`expr "$ls" : '.*-> \(.*\)$'`
13+
if expr "$link" : '/.*' > /dev/null; then
14+
PRG="$link"
15+
else
16+
PRG="`dirname "$PRG"`/$link"
17+
fi
18+
done
19+
20+
saveddir=`pwd`
21+
22+
PROG_HOME=`dirname "$PRG"`/..
23+
24+
# make it fully qualified
25+
PROG_HOME=`cd "$PROG_HOME" && pwd`
26+
27+
cd "$saveddir"
28+
fi
29+
30+
source "$PROG_HOME/bin/common"
31+
32+
CLASS_PATH="-classpath .$PSEP$DOTTY_LIB$PSEP$SCALA_LIB"
33+
34+
first_arg="$1"
35+
36+
if [ -z "$1" ]; then
37+
echo "Starting dotty REPL..."
38+
eval "$PROG_HOME/bin/dotc -repl"
39+
elif [[ ${first_arg:0:1} == "-" ]]; then
40+
eval "$PROG_HOME/bin/dotc -repl $@"
41+
else
42+
eval exec "\"$JAVACMD\"" $CLASS_PATH $@
43+
fi

project/Build.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import java.util.Calendar
88

99
import scala.reflect.io.Path
1010
import sbtassembly.AssemblyKeys.assembly
11+
import xerial.sbt.Pack._
1112

1213
import org.scalajs.sbtplugin.ScalaJSPlugin
1314
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._
@@ -1052,4 +1053,20 @@ object DottyInjectedPlugin extends AutoPlugin {
10521053
}
10531054
state
10541055
}
1056+
1057+
lazy val dist = project.
1058+
dependsOn(`dotty-interfaces`).
1059+
dependsOn(`dotty-compiler`).
1060+
dependsOn(`dotty-library`).
1061+
settings(commonNonBootstrappedSettings).
1062+
settings(packSettings).
1063+
settings(
1064+
triggeredMessage in ThisBuild := Watched.clearWhenTriggered,
1065+
submoduleChecks,
1066+
publishArtifact := false,
1067+
// packMain := Map("dummy" -> "dotty.tools.dotc.Main"),
1068+
packExpandedClasspath := true,
1069+
packResourceDir += (baseDirectory.value / "bin" -> "bin"),
1070+
packArchiveName := "dotty-" + dottyVersion
1071+
)
10551072
}

project/plugins.sbt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.4")
1212
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "1.1")
1313

1414
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0")
15+
16+
addSbtPlugin("org.xerial.sbt" % "sbt-pack" % "0.8.2")

0 commit comments

Comments
 (0)