diff --git a/build.sbt b/build.sbt index cb8c4fe8df41..4a07c81babb6 100644 --- a/build.sbt +++ b/build.sbt @@ -18,6 +18,7 @@ val `scala-library` = Build.`scala-library` val `scala-compiler` = Build.`scala-compiler` val `scala-reflect` = Build.`scala-reflect` val scalap = Build.scalap +val dist = Build.dist val `sbt-dotty` = Build.`sbt-dotty` diff --git a/dist/bin/common b/dist/bin/common new file mode 100755 index 000000000000..9f764a0d8b4c --- /dev/null +++ b/dist/bin/common @@ -0,0 +1,105 @@ +#!/usr/bin/env bash + +#/*-------------------------------------------------------------------------- +# * Credits: This script is based on the script generated by sbt-pack. +# *--------------------------------------------------------------------------*/ + +cygwin=false +mingw=false +darwin=false +case "`uname`" in + CYGWIN*) cygwin=true + ;; + MINGW*) mingw=true + ;; + Darwin*) darwin=true + if [ -z "$JAVA_VERSION" ] ; then + JAVA_VERSION="CurrentJDK" + else + echo "Using Java version: $JAVA_VERSION" 1>&2 + fi + if [ -z "$JAVA_HOME" ] ; then + JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/${JAVA_VERSION}/Home + fi + JAVA_OPTS="$JAVA_OPTS -Xdock:name=\"${PROG_NAME}\" -Xdock:icon=\"$PROG_HOME/icon-mac.png\" -Dapple.laf.useScreenMenuBar=true" + JAVACMD="`which java`" + ;; +esac + +# 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 + +CLASSPATH_SUFFIX="" +# Path separator used in EXTRA_CLASSPATH +PSEP=":" + +# For Cygwin, switch paths to Windows-mixed format before running java +if $cygwin; then + [ -n "$PROG_HOME" ] && + PROG_HOME=`cygpath -am "$PROG_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath -am "$JAVA_HOME"` + CLASSPATH_SUFFIX=";" + PSEP=";" +fi + +# For Migwn, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$PROG_HOME" ] && + PROG_HOME="`(cd "$PROG_HOME"; pwd -W | sed 's|/|\\\\|g')`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd -W | sed 's|/|\\\\|g')`" + CLASSPATH_SUFFIX=";" + PSEP=";" +fi + +#/*-------------------------------------------------- +# * The code below is for Dotty +# *-------------------------------------------------*/ + +for filename in $PROG_HOME/lib/*.jar; do + [[ $filename =~ .*dotty-compiler.*.jar ]] && DOTTY_COMP=$filename + [[ $filename =~ .*dotty-interfaces.*.jar ]] && DOTTY_INTF=$filename + [[ $filename =~ .*dotty-library.*.jar ]] && DOTTY_LIB=$filename + [[ $filename =~ .*scala-asm.*.jar ]] && SCALA_ASM=$filename + [[ $filename =~ .*scala-library.*.jar ]] && SCALA_LIB=$filename + [[ $filename =~ .*scala-xml.*.jar ]] && SCALA_XML=$filename + [[ $filename =~ .*sbt-interface.*.jar ]] && SBT_INTF=$filename +done \ No newline at end of file diff --git a/dist/bin/dotc b/dist/bin/dotc new file mode 100755 index 000000000000..9772ff60b680 --- /dev/null +++ b/dist/bin/dotc @@ -0,0 +1,112 @@ +#!/usr/bin/env bash + +if [ -z "$PROG_HOME" ] ; then + ## resolve links - $0 may be a link to PROG_HOME + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + PROG_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + PROG_HOME=`cd "$PROG_HOME" && pwd` + + cd "$saveddir" +fi + +source "$PROG_HOME/bin/common" + +default_java_opts="-Xmx768m -Xms768m" +bootcp=true + +CompilerMain=dotty.tools.dotc.Main +FromTasty=dotty.tools.dotc.FromTasty +ReplMain=dotty.tools.dotc.repl.Main + +PROG_NAME=$CompilerMain + +addJava () { + java_args+=("$1") +} +addScala () { + scala_args+=("$1") +} +addResidual () { + residual_args+=("$1") +} + +classpathArgs () { + # echo "dotty-compiler: $DOTTY_COMP" + # echo "dotty-interface: $DOTTY_INTF" + # echo "dotty-library: $DOTTY_LIB" + # echo "scala-asm: $SCALA_ASM" + # echo "scala-lib: $SCALA_LIB" + # echo "scala-xml: $SCALA_XML" + # echo "sbt-intface: $SBT_INTF" + + toolchain="" + toolchain+="$SCALA_LIB$PSEP" + toolchain+="$DOTTY_LIB$PSEP" + toolchain+="$SCALA_ASM$PSEP" + toolchain+="$SBT_INTF$PSEP" + toolchain+="$DOTTY_INTF$PSEP" + toolchain+="$DOTTY_LIB$PSEP" + toolchain+="$DOTTY_COMP" + + if [[ -n "$bootcp" ]]; then + jvm_cp_args="-Xbootclasspath/a:$toolchain" + else + jvm_cp_args="-classpath $toolchain" + fi +} + +while [[ $# -gt 0 ]]; do +case "$1" in + --) shift; for arg; do addResidual "$arg"; done; set -- ;; + -h|-help) help=true && shift ;; + -v|-verbose) verbose=true && shift ;; + -debug) debug=true && shift ;; + -q|-quiet) quiet=true && shift ;; + + # Optimize for short-running applications, see https://github.com/lampepfl/dotty/issues/222 + -Oshort) addJava "-XX:+TieredCompilation -XX:TieredStopAtLevel=1" && shift ;; + -repl) PROG_NAME="$ReplMain" && shift ;; + -tasty) PROG_NAME="$FromTasty" && shift ;; + -compile) PROG_NAME="$CompilerMain" && shift ;; + -run) PROG_NAME="$ReplMain" && shift ;; + -bootcp) bootcp=true && shift ;; + -nobootcp) unset bootcp && shift ;; + -colors) colors=true && shift ;; + -no-colors) unset colors && shift ;; + + # break out -D and -J options and add them to JAVA_OPTS as well + # so they reach the JVM in time to do some good. The -D options + # will be available as system properties. + -D*) addJava "$1" && addScala "$1" && shift ;; + -J*) addJava "${1:2}" && addScala "$1" && shift ;; + *) addResidual "$1" && shift ;; + esac +done + +classpathArgs + +eval exec "\"$JAVACMD\"" \ + ${JAVA_OPTS:-$default_java_opts} \ + "${java_args[@]}" \ + "$jvm_cp_args" \ + -Dscala.usejavacp=true \ + "$PROG_NAME" \ + "${scala_args[@]}" \ + "${residual_args[@]}" +exit $? diff --git a/dist/bin/dotr b/dist/bin/dotr new file mode 100755 index 000000000000..0c387e823c83 --- /dev/null +++ b/dist/bin/dotr @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +# Try to autodetect real location of the script + +if [ -z "$PROG_HOME" ] ; then + ## resolve links - $0 may be a link to PROG_HOME + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + PROG_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + PROG_HOME=`cd "$PROG_HOME" && pwd` + + cd "$saveddir" +fi + +source "$PROG_HOME/bin/common" + +CLASS_PATH="-classpath .$PSEP$DOTTY_LIB$PSEP$SCALA_LIB" + +first_arg="$1" + +if [ -z "$1" ]; then + echo "Starting dotty REPL..." + eval "$PROG_HOME/bin/dotc -repl" +elif [[ ${first_arg:0:1} == "-" ]]; then + eval "$PROG_HOME/bin/dotc -repl $@" +else + eval exec "\"$JAVACMD\"" $CLASS_PATH $@ +fi diff --git a/project/Build.scala b/project/Build.scala index c8785c5ed34d..cae2515d9e3d 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -8,6 +8,7 @@ import java.util.Calendar import scala.reflect.io.Path import sbtassembly.AssemblyKeys.assembly +import xerial.sbt.Pack._ import org.scalajs.sbtplugin.ScalaJSPlugin import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._ @@ -1052,4 +1053,20 @@ object DottyInjectedPlugin extends AutoPlugin { } state } + + lazy val dist = project. + dependsOn(`dotty-interfaces`). + dependsOn(`dotty-compiler`). + dependsOn(`dotty-library`). + settings(commonNonBootstrappedSettings). + settings(packSettings). + settings( + triggeredMessage in ThisBuild := Watched.clearWhenTriggered, + submoduleChecks, + publishArtifact := false, + // packMain := Map("dummy" -> "dotty.tools.dotc.Main"), + packExpandedClasspath := true, + packResourceDir += (baseDirectory.value / "bin" -> "bin"), + packArchiveName := "dotty-" + dottyVersion + ) } diff --git a/project/plugins.sbt b/project/plugins.sbt index 2478a7773fb4..12881ebf2343 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -12,3 +12,5 @@ addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.4") addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "1.1") addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0") + +addSbtPlugin("org.xerial.sbt" % "sbt-pack" % "0.8.2")