From 488cd7a81a9700b9d04805cf60f66d53a3a86084 Mon Sep 17 00:00:00 2001 From: Felix Mulder Date: Mon, 20 Jun 2016 14:17:39 +0200 Subject: [PATCH 1/6] Rework dotc to choose correct packages fixing #1321 New algorithm similar to proposal by @DarkDimius: 1. Bash script checks for existance of `$DOTTY_ROOT/.packages`, if not found - rebuilds all packages and places their full paths in the `.packages` file in the following order: - dotty-interfaces - dotty - dotty-tests 2. Checks if there are any files newer than those contained within `.packages` and if so - rebuilds that package 3. Runs Java with correct classpath setup --- .gitignore | 3 ++ bin/dotc | 118 ++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 83 insertions(+), 38 deletions(-) diff --git a/.gitignore b/.gitignore index ce4e4a44058a..c9f12e98668f 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,6 @@ scala-scala # Ignore output files but keep the directory out/ !out/.keep + +# Ignore build-file +.packages diff --git a/bin/dotc b/bin/dotc index 128b42c4b4e7..dcbe358d4636 100755 --- a/bin/dotc +++ b/bin/dotc @@ -21,7 +21,6 @@ function getLastStringOnLineWith { SCALA_VERSION=$(getLastStringOnLineWith "scalaVersion in") SCALA_BINARY_VERSION=2.11 SCALA_COMPILER_VERSION=$(getLastStringOnLineWith "scala-compiler") -DOTTY_VERSION=$(getLastStringOnLineWith "version in") JLINE_VERSION=$(getLastStringOnLineWith "jline") SBT_VERSION=$(grep "sbt.version=" "$DOTTY_ROOT/project/build.properties" | sed 's/sbt.version=//') bootcp=true @@ -31,54 +30,97 @@ programName=$(basename "$0") # uncomment next line to enable debug output #debug=true - - declare -a java_args scala_args residual_args unset verbose quiet cygwin toolcp colors saved_stty CDPATH +function build_jar { + # Usage: + # build_jar package path/to/jar/dir ['/some/sed/command'] + # + # Last arg is optional + cd $DOTTY_ROOT >& /dev/null + local build_output=$(sbt "$1") + local jar=$(echo $build_output | sed -n 's/.*Packaging //g; s/ \.\.\..*//g; /^\/.*/p') + + local sedjar="$3" + if [ "$sedjar" == "" ]; then + sedjar="/.*\.jar/p" + fi -CompilerMain=dotty.tools.dotc.Main -FromTasty=dotty.tools.dotc.FromTasty -ReplMain=dotty.tools.dotc.repl.Main + if [ "$jar" == "" ]; then + # Didn't build a jar - could've run sbt by oneself, get latest jar in target: + jar="$DOTTY_ROOT/$2/$(ls -1t "$2" | sed -n "$sedjar" | awk 'NR==1')" + fi + cd - >& /dev/null + echo $jar +} -# autodetecting the compiler jars. this is the location where sbt 'packages' them -INTERFACES_JAR=$DOTTY_ROOT/interfaces/target/dotty-interfaces-$DOTTY_VERSION.jar -MAIN_JAR=$DOTTY_ROOT/target/scala-$SCALA_BINARY_VERSION/dotty_$SCALA_BINARY_VERSION-$DOTTY_VERSION.jar -TEST_JAR=$DOTTY_ROOT/target/scala-$SCALA_BINARY_VERSION/dotty_$SCALA_BINARY_VERSION-$DOTTY_VERSION-tests.jar -DOTTY_JAR=$DOTTY_ROOT/dotty.jar +function update_packages { + echo "$INTERFACES_JAR" > $DOTTY_ROOT/.packages + echo "$MAIN_JAR" >> $DOTTY_ROOT/.packages + echo "$TEST_JAR" >> $DOTTY_ROOT/.packages +} + +function build_all { + echo "The script is going to build the required jar files" + + printf "Building dotty-interfaces..." + INTERFACES_JAR=$(build_jar dotty-interfaces/package interfaces/target) + printf "done\n" + + printf "Building dotty..." + MAIN_JAR=$(build_jar package target/scala-2.11) + printf "done\n" + + printf "Building tests..." + TEST_JAR=$(build_jar test:package target/scala-2.11 '/dotty.*-tests\.jar/p') + printf "done\n" -function checkjar { - if [ ! -f "$1" ] - then - echo "The script is going to build the required jar file $1 by running \"sbt $2\"" - cd $DOTTY_ROOT - sbt "$2" - cd - - if [ ! -f "$1" ] - then - echo "The required jar file has not been built by sbt. Please run \"sbt $2\"" - exit 1 + update_packages +} + + +# Check if .packages file does not exist - if so assume old build and rebuild all +if [ ! -f "$DOTTY_ROOT/.packages" ]; then + build_all +else + IFS=$'\r\n' GLOBIGNORE='*' command eval 'JARS=($(cat $DOTTY_ROOT/.packages))' + + if [ "${#JARS[@]}" == "3" ]; then + INTERFACES_JAR="${JARS[0]}" + MAIN_JAR="${JARS[1]}" + TEST_JAR="${JARS[2]}" else - echo "The required jar file was built successfully." + echo "Corrupted .packages file" + build_all fi - else - NEW_FILES="$(find "$DOTTY_ROOT/$3" \( -iname "*.scala" -o -iname "*.java" \) -newer "$1")" - if [ ! -z "$NEW_FILES" ]; - then - echo "new files detected. rebuilding" - cd $DOTTY_ROOT - sbt "$2" - touch "$1" - cd - +fi + +################# After this point, jar variables will be set ################# +function check_jar { + # Usage: + # check_jar "name" "path/to/package.jar" "sources/dir" 'lambda to exec on failure' + local new_files="$(find "$3" \( -iname "*.scala" -o -iname "*.java" \) -newer "$2")" + if [ ! -z "$new_files" ]; then + printf "New files detected in $1, rebuilding..." + eval "$4" + printf "done\n" + update_packages fi - fi } -checkjar $INTERFACES_JAR dotty-interfaces/package interfaces -checkjar $MAIN_JAR package src -checkjar $TEST_JAR test:package test +check_jar "dotty-interfaces" $INTERFACES_JAR "interfaces" 'INTERFACES_JAR=$(build_jar dotty-interfaces/package interfaces/target)' +check_jar "dotty" $MAIN_JAR "src" 'MAIN_JAR=$(build_jar package target/scala-2.11)' +check_jar "dotty-tests" $TEST_JAR "test" 'TEST_JAR=$(build_jar test:package target/scala-2.11 /dotty.*-tests\.jar/p)' + +# dotc.build test places bootstrapped jar here +DOTTY_JAR=$DOTTY_ROOT/dotty.jar + +CompilerMain=dotty.tools.dotc.Main +FromTasty=dotty.tools.dotc.FromTasty +ReplMain=dotty.tools.dotc.repl.Main # Autodetecting the scala-library location, in case it wasn't provided by an environment variable if [ "$SCALA_LIBRARY_JAR" == "" ] @@ -201,8 +243,8 @@ trap onExit INT # If using the boot classpath, also pass an empty classpath # to java to suppress "." from materializing. classpathArgs () { - if [[ "true" == $bootstrapped ]]; then - checkjar $DOTTY_JAR "test:runMain dotc.build" src + if [[ "true" == $bootstrapped ]]; then + check_jar "dotty-bootstrapped" $DOTTY_JAR "target" 'build_jar "test:runMain dotc.build" target' &> /dev/null toolchain="$DOTTY_JAR:$SCALA_LIBRARY_JAR:$SCALA_REFLECT_JAR:$SCALA_COMPILER_JAR:$JLINE_JAR:$SBT_INTERFACE_JAR" else toolchain="$SCALA_LIBRARY_JAR:$SCALA_REFLECT_JAR:$SCALA_COMPILER_JAR:$JLINE_JAR:$SBT_INTERFACE_JAR" From 81034c52f8f1b227c55d8ae998963ad534073501 Mon Sep 17 00:00:00 2001 From: Felix Mulder Date: Tue, 21 Jun 2016 10:16:48 +0200 Subject: [PATCH 2/6] Fix #1323: change sbt interface dependency to allow artifact resolution by coursier --- bin/dotc | 41 ++++++++++++++++++++++++----------------- project/Build.scala | 5 ++--- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/bin/dotc b/bin/dotc index dcbe358d4636..d64755ec02b3 100755 --- a/bin/dotc +++ b/bin/dotc @@ -122,30 +122,37 @@ CompilerMain=dotty.tools.dotc.Main FromTasty=dotty.tools.dotc.FromTasty ReplMain=dotty.tools.dotc.repl.Main +function find_jar { + # Usage: + # find_jar path/to/location file.jar + local artifact="$1/$2" + + if [ ! -f "$artifact" ]; then + artifact=$(find "$HOME/.coursier/cache" -iname "$2") + fi + + echo "$artifact" +} + # Autodetecting the scala-library location, in case it wasn't provided by an environment variable -if [ "$SCALA_LIBRARY_JAR" == "" ] -then - SCALA_LIBRARY_JAR=$HOME/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-$SCALA_VERSION.jar - # this is location where sbt stores it in ivy cache +if [ "$SCALA_LIBRARY_JAR" == "" ]; then + SCALA_LIBRARY_JAR=$(find_jar "$HOME/.ivy2/cache/org.scala-lang/scala-library/jars" "scala-library-$SCALA_VERSION.jar") fi -# save as for scala-library now for scala-reflect -if [ "$SCALA_REFLECT_JAR" == "" ] -then - SCALA_REFLECT_JAR=$HOME/.ivy2/cache/org.scala-lang/scala-reflect/jars/scala-reflect-$SCALA_VERSION.jar + +if [ "$SCALA_REFLECT_JAR" == "" ]; then + SCALA_REFLECT_JAR=$(find_jar "$HOME/.ivy2/cache/org.scala-lang/scala-reflect/jars" "scala-reflect-$SCALA_VERSION.jar") fi -if [ "$SCALA_COMPILER_JAR" == "" ] -then - SCALA_COMPILER_JAR=$HOME/.ivy2/cache/me.d-d/scala-compiler/jars/scala-compiler-$SCALA_COMPILER_VERSION.jar + +if [ "$SCALA_COMPILER_JAR" == "" ]; then + SCALA_COMPILER_JAR=$(find_jar "$HOME/.ivy2/cache/me.d-d/scala-compiler/jars" "scala-compiler-$SCALA_COMPILER_VERSION.jar") fi -if [ "$JLINE_JAR" == "" ] -then - JLINE_JAR=$HOME/.ivy2/cache/jline/jline/jars/jline-$JLINE_VERSION.jar +if [ "$JLINE_JAR" == "" ]; then + JLINE_JAR=$(find_jar "$HOME/.ivy2/cache/jline/jline/jars" "jline-$JLINE_VERSION.jar") fi -if [ "$SBT_INTERFACE_JAR" == "" ] -then - SBT_INTERFACE_JAR=$HOME/.ivy2/cache/org.scala-sbt/interface/jars/interface-$SBT_VERSION.jar +if [ "$SBT_INTERFACE_JAR" == "" ]; then + SBT_INTERFACE_JAR=$(find_jar "$HOME/.ivy2/cache/org.scala-sbt/interface/jars" "interface-$SBT_VERSION.jar") fi if [ ! -f "$SCALA_LIBRARY_JAR" -o ! -f "$SCALA_REFLECT_JAR" -o ! -f "$SCALA_COMPILER_JAR" -o ! -f "$JLINE_JAR" -o ! -f "$SBT_INTERFACE_JAR" ] diff --git a/project/Build.scala b/project/Build.scala index fc452f7f66ac..ecb0668bdd0a 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -93,8 +93,7 @@ object DottyBuild extends Build { "org.scala-lang.modules" %% "scala-partest" % "1.0.11" % "test", "com.novocode" % "junit-interface" % "0.11" % "test", "jline" % "jline" % "2.12", - "org.scala-sbt" % "interface" % sbtVersion.value), - + "com.typesafe.sbt" % "sbt-interface" % sbtVersion.value), // enable improved incremental compilation algorithm incOptions := incOptions.value.withNameHashing(true), @@ -205,7 +204,7 @@ object DottyBuild extends Build { description := "sbt compiler bridge for Dotty", resolvers += Resolver.typesafeIvyRepo("releases"), libraryDependencies ++= Seq( - "org.scala-sbt" % "interface" % sbtVersion.value, + "com.typesafe.sbt" % "sbt-interface" % sbtVersion.value, "org.scala-sbt" % "api" % sbtVersion.value % "test", "org.specs2" %% "specs2" % "2.3.11" % "test" ), From 0a8020bbe3cbe145b86945ac13ee7d376ef110f5 Mon Sep 17 00:00:00 2001 From: Felix Mulder Date: Tue, 21 Jun 2016 14:33:29 +0200 Subject: [PATCH 3/6] Add tests fixing #1322 --- test/scripts/TestDotc.scala | 89 +++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 test/scripts/TestDotc.scala diff --git a/test/scripts/TestDotc.scala b/test/scripts/TestDotc.scala new file mode 100644 index 000000000000..f662a269501d --- /dev/null +++ b/test/scripts/TestDotc.scala @@ -0,0 +1,89 @@ +package test + +import org.junit.Assert._ +import org.junit.{Before, After, Test} + +import scala.io.Source +import scala.sys.process.{Process, ProcessLogger} +import java.io.{File => JFile, FileNotFoundException} + +class TestDotc { + private val lineSep = util.Properties.lineSeparator + private def doUnlessWindows(op: => Unit) = + if (!System.getProperty("os.name").toLowerCase.contains("windows")) + op + else + Console.err.println("[warn] Could not perform test, windows batch-scripts not available") + + private def executeScript(script: String): (Int, String) = { + val sb = new StringBuilder + val ret = Process(script) ! ProcessLogger(sb append _) + (ret, sb.toString) + } + + private def deletePackages: Unit = { + def delete(path: String) = { + val file = new JFile(path) + if (file.exists) file.delete() + } + + try { + for (jar <- Source.fromFile(".packages").getLines()) + delete(jar) + + delete(".packages") + delete("src/dotty/tools/dotc/Dummy.scala") + } catch { + case _: FileNotFoundException => () + } + } + + @Before def buildUp = deletePackages + @After def tearDown = deletePackages + + /** bin/dotc script should be able to build hello world and successfully + * execute it using dotr + */ + @Test def buildAndRunHelloWorld = doUnlessWindows { + val (retDotc, dotcOutput) = executeScript("bin/dotc tests/pos/HelloWorld.scala") + + // Check correct output of building and running dotc + assert( + retDotc == 0, + s"bin/dotc script did not run properly. Output:$lineSep$dotcOutput" + ) + + val (retDotr, dotrOutput) = executeScript("bin/dotr HelloWorld") + assert( + retDotr == 0 && dotrOutput == "hello world", + s"Running hello world exited with status: $retDotr and output: $dotrOutput" + ) + } + + /** bin/dotc script should be able to detect changes in dotty sources and + * rebuild dotty if needed + */ + @Test def rebuildIfNecessary = doUnlessWindows { + val (retFirstBuild, _) = executeScript("bin/dotc tests/pos/HelloWorld.scala") + assert(retFirstBuild == 0, "building dotc failed") + + // Create a new file + new JFile("src/dotty/tools/dotc/Dummy.scala").createNewFile() + + val (retSecondBuild, output) = executeScript("bin/dotc tests/pos/HelloWorld.scala") + assert( + retSecondBuild == 0 && output.contains("rebuilding"), + s"Rebuilding the tool should result in jar files being rebuilt. Status: $retSecondBuild, output:$lineSep$output") + } + + /** if no changes to dotty, dotc script should be fast */ + @Test def beFastOnNoChanges = doUnlessWindows { + val (retFirstBuild, _) = executeScript("bin/dotc tests/pos/HelloWorld.scala") + assert(retFirstBuild == 0, "building dotc failed") + + val (ret, output) = executeScript("bin/dotc tests/pos/HelloWorld.scala") + assert( + ret == 0 && !output.contains("rebuilding"), + s"Project recompiled when it didn't need to be. Status $ret, output:$lineSep$output") + } +} From 156066d4aa03619c58a3197550cf998c5b67343a Mon Sep 17 00:00:00 2001 From: Felix Mulder Date: Tue, 21 Jun 2016 19:49:20 +0200 Subject: [PATCH 4/6] Remove call to `scala` in dotr --- bin/dotr | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/bin/dotr b/bin/dotr index ee113b7060fc..f1da6c8eab26 100755 --- a/bin/dotr +++ b/bin/dotr @@ -7,12 +7,40 @@ if [[ "$DOTTY_ROOT" == "" ]]; then fi DOTTY_ROOT="$(dirname "$DOTTY_ROOT")" DOTTY_ROOT="$( cd "$DOTTY_ROOT" >& /dev/null && pwd )/.." # absolute +SCALA_VERSION=$(grep "scalaVersion in" "$DOTTY_ROOT/project/Build.scala"|sed -n 's/.*\"\(.*\)\".*/\1/'p) -# CLASS_PATH is derived from the DOTTY_ROOT -CLASS_PATH="-J-Xbootclasspath/a:.:$DOTTY_ROOT/target/scala-2.11/classes/" +function find_jar { + # Usage: + # find_jar path/to/location file.jar + local artifact="$1/$2" + + if [ ! -f "$artifact" ]; then + artifact=$(find "$HOME/.coursier/cache" -iname "$2") + fi + + echo "$artifact" +} + +# Autodetecting the scala-library location, in case it wasn't provided by an environment variable +if [ "$SCALA_LIBRARY_JAR" == "" ]; then + SCALA_LIBRARY_JAR=$(find_jar "$HOME/.ivy2/cache/org.scala-lang/scala-library/jars" "scala-library-$SCALA_VERSION.jar") +fi + +# CLASS_PATH is derived from the DOTTY_ROOT and SCALA_LIBRARY_JAR +CLASS_PATH="-Xbootclasspath/a:.:$DOTTY_ROOT/target/scala-2.11/classes/:.:$SCALA_LIBRARY_JAR" function runMain { - scala $CLASS_PATH $@ + local jbin=$(which "java") + + if [ ! -z "$JAVA_BIN" ]; then + jbin=$JAVA_BIN + fi + + if [ "$jbin" == "" ]; then + echo "java bin not detected - please specify with \$JAVA_BIN or install java to a default location" + else + eval "$jbin $CLASS_PATH $@" + fi } if [ -z "$1" ]; then From 574681ebf468642ce55a6aa06c66daee6b8d3742 Mon Sep 17 00:00:00 2001 From: Felix Mulder Date: Tue, 21 Jun 2016 20:02:42 +0200 Subject: [PATCH 5/6] Extract common variables to common script in bin dir --- bin/common | 138 +++++++++++++++++++++++++++++++++++++++++++++++++++++ bin/dotc | 138 +---------------------------------------------------- bin/dotr | 19 +------- 3 files changed, 141 insertions(+), 154 deletions(-) create mode 100755 bin/common diff --git a/bin/common b/bin/common new file mode 100755 index 000000000000..150e79016099 --- /dev/null +++ b/bin/common @@ -0,0 +1,138 @@ +#!/bin/bash + +# Finds in dotty build file a line containing PATTERN +# returns last "" escaped string in this line +function getLastStringOnLineWith { + PATTERN="$1" + grep "$PATTERN" "$DOTTY_ROOT/project/Build.scala"|sed -n 's/.*\"\(.*\)\".*/\1/'p +} + +# Configuration +SCALA_VERSION=$(getLastStringOnLineWith "scalaVersion in") +SCALA_BINARY_VERSION=2.11 +SCALA_COMPILER_VERSION=$(getLastStringOnLineWith "scala-compiler") +JLINE_VERSION=$(getLastStringOnLineWith "jline") +SBT_VERSION=$(grep "sbt.version=" "$DOTTY_ROOT/project/build.properties" | sed 's/sbt.version=//') +bootcp=true +bootstrapped=false +default_java_opts="-Xmx768m -Xms768m" +programName=$(basename "$0") +# uncomment next line to enable debug output +#debug=true + +declare -a java_args scala_args residual_args +unset verbose quiet cygwin toolcp colors saved_stty CDPATH + +function find_jar { + # Usage: + # find_jar path/to/location file.jar + local artifact="$1/$2" + + if [ ! -f "$artifact" ]; then + artifact=$(find "$HOME/.coursier/cache" -iname "$2") + fi + + echo "$artifact" +} + +# Autodetecting the scala-library location, in case it wasn't provided by an environment variable +if [ "$SCALA_LIBRARY_JAR" == "" ]; then + SCALA_LIBRARY_JAR=$(find_jar "$HOME/.ivy2/cache/org.scala-lang/scala-library/jars" "scala-library-$SCALA_VERSION.jar") +fi + +if [ "$SCALA_REFLECT_JAR" == "" ]; then + SCALA_REFLECT_JAR=$(find_jar "$HOME/.ivy2/cache/org.scala-lang/scala-reflect/jars" "scala-reflect-$SCALA_VERSION.jar") +fi + +if [ "$SCALA_COMPILER_JAR" == "" ]; then + SCALA_COMPILER_JAR=$(find_jar "$HOME/.ivy2/cache/me.d-d/scala-compiler/jars" "scala-compiler-$SCALA_COMPILER_VERSION.jar") +fi + +if [ "$JLINE_JAR" == "" ]; then + JLINE_JAR=$(find_jar "$HOME/.ivy2/cache/jline/jline/jars" "jline-$JLINE_VERSION.jar") +fi + +if [ "$SBT_INTERFACE_JAR" == "" ]; then + SBT_INTERFACE_JAR=$(find_jar "$HOME/.ivy2/cache/org.scala-sbt/interface/jars" "interface-$SBT_VERSION.jar") +fi + +function build_jar { + # Usage: + # build_jar package path/to/jar/dir ['/some/sed/command'] + # + # Last arg is optional + cd $DOTTY_ROOT >& /dev/null + local build_output=$(sbt "$1") + local jar=$(echo $build_output | sed -n 's/.*Packaging //g; s/ \.\.\..*//g; /^\/.*/p') + + local sedjar="$3" + if [ "$sedjar" == "" ]; then + sedjar="/.*\.jar/p" + fi + + if [ "$jar" == "" ]; then + # Didn't build a jar - could've run sbt by oneself, get latest jar in target: + jar="$DOTTY_ROOT/$2/$(ls -1t "$2" | sed -n "$sedjar" | awk 'NR==1')" + fi + + cd - >& /dev/null + + echo $jar +} + +function update_packages { + echo "$INTERFACES_JAR" > $DOTTY_ROOT/.packages + echo "$MAIN_JAR" >> $DOTTY_ROOT/.packages + echo "$TEST_JAR" >> $DOTTY_ROOT/.packages +} + +function build_all { + echo "The script is going to build the required jar files" + + printf "Building dotty-interfaces..." + INTERFACES_JAR=$(build_jar dotty-interfaces/package interfaces/target) + printf "done\n" + + printf "Building dotty..." + MAIN_JAR=$(build_jar package target/scala-2.11) + printf "done\n" + + printf "Building tests..." + TEST_JAR=$(build_jar test:package target/scala-2.11 '/dotty.*-tests\.jar/p') + printf "done\n" + + update_packages +} + +# Check if .packages file does not exist - if so assume old build and rebuild all +if [ ! -f "$DOTTY_ROOT/.packages" ]; then + build_all +else + IFS=$'\r\n' GLOBIGNORE='*' command eval 'JARS=($(cat $DOTTY_ROOT/.packages))' + + if [ "${#JARS[@]}" == "3" ]; then + INTERFACES_JAR="${JARS[0]}" + MAIN_JAR="${JARS[1]}" + TEST_JAR="${JARS[2]}" + else + echo "Corrupted .packages file" + build_all + fi +fi + +################# After this point, jar variables will be set ################# +function check_jar { + # Usage: + # check_jar "name" "path/to/package.jar" "sources/dir" 'lambda to exec on failure' + local new_files="$(find "$3" \( -iname "*.scala" -o -iname "*.java" \) -newer "$2")" + if [ ! -z "$new_files" ]; then + printf "New files detected in $1, rebuilding..." + eval "$4" + printf "done\n" + update_packages + fi +} + +check_jar "dotty-interfaces" $INTERFACES_JAR "interfaces" 'INTERFACES_JAR=$(build_jar dotty-interfaces/package interfaces/target)' +check_jar "dotty" $MAIN_JAR "src" 'MAIN_JAR=$(build_jar package target/scala-2.11)' +check_jar "dotty-tests" $TEST_JAR "test" 'TEST_JAR=$(build_jar test:package target/scala-2.11 /dotty.*-tests\.jar/p)' diff --git a/bin/dotc b/bin/dotc index d64755ec02b3..f604483c1c4d 100755 --- a/bin/dotc +++ b/bin/dotc @@ -10,110 +10,7 @@ fi DOTTY_ROOT="$(dirname "$DOTTY_ROOT")" DOTTY_ROOT="$( cd "$DOTTY_ROOT" >& /dev/null && pwd )/.." # absolute -# Finds in dotty build file a line containing PATTERN -# returns last "" escaped string in this line -function getLastStringOnLineWith { - PATTERN="$1" - grep "$PATTERN" "$DOTTY_ROOT/project/Build.scala"|sed -n 's/.*\"\(.*\)\".*/\1/'p -} - -# Configuration -SCALA_VERSION=$(getLastStringOnLineWith "scalaVersion in") -SCALA_BINARY_VERSION=2.11 -SCALA_COMPILER_VERSION=$(getLastStringOnLineWith "scala-compiler") -JLINE_VERSION=$(getLastStringOnLineWith "jline") -SBT_VERSION=$(grep "sbt.version=" "$DOTTY_ROOT/project/build.properties" | sed 's/sbt.version=//') -bootcp=true -bootstrapped=false -default_java_opts="-Xmx768m -Xms768m" -programName=$(basename "$0") -# uncomment next line to enable debug output -#debug=true - -declare -a java_args scala_args residual_args -unset verbose quiet cygwin toolcp colors saved_stty CDPATH - -function build_jar { - # Usage: - # build_jar package path/to/jar/dir ['/some/sed/command'] - # - # Last arg is optional - cd $DOTTY_ROOT >& /dev/null - local build_output=$(sbt "$1") - local jar=$(echo $build_output | sed -n 's/.*Packaging //g; s/ \.\.\..*//g; /^\/.*/p') - - local sedjar="$3" - if [ "$sedjar" == "" ]; then - sedjar="/.*\.jar/p" - fi - - if [ "$jar" == "" ]; then - # Didn't build a jar - could've run sbt by oneself, get latest jar in target: - jar="$DOTTY_ROOT/$2/$(ls -1t "$2" | sed -n "$sedjar" | awk 'NR==1')" - fi - - cd - >& /dev/null - - echo $jar -} - -function update_packages { - echo "$INTERFACES_JAR" > $DOTTY_ROOT/.packages - echo "$MAIN_JAR" >> $DOTTY_ROOT/.packages - echo "$TEST_JAR" >> $DOTTY_ROOT/.packages -} - -function build_all { - echo "The script is going to build the required jar files" - - printf "Building dotty-interfaces..." - INTERFACES_JAR=$(build_jar dotty-interfaces/package interfaces/target) - printf "done\n" - - printf "Building dotty..." - MAIN_JAR=$(build_jar package target/scala-2.11) - printf "done\n" - - printf "Building tests..." - TEST_JAR=$(build_jar test:package target/scala-2.11 '/dotty.*-tests\.jar/p') - printf "done\n" - - update_packages -} - - -# Check if .packages file does not exist - if so assume old build and rebuild all -if [ ! -f "$DOTTY_ROOT/.packages" ]; then - build_all -else - IFS=$'\r\n' GLOBIGNORE='*' command eval 'JARS=($(cat $DOTTY_ROOT/.packages))' - - if [ "${#JARS[@]}" == "3" ]; then - INTERFACES_JAR="${JARS[0]}" - MAIN_JAR="${JARS[1]}" - TEST_JAR="${JARS[2]}" - else - echo "Corrupted .packages file" - build_all - fi -fi - -################# After this point, jar variables will be set ################# -function check_jar { - # Usage: - # check_jar "name" "path/to/package.jar" "sources/dir" 'lambda to exec on failure' - local new_files="$(find "$3" \( -iname "*.scala" -o -iname "*.java" \) -newer "$2")" - if [ ! -z "$new_files" ]; then - printf "New files detected in $1, rebuilding..." - eval "$4" - printf "done\n" - update_packages - fi -} - -check_jar "dotty-interfaces" $INTERFACES_JAR "interfaces" 'INTERFACES_JAR=$(build_jar dotty-interfaces/package interfaces/target)' -check_jar "dotty" $MAIN_JAR "src" 'MAIN_JAR=$(build_jar package target/scala-2.11)' -check_jar "dotty-tests" $TEST_JAR "test" 'TEST_JAR=$(build_jar test:package target/scala-2.11 /dotty.*-tests\.jar/p)' +source $DOTTY_ROOT/bin/common # dotc.build test places bootstrapped jar here DOTTY_JAR=$DOTTY_ROOT/dotty.jar @@ -122,39 +19,6 @@ CompilerMain=dotty.tools.dotc.Main FromTasty=dotty.tools.dotc.FromTasty ReplMain=dotty.tools.dotc.repl.Main -function find_jar { - # Usage: - # find_jar path/to/location file.jar - local artifact="$1/$2" - - if [ ! -f "$artifact" ]; then - artifact=$(find "$HOME/.coursier/cache" -iname "$2") - fi - - echo "$artifact" -} - -# Autodetecting the scala-library location, in case it wasn't provided by an environment variable -if [ "$SCALA_LIBRARY_JAR" == "" ]; then - SCALA_LIBRARY_JAR=$(find_jar "$HOME/.ivy2/cache/org.scala-lang/scala-library/jars" "scala-library-$SCALA_VERSION.jar") -fi - -if [ "$SCALA_REFLECT_JAR" == "" ]; then - SCALA_REFLECT_JAR=$(find_jar "$HOME/.ivy2/cache/org.scala-lang/scala-reflect/jars" "scala-reflect-$SCALA_VERSION.jar") -fi - -if [ "$SCALA_COMPILER_JAR" == "" ]; then - SCALA_COMPILER_JAR=$(find_jar "$HOME/.ivy2/cache/me.d-d/scala-compiler/jars" "scala-compiler-$SCALA_COMPILER_VERSION.jar") -fi - -if [ "$JLINE_JAR" == "" ]; then - JLINE_JAR=$(find_jar "$HOME/.ivy2/cache/jline/jline/jars" "jline-$JLINE_VERSION.jar") -fi - -if [ "$SBT_INTERFACE_JAR" == "" ]; then - SBT_INTERFACE_JAR=$(find_jar "$HOME/.ivy2/cache/org.scala-sbt/interface/jars" "interface-$SBT_VERSION.jar") -fi - if [ ! -f "$SCALA_LIBRARY_JAR" -o ! -f "$SCALA_REFLECT_JAR" -o ! -f "$SCALA_COMPILER_JAR" -o ! -f "$JLINE_JAR" -o ! -f "$SBT_INTERFACE_JAR" ] then echo To use this script please set diff --git a/bin/dotr b/bin/dotr index f1da6c8eab26..90d2825e6b5c 100755 --- a/bin/dotr +++ b/bin/dotr @@ -7,24 +7,9 @@ if [[ "$DOTTY_ROOT" == "" ]]; then fi DOTTY_ROOT="$(dirname "$DOTTY_ROOT")" DOTTY_ROOT="$( cd "$DOTTY_ROOT" >& /dev/null && pwd )/.." # absolute -SCALA_VERSION=$(grep "scalaVersion in" "$DOTTY_ROOT/project/Build.scala"|sed -n 's/.*\"\(.*\)\".*/\1/'p) -function find_jar { - # Usage: - # find_jar path/to/location file.jar - local artifact="$1/$2" - - if [ ! -f "$artifact" ]; then - artifact=$(find "$HOME/.coursier/cache" -iname "$2") - fi - - echo "$artifact" -} - -# Autodetecting the scala-library location, in case it wasn't provided by an environment variable -if [ "$SCALA_LIBRARY_JAR" == "" ]; then - SCALA_LIBRARY_JAR=$(find_jar "$HOME/.ivy2/cache/org.scala-lang/scala-library/jars" "scala-library-$SCALA_VERSION.jar") -fi +# Load common functions and variables +source $DOTTY_ROOT/bin/common # CLASS_PATH is derived from the DOTTY_ROOT and SCALA_LIBRARY_JAR CLASS_PATH="-Xbootclasspath/a:.:$DOTTY_ROOT/target/scala-2.11/classes/:.:$SCALA_LIBRARY_JAR" From a338ac76accb3149603b91f1dff1f6f53b11dcb2 Mon Sep 17 00:00:00 2001 From: Felix Mulder Date: Tue, 21 Jun 2016 20:16:44 +0200 Subject: [PATCH 6/6] Die if `java` bin is not found or specified --- bin/dotr | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/dotr b/bin/dotr index 90d2825e6b5c..a3870ac7ab17 100755 --- a/bin/dotr +++ b/bin/dotr @@ -23,6 +23,7 @@ function runMain { if [ "$jbin" == "" ]; then echo "java bin not detected - please specify with \$JAVA_BIN or install java to a default location" + exit 1 else eval "$jbin $CLASS_PATH $@" fi