From d3182f1b4ca383f7898ca4ab7da30b9e5b78e054 Mon Sep 17 00:00:00 2001 From: liu fengyun Date: Wed, 24 May 2017 14:49:10 +0200 Subject: [PATCH 1/6] add packing and dotc/dotr --- build.sbt | 1 + dist/bin/common | 105 +++++++++++++++++++++++++++++++++++++++ dist/bin/dotc | 116 ++++++++++++++++++++++++++++++++++++++++++++ dist/bin/dotr | 43 ++++++++++++++++ project/Build.scala | 17 +++++++ project/plugins.sbt | 2 + 6 files changed, 284 insertions(+) create mode 100755 dist/bin/common create mode 100755 dist/bin/dotc create mode 100755 dist/bin/dotr 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..dd6866279335 --- /dev/null +++ b/dist/bin/dotc @@ -0,0 +1,116 @@ +#!/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 ;; + -jrebel) jrebel=true && shift ;; + -no-jrebel) unset jrebel && shift ;; + + -toolcp) require_arg classpath "$1" "$2" && toolcp="$2" && shift 2 ;; + + # 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..fd05800f3092 --- /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 .:$DOTTY_LIB:$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..c6948362e2c6 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. + aggregate(`dotty-interfaces`, `dotty-library`, `dotty-compiler`). + 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") From dd9a47392eb676954c2d2634608fd552607f6b98 Mon Sep 17 00:00:00 2001 From: liu fengyun Date: Wed, 24 May 2017 14:49:21 +0200 Subject: [PATCH 2/6] add brew script for install on Mac --- dist/dotty.rb | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 dist/dotty.rb diff --git a/dist/dotty.rb b/dist/dotty.rb new file mode 100644 index 000000000000..ac937acfcebc --- /dev/null +++ b/dist/dotty.rb @@ -0,0 +1,32 @@ +class Dotty < Formula + desc "Experimental Scala Compiler" + homepage "http://dotty.epfl.ch/" + url "http://dotty.epfl.ch/dotty/dotty-0.1.1-bin-SNAPSHOT.tar.gz" + sha256 "4e1bda148754543844d25290a87076e6bfb0b6b0275535f97c1871e0fc5c2c4c" + # mirror "https://downloads.typesafe.com/scala/2.12.2/scala-2.12.2.tgz" + # mirror "https://www.scala-lang.org/files/archive/scala-2.12.2.tgz" + + bottle :unneeded + + depends_on :java => "1.8+" + + def install + rm_f Dir["bin/*.bat"] + prefix.install "bin", "lib" + end + + test do + file = testpath/"Test.scala" + file.write <<-EOS.undent + object Test { + def main(args: Array[String]) { + println(s"${2 + 2}") + } + } + EOS + + out = shell_output("#{bin}/dotr #{file}").strip + + assert_equal "4", out + end +end From dc2f5584fa0b468a87750091754106329829c4d4 Mon Sep 17 00:00:00 2001 From: liu fengyun Date: Wed, 24 May 2017 15:20:07 +0200 Subject: [PATCH 3/6] fix separation in dotr --- dist/bin/dotr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/bin/dotr b/dist/bin/dotr index fd05800f3092..0c387e823c83 100755 --- a/dist/bin/dotr +++ b/dist/bin/dotr @@ -29,7 +29,7 @@ fi source "$PROG_HOME/bin/common" -CLASS_PATH="-classpath .:$DOTTY_LIB:$SCALA_LIB" +CLASS_PATH="-classpath .$PSEP$DOTTY_LIB$PSEP$SCALA_LIB" first_arg="$1" From 0dda9e15a24abc00e7937fd104f9158178d34fdb Mon Sep 17 00:00:00 2001 From: liu fengyun Date: Wed, 24 May 2017 15:24:56 +0200 Subject: [PATCH 4/6] move brew formula to lampepfl/homebrew-dotty --- dist/dotty.rb | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100644 dist/dotty.rb diff --git a/dist/dotty.rb b/dist/dotty.rb deleted file mode 100644 index ac937acfcebc..000000000000 --- a/dist/dotty.rb +++ /dev/null @@ -1,32 +0,0 @@ -class Dotty < Formula - desc "Experimental Scala Compiler" - homepage "http://dotty.epfl.ch/" - url "http://dotty.epfl.ch/dotty/dotty-0.1.1-bin-SNAPSHOT.tar.gz" - sha256 "4e1bda148754543844d25290a87076e6bfb0b6b0275535f97c1871e0fc5c2c4c" - # mirror "https://downloads.typesafe.com/scala/2.12.2/scala-2.12.2.tgz" - # mirror "https://www.scala-lang.org/files/archive/scala-2.12.2.tgz" - - bottle :unneeded - - depends_on :java => "1.8+" - - def install - rm_f Dir["bin/*.bat"] - prefix.install "bin", "lib" - end - - test do - file = testpath/"Test.scala" - file.write <<-EOS.undent - object Test { - def main(args: Array[String]) { - println(s"${2 + 2}") - } - } - EOS - - out = shell_output("#{bin}/dotr #{file}").strip - - assert_equal "4", out - end -end From c09e87e569b36d443d57e379fb09bb5c44193872 Mon Sep 17 00:00:00 2001 From: liu fengyun Date: Wed, 24 May 2017 18:08:42 +0200 Subject: [PATCH 5/6] refine sbt task for dist --- project/Build.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/Build.scala b/project/Build.scala index c6948362e2c6..cae2515d9e3d 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -1055,7 +1055,7 @@ object DottyInjectedPlugin extends AutoPlugin { } lazy val dist = project. - aggregate(`dotty-interfaces`, `dotty-library`, `dotty-compiler`). + dependsOn(`dotty-interfaces`). dependsOn(`dotty-compiler`). dependsOn(`dotty-library`). settings(commonNonBootstrappedSettings). From b8b6ee4a224d8a9da216f02ddd0ecb623f710d87 Mon Sep 17 00:00:00 2001 From: liu fengyun Date: Fri, 26 May 2017 09:58:05 +0200 Subject: [PATCH 6/6] remove unsupported options --- dist/bin/dotc | 4 ---- 1 file changed, 4 deletions(-) diff --git a/dist/bin/dotc b/dist/bin/dotc index dd6866279335..9772ff60b680 100755 --- a/dist/bin/dotc +++ b/dist/bin/dotc @@ -89,10 +89,6 @@ case "$1" in -nobootcp) unset bootcp && shift ;; -colors) colors=true && shift ;; -no-colors) unset colors && shift ;; - -jrebel) jrebel=true && shift ;; - -no-jrebel) unset jrebel && shift ;; - - -toolcp) require_arg classpath "$1" "$2" && toolcp="$2" && shift 2 ;; # 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