@@ -21,7 +21,6 @@ function getLastStringOnLineWith {
21
21
SCALA_VERSION=$( getLastStringOnLineWith " scalaVersion in" )
22
22
SCALA_BINARY_VERSION=2.11
23
23
SCALA_COMPILER_VERSION=$( getLastStringOnLineWith " scala-compiler" )
24
- DOTTY_VERSION=$( getLastStringOnLineWith " version in" )
25
24
JLINE_VERSION=$( getLastStringOnLineWith " jline" )
26
25
SBT_VERSION=$( grep " sbt.version=" " $DOTTY_ROOT /project/build.properties" | sed ' s/sbt.version=//' )
27
26
bootcp=true
@@ -31,54 +30,97 @@ programName=$(basename "$0")
31
30
# uncomment next line to enable debug output
32
31
# debug=true
33
32
34
-
35
-
36
33
declare -a java_args scala_args residual_args
37
34
unset verbose quiet cygwin toolcp colors saved_stty CDPATH
38
35
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
39
49
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
43
54
55
+ cd - >& /dev/null
44
56
57
+ echo $jar
58
+ }
45
59
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"
51
80
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]} "
63
95
else
64
- echo " The required jar file was built successfully."
96
+ echo " Corrupted .packages file"
97
+ build_all
65
98
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
75
111
fi
76
- fi
77
112
}
78
113
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
82
124
83
125
# Autodetecting the scala-library location, in case it wasn't provided by an environment variable
84
126
if [ " $SCALA_LIBRARY_JAR " == " " ]
@@ -201,8 +243,8 @@ trap onExit INT
201
243
# If using the boot classpath, also pass an empty classpath
202
244
# to java to suppress "." from materializing.
203
245
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
206
248
toolchain=" $DOTTY_JAR :$SCALA_LIBRARY_JAR :$SCALA_REFLECT_JAR :$SCALA_COMPILER_JAR :$JLINE_JAR :$SBT_INTERFACE_JAR "
207
249
else
208
250
toolchain=" $SCALA_LIBRARY_JAR :$SCALA_REFLECT_JAR :$SCALA_COMPILER_JAR :$JLINE_JAR :$SBT_INTERFACE_JAR "
0 commit comments