Skip to content

Fix #2516: Support Packaging and Distribution #2524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
105 changes: 105 additions & 0 deletions dist/bin/common
Original file line number Diff line number Diff line change
@@ -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
112 changes: 112 additions & 0 deletions dist/bin/dotc
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/usr/bin/env bash

if [ -z "$PROG_HOME" ] ; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot of copy paste and re-implementation for the current bin/dotc script.
I propose we merge the two, otherwise it will be hard to maintain and we'll be using different scripts from the ones our users do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DarkDimius I agree there's a potential to merge the two. But I think we can delay the merge after the Copenhagen release -- as the bin/dotc and bin/dotr have something special to the development of the compiler, such as switch between bootstrap and unbootstrap versions. We can make the decision later.

## 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 $?
43 changes: 43 additions & 0 deletions dist/bin/dotr
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash

# Try to autodetect real location of the script

if [ -z "$PROG_HOME" ] ; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here.

## 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
17 changes: 17 additions & 0 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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._
Expand Down Expand Up @@ -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
)
}
2 changes: 2 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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")