Skip to content

Commit af93e88

Browse files
authored
Merge pull request #1324 from felixmulder/fix/dotc-version#1321
Multiple fixes for `bin/dotc` and `bin/dotr`
2 parents 82a0bd3 + a338ac7 commit af93e88

File tree

6 files changed

+254
-98
lines changed

6 files changed

+254
-98
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,6 @@ scala-scala
3838
# Ignore output files but keep the directory
3939
out/
4040
!out/.keep
41+
42+
# Ignore build-file
43+
.packages

bin/common

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#!/bin/bash
2+
3+
# Finds in dotty build file a line containing PATTERN
4+
# returns last "" escaped string in this line
5+
function getLastStringOnLineWith {
6+
PATTERN="$1"
7+
grep "$PATTERN" "$DOTTY_ROOT/project/Build.scala"|sed -n 's/.*\"\(.*\)\".*/\1/'p
8+
}
9+
10+
# Configuration
11+
SCALA_VERSION=$(getLastStringOnLineWith "scalaVersion in")
12+
SCALA_BINARY_VERSION=2.11
13+
SCALA_COMPILER_VERSION=$(getLastStringOnLineWith "scala-compiler")
14+
JLINE_VERSION=$(getLastStringOnLineWith "jline")
15+
SBT_VERSION=$(grep "sbt.version=" "$DOTTY_ROOT/project/build.properties" | sed 's/sbt.version=//')
16+
bootcp=true
17+
bootstrapped=false
18+
default_java_opts="-Xmx768m -Xms768m"
19+
programName=$(basename "$0")
20+
# uncomment next line to enable debug output
21+
#debug=true
22+
23+
declare -a java_args scala_args residual_args
24+
unset verbose quiet cygwin toolcp colors saved_stty CDPATH
25+
26+
function find_jar {
27+
# Usage:
28+
# find_jar path/to/location file.jar
29+
local artifact="$1/$2"
30+
31+
if [ ! -f "$artifact" ]; then
32+
artifact=$(find "$HOME/.coursier/cache" -iname "$2")
33+
fi
34+
35+
echo "$artifact"
36+
}
37+
38+
# Autodetecting the scala-library location, in case it wasn't provided by an environment variable
39+
if [ "$SCALA_LIBRARY_JAR" == "" ]; then
40+
SCALA_LIBRARY_JAR=$(find_jar "$HOME/.ivy2/cache/org.scala-lang/scala-library/jars" "scala-library-$SCALA_VERSION.jar")
41+
fi
42+
43+
if [ "$SCALA_REFLECT_JAR" == "" ]; then
44+
SCALA_REFLECT_JAR=$(find_jar "$HOME/.ivy2/cache/org.scala-lang/scala-reflect/jars" "scala-reflect-$SCALA_VERSION.jar")
45+
fi
46+
47+
if [ "$SCALA_COMPILER_JAR" == "" ]; then
48+
SCALA_COMPILER_JAR=$(find_jar "$HOME/.ivy2/cache/me.d-d/scala-compiler/jars" "scala-compiler-$SCALA_COMPILER_VERSION.jar")
49+
fi
50+
51+
if [ "$JLINE_JAR" == "" ]; then
52+
JLINE_JAR=$(find_jar "$HOME/.ivy2/cache/jline/jline/jars" "jline-$JLINE_VERSION.jar")
53+
fi
54+
55+
if [ "$SBT_INTERFACE_JAR" == "" ]; then
56+
SBT_INTERFACE_JAR=$(find_jar "$HOME/.ivy2/cache/org.scala-sbt/interface/jars" "interface-$SBT_VERSION.jar")
57+
fi
58+
59+
function build_jar {
60+
# Usage:
61+
# build_jar package path/to/jar/dir ['/some/sed/command']
62+
#
63+
# Last arg is optional
64+
cd $DOTTY_ROOT >& /dev/null
65+
local build_output=$(sbt "$1")
66+
local jar=$(echo $build_output | sed -n 's/.*Packaging //g; s/ \.\.\..*//g; /^\/.*/p')
67+
68+
local sedjar="$3"
69+
if [ "$sedjar" == "" ]; then
70+
sedjar="/.*\.jar/p"
71+
fi
72+
73+
if [ "$jar" == "" ]; then
74+
# Didn't build a jar - could've run sbt by oneself, get latest jar in target:
75+
jar="$DOTTY_ROOT/$2/$(ls -1t "$2" | sed -n "$sedjar" | awk 'NR==1')"
76+
fi
77+
78+
cd - >& /dev/null
79+
80+
echo $jar
81+
}
82+
83+
function update_packages {
84+
echo "$INTERFACES_JAR" > $DOTTY_ROOT/.packages
85+
echo "$MAIN_JAR" >> $DOTTY_ROOT/.packages
86+
echo "$TEST_JAR" >> $DOTTY_ROOT/.packages
87+
}
88+
89+
function build_all {
90+
echo "The script is going to build the required jar files"
91+
92+
printf "Building dotty-interfaces..."
93+
INTERFACES_JAR=$(build_jar dotty-interfaces/package interfaces/target)
94+
printf "done\n"
95+
96+
printf "Building dotty..."
97+
MAIN_JAR=$(build_jar package target/scala-2.11)
98+
printf "done\n"
99+
100+
printf "Building tests..."
101+
TEST_JAR=$(build_jar test:package target/scala-2.11 '/dotty.*-tests\.jar/p')
102+
printf "done\n"
103+
104+
update_packages
105+
}
106+
107+
# Check if .packages file does not exist - if so assume old build and rebuild all
108+
if [ ! -f "$DOTTY_ROOT/.packages" ]; then
109+
build_all
110+
else
111+
IFS=$'\r\n' GLOBIGNORE='*' command eval 'JARS=($(cat $DOTTY_ROOT/.packages))'
112+
113+
if [ "${#JARS[@]}" == "3" ]; then
114+
INTERFACES_JAR="${JARS[0]}"
115+
MAIN_JAR="${JARS[1]}"
116+
TEST_JAR="${JARS[2]}"
117+
else
118+
echo "Corrupted .packages file"
119+
build_all
120+
fi
121+
fi
122+
123+
################# After this point, jar variables will be set #################
124+
function check_jar {
125+
# Usage:
126+
# check_jar "name" "path/to/package.jar" "sources/dir" 'lambda to exec on failure'
127+
local new_files="$(find "$3" \( -iname "*.scala" -o -iname "*.java" \) -newer "$2")"
128+
if [ ! -z "$new_files" ]; then
129+
printf "New files detected in $1, rebuilding..."
130+
eval "$4"
131+
printf "done\n"
132+
update_packages
133+
fi
134+
}
135+
136+
check_jar "dotty-interfaces" $INTERFACES_JAR "interfaces" 'INTERFACES_JAR=$(build_jar dotty-interfaces/package interfaces/target)'
137+
check_jar "dotty" $MAIN_JAR "src" 'MAIN_JAR=$(build_jar package target/scala-2.11)'
138+
check_jar "dotty-tests" $TEST_JAR "test" 'TEST_JAR=$(build_jar test:package target/scala-2.11 /dotty.*-tests\.jar/p)'

bin/dotc

Lines changed: 5 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -10,102 +10,15 @@ fi
1010
DOTTY_ROOT="$(dirname "$DOTTY_ROOT")"
1111
DOTTY_ROOT="$( cd "$DOTTY_ROOT" >& /dev/null && pwd )/.." # absolute
1212

13-
# Finds in dotty build file a line containing PATTERN
14-
# returns last "" escaped string in this line
15-
function getLastStringOnLineWith {
16-
PATTERN="$1"
17-
grep "$PATTERN" "$DOTTY_ROOT/project/Build.scala"|sed -n 's/.*\"\(.*\)\".*/\1/'p
18-
}
19-
20-
# Configuration
21-
SCALA_VERSION=$(getLastStringOnLineWith "scalaVersion in")
22-
SCALA_BINARY_VERSION=2.11
23-
SCALA_COMPILER_VERSION=$(getLastStringOnLineWith "scala-compiler")
24-
DOTTY_VERSION=$(getLastStringOnLineWith "version in")
25-
JLINE_VERSION=$(getLastStringOnLineWith "jline")
26-
SBT_VERSION=$(grep "sbt.version=" "$DOTTY_ROOT/project/build.properties" | sed 's/sbt.version=//')
27-
bootcp=true
28-
bootstrapped=false
29-
default_java_opts="-Xmx768m -Xms768m"
30-
programName=$(basename "$0")
31-
# uncomment next line to enable debug output
32-
#debug=true
33-
34-
35-
36-
declare -a java_args scala_args residual_args
37-
unset verbose quiet cygwin toolcp colors saved_stty CDPATH
13+
source $DOTTY_ROOT/bin/common
3814

15+
# dotc.build test places bootstrapped jar here
16+
DOTTY_JAR=$DOTTY_ROOT/dotty.jar
3917

4018
CompilerMain=dotty.tools.dotc.Main
4119
FromTasty=dotty.tools.dotc.FromTasty
4220
ReplMain=dotty.tools.dotc.repl.Main
4321

44-
45-
46-
# autodetecting the compiler jars. this is the location where sbt 'packages' them
47-
INTERFACES_JAR=$DOTTY_ROOT/interfaces/target/dotty-interfaces-$DOTTY_VERSION.jar
48-
MAIN_JAR=$DOTTY_ROOT/target/scala-$SCALA_BINARY_VERSION/dotty_$SCALA_BINARY_VERSION-$DOTTY_VERSION.jar
49-
TEST_JAR=$DOTTY_ROOT/target/scala-$SCALA_BINARY_VERSION/dotty_$SCALA_BINARY_VERSION-$DOTTY_VERSION-tests.jar
50-
DOTTY_JAR=$DOTTY_ROOT/dotty.jar
51-
52-
function checkjar {
53-
if [ ! -f "$1" ]
54-
then
55-
echo "The script is going to build the required jar file $1 by running \"sbt $2\""
56-
cd $DOTTY_ROOT
57-
sbt "$2"
58-
cd -
59-
if [ ! -f "$1" ]
60-
then
61-
echo "The required jar file has not been built by sbt. Please run \"sbt $2\""
62-
exit 1
63-
else
64-
echo "The required jar file was built successfully."
65-
fi
66-
else
67-
NEW_FILES="$(find "$DOTTY_ROOT/$3" \( -iname "*.scala" -o -iname "*.java" \) -newer "$1")"
68-
if [ ! -z "$NEW_FILES" ];
69-
then
70-
echo "new files detected. rebuilding"
71-
cd $DOTTY_ROOT
72-
sbt "$2"
73-
touch "$1"
74-
cd -
75-
fi
76-
fi
77-
}
78-
79-
checkjar $INTERFACES_JAR dotty-interfaces/package interfaces
80-
checkjar $MAIN_JAR package src
81-
checkjar $TEST_JAR test:package test
82-
83-
# Autodetecting the scala-library location, in case it wasn't provided by an environment variable
84-
if [ "$SCALA_LIBRARY_JAR" == "" ]
85-
then
86-
SCALA_LIBRARY_JAR=$HOME/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-$SCALA_VERSION.jar
87-
# this is location where sbt stores it in ivy cache
88-
fi
89-
# save as for scala-library now for scala-reflect
90-
if [ "$SCALA_REFLECT_JAR" == "" ]
91-
then
92-
SCALA_REFLECT_JAR=$HOME/.ivy2/cache/org.scala-lang/scala-reflect/jars/scala-reflect-$SCALA_VERSION.jar
93-
fi
94-
if [ "$SCALA_COMPILER_JAR" == "" ]
95-
then
96-
SCALA_COMPILER_JAR=$HOME/.ivy2/cache/me.d-d/scala-compiler/jars/scala-compiler-$SCALA_COMPILER_VERSION.jar
97-
fi
98-
99-
if [ "$JLINE_JAR" == "" ]
100-
then
101-
JLINE_JAR=$HOME/.ivy2/cache/jline/jline/jars/jline-$JLINE_VERSION.jar
102-
fi
103-
104-
if [ "$SBT_INTERFACE_JAR" == "" ]
105-
then
106-
SBT_INTERFACE_JAR=$HOME/.ivy2/cache/org.scala-sbt/interface/jars/interface-$SBT_VERSION.jar
107-
fi
108-
10922
if [ ! -f "$SCALA_LIBRARY_JAR" -o ! -f "$SCALA_REFLECT_JAR" -o ! -f "$SCALA_COMPILER_JAR" -o ! -f "$JLINE_JAR" -o ! -f "$SBT_INTERFACE_JAR" ]
11023
then
11124
echo To use this script please set
@@ -201,8 +114,8 @@ trap onExit INT
201114
# If using the boot classpath, also pass an empty classpath
202115
# to java to suppress "." from materializing.
203116
classpathArgs () {
204-
if [[ "true" == $bootstrapped ]]; then
205-
checkjar $DOTTY_JAR "test:runMain dotc.build" src
117+
if [[ "true" == $bootstrapped ]]; then
118+
check_jar "dotty-bootstrapped" $DOTTY_JAR "target" 'build_jar "test:runMain dotc.build" target' &> /dev/null
206119
toolchain="$DOTTY_JAR:$SCALA_LIBRARY_JAR:$SCALA_REFLECT_JAR:$SCALA_COMPILER_JAR:$JLINE_JAR:$SBT_INTERFACE_JAR"
207120
else
208121
toolchain="$SCALA_LIBRARY_JAR:$SCALA_REFLECT_JAR:$SCALA_COMPILER_JAR:$JLINE_JAR:$SBT_INTERFACE_JAR"

bin/dotr

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,25 @@ fi
88
DOTTY_ROOT="$(dirname "$DOTTY_ROOT")"
99
DOTTY_ROOT="$( cd "$DOTTY_ROOT" >& /dev/null && pwd )/.." # absolute
1010

11-
# CLASS_PATH is derived from the DOTTY_ROOT
12-
CLASS_PATH="-J-Xbootclasspath/a:.:$DOTTY_ROOT/target/scala-2.11/classes/"
11+
# Load common functions and variables
12+
source $DOTTY_ROOT/bin/common
13+
14+
# CLASS_PATH is derived from the DOTTY_ROOT and SCALA_LIBRARY_JAR
15+
CLASS_PATH="-Xbootclasspath/a:.:$DOTTY_ROOT/target/scala-2.11/classes/:.:$SCALA_LIBRARY_JAR"
1316

1417
function runMain {
15-
scala $CLASS_PATH $@
18+
local jbin=$(which "java")
19+
20+
if [ ! -z "$JAVA_BIN" ]; then
21+
jbin=$JAVA_BIN
22+
fi
23+
24+
if [ "$jbin" == "" ]; then
25+
echo "java bin not detected - please specify with \$JAVA_BIN or install java to a default location"
26+
exit 1
27+
else
28+
eval "$jbin $CLASS_PATH $@"
29+
fi
1630
}
1731

1832
if [ -z "$1" ]; then

project/Build.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ object DottyBuild extends Build {
9393
"org.scala-lang.modules" %% "scala-partest" % "1.0.11" % "test",
9494
"com.novocode" % "junit-interface" % "0.11" % "test",
9595
"jline" % "jline" % "2.12",
96-
"org.scala-sbt" % "interface" % sbtVersion.value),
97-
96+
"com.typesafe.sbt" % "sbt-interface" % sbtVersion.value),
9897
// enable improved incremental compilation algorithm
9998
incOptions := incOptions.value.withNameHashing(true),
10099

@@ -205,7 +204,7 @@ object DottyBuild extends Build {
205204
description := "sbt compiler bridge for Dotty",
206205
resolvers += Resolver.typesafeIvyRepo("releases"),
207206
libraryDependencies ++= Seq(
208-
"org.scala-sbt" % "interface" % sbtVersion.value,
207+
"com.typesafe.sbt" % "sbt-interface" % sbtVersion.value,
209208
"org.scala-sbt" % "api" % sbtVersion.value % "test",
210209
"org.specs2" %% "specs2" % "2.3.11" % "test"
211210
),

0 commit comments

Comments
 (0)