Skip to content

Commit 488cd7a

Browse files
committed
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
1 parent c7d1826 commit 488cd7a

File tree

2 files changed

+83
-38
lines changed

2 files changed

+83
-38
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/dotc

Lines changed: 80 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ function getLastStringOnLineWith {
2121
SCALA_VERSION=$(getLastStringOnLineWith "scalaVersion in")
2222
SCALA_BINARY_VERSION=2.11
2323
SCALA_COMPILER_VERSION=$(getLastStringOnLineWith "scala-compiler")
24-
DOTTY_VERSION=$(getLastStringOnLineWith "version in")
2524
JLINE_VERSION=$(getLastStringOnLineWith "jline")
2625
SBT_VERSION=$(grep "sbt.version=" "$DOTTY_ROOT/project/build.properties" | sed 's/sbt.version=//')
2726
bootcp=true
@@ -31,54 +30,97 @@ programName=$(basename "$0")
3130
# uncomment next line to enable debug output
3231
#debug=true
3332

34-
35-
3633
declare -a java_args scala_args residual_args
3734
unset verbose quiet cygwin toolcp colors saved_stty CDPATH
3835

36+
function build_jar {
37+
# Usage:
38+
# build_jar package path/to/jar/dir ['/some/sed/command']
39+
#
40+
# Last arg is optional
41+
cd $DOTTY_ROOT >& /dev/null
42+
local build_output=$(sbt "$1")
43+
local jar=$(echo $build_output | sed -n 's/.*Packaging //g; s/ \.\.\..*//g; /^\/.*/p')
44+
45+
local sedjar="$3"
46+
if [ "$sedjar" == "" ]; then
47+
sedjar="/.*\.jar/p"
48+
fi
3949

40-
CompilerMain=dotty.tools.dotc.Main
41-
FromTasty=dotty.tools.dotc.FromTasty
42-
ReplMain=dotty.tools.dotc.repl.Main
50+
if [ "$jar" == "" ]; then
51+
# Didn't build a jar - could've run sbt by oneself, get latest jar in target:
52+
jar="$DOTTY_ROOT/$2/$(ls -1t "$2" | sed -n "$sedjar" | awk 'NR==1')"
53+
fi
4354

55+
cd - >& /dev/null
4456

57+
echo $jar
58+
}
4559

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
60+
function update_packages {
61+
echo "$INTERFACES_JAR" > $DOTTY_ROOT/.packages
62+
echo "$MAIN_JAR" >> $DOTTY_ROOT/.packages
63+
echo "$TEST_JAR" >> $DOTTY_ROOT/.packages
64+
}
65+
66+
function build_all {
67+
echo "The script is going to build the required jar files"
68+
69+
printf "Building dotty-interfaces..."
70+
INTERFACES_JAR=$(build_jar dotty-interfaces/package interfaces/target)
71+
printf "done\n"
72+
73+
printf "Building dotty..."
74+
MAIN_JAR=$(build_jar package target/scala-2.11)
75+
printf "done\n"
76+
77+
printf "Building tests..."
78+
TEST_JAR=$(build_jar test:package target/scala-2.11 '/dotty.*-tests\.jar/p')
79+
printf "done\n"
5180

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
81+
update_packages
82+
}
83+
84+
85+
# Check if .packages file does not exist - if so assume old build and rebuild all
86+
if [ ! -f "$DOTTY_ROOT/.packages" ]; then
87+
build_all
88+
else
89+
IFS=$'\r\n' GLOBIGNORE='*' command eval 'JARS=($(cat $DOTTY_ROOT/.packages))'
90+
91+
if [ "${#JARS[@]}" == "3" ]; then
92+
INTERFACES_JAR="${JARS[0]}"
93+
MAIN_JAR="${JARS[1]}"
94+
TEST_JAR="${JARS[2]}"
6395
else
64-
echo "The required jar file was built successfully."
96+
echo "Corrupted .packages file"
97+
build_all
6598
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 -
99+
fi
100+
101+
################# After this point, jar variables will be set #################
102+
function check_jar {
103+
# Usage:
104+
# check_jar "name" "path/to/package.jar" "sources/dir" 'lambda to exec on failure'
105+
local new_files="$(find "$3" \( -iname "*.scala" -o -iname "*.java" \) -newer "$2")"
106+
if [ ! -z "$new_files" ]; then
107+
printf "New files detected in $1, rebuilding..."
108+
eval "$4"
109+
printf "done\n"
110+
update_packages
75111
fi
76-
fi
77112
}
78113

79-
checkjar $INTERFACES_JAR dotty-interfaces/package interfaces
80-
checkjar $MAIN_JAR package src
81-
checkjar $TEST_JAR test:package test
114+
check_jar "dotty-interfaces" $INTERFACES_JAR "interfaces" 'INTERFACES_JAR=$(build_jar dotty-interfaces/package interfaces/target)'
115+
check_jar "dotty" $MAIN_JAR "src" 'MAIN_JAR=$(build_jar package target/scala-2.11)'
116+
check_jar "dotty-tests" $TEST_JAR "test" 'TEST_JAR=$(build_jar test:package target/scala-2.11 /dotty.*-tests\.jar/p)'
117+
118+
# dotc.build test places bootstrapped jar here
119+
DOTTY_JAR=$DOTTY_ROOT/dotty.jar
120+
121+
CompilerMain=dotty.tools.dotc.Main
122+
FromTasty=dotty.tools.dotc.FromTasty
123+
ReplMain=dotty.tools.dotc.repl.Main
82124

83125
# Autodetecting the scala-library location, in case it wasn't provided by an environment variable
84126
if [ "$SCALA_LIBRARY_JAR" == "" ]
@@ -201,8 +243,8 @@ trap onExit INT
201243
# If using the boot classpath, also pass an empty classpath
202244
# to java to suppress "." from materializing.
203245
classpathArgs () {
204-
if [[ "true" == $bootstrapped ]]; then
205-
checkjar $DOTTY_JAR "test:runMain dotc.build" src
246+
if [[ "true" == $bootstrapped ]]; then
247+
check_jar "dotty-bootstrapped" $DOTTY_JAR "target" 'build_jar "test:runMain dotc.build" target' &> /dev/null
206248
toolchain="$DOTTY_JAR:$SCALA_LIBRARY_JAR:$SCALA_REFLECT_JAR:$SCALA_COMPILER_JAR:$JLINE_JAR:$SBT_INTERFACE_JAR"
207249
else
208250
toolchain="$SCALA_LIBRARY_JAR:$SCALA_REFLECT_JAR:$SCALA_COMPILER_JAR:$JLINE_JAR:$SBT_INTERFACE_JAR"

0 commit comments

Comments
 (0)