Skip to content

Commit ba36c2b

Browse files
committed
Merge pull request scala#4455 from adriaanm/sbt-build
Experimental sbt build [ci: last-only]
2 parents d063dd3 + 1e4a125 commit ba36c2b

File tree

10 files changed

+521
-5
lines changed

10 files changed

+521
-5
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,9 @@
4848

4949
# Standard symbolic link to build/quick/bin
5050
/qbin
51+
52+
# Sbt's target directories
53+
/target/
54+
/project/target/
55+
/project/project/target
56+
/build-sbt/

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,15 @@ The Scala build system is based on Apache Ant. Most required pre-compiled
138138
libraries are part of the repository (in 'lib/'). The following however is
139139
assumed to be installed on the build machine:
140140

141+
## Building with Sbt (EXPERIMENTAL)
142+
143+
The experimental sbt-based build definition has arrived! Run `sbt package`
144+
to build the compiler. You can run `sbt test` to run unit (JUnit) tests.
145+
Use `sbt test/it:test` to run integration (partest) tests.
146+
147+
We would like to migrate to sbt build as quickly as possible. If you would
148+
like to help please contact scala-internals@ mailing list to discuss your
149+
ideas and coordinate your effort with others.
141150

142151
### Tips and tricks
143152

build.sbt

Lines changed: 443 additions & 0 deletions
Large diffs are not rendered by default.

build.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ TODO:
165165
<property name="build.dir" value="${basedir}/build"/>
166166
<property name="build-deps.dir" value="${build.dir}/deps"/>
167167
<property name="build-libs.dir" value="${build.dir}/libs"/>
168-
<property name="build-asm.dir" value="${build.dir}/asm"/>
168+
<property name="build-asm.dir" value="${build-libs.dir}"/>
169169
<property name="build-forkjoin.dir" value="${build-libs.dir}"/>
170170
<property name="build-locker.dir" value="${build.dir}/locker"/>
171171
<property name="build-quick.dir" value="${build.dir}/quick"/>
@@ -588,8 +588,8 @@ TODO:
588588
</propertyfile>
589589
</then></if>
590590

591-
<path id="forkjoin.classpath" path="${build-libs.dir}/classes/forkjoin"/>
592-
<path id="asm.classpath" path="${build-asm.dir}/classes"/>
591+
<path id="forkjoin.classpath" path="${build-forkjoin.dir}/classes/forkjoin"/>
592+
<path id="asm.classpath" path="${build-asm.dir}/classes/asm"/>
593593
<property name="forkjoin-classes" refid="forkjoin.classpath"/>
594594
<property name="asm-classes" refid="asm.classpath"/>
595595

@@ -1061,7 +1061,7 @@ TODO:
10611061
============================================================================ -->
10621062

10631063
<target name="asm.done" depends="init"> <simple-javac project="asm" jar="no"/> </target>
1064-
<target name="forkjoin.done" depends="init"> <simple-javac project="forkjoin" args="-XDignore.symbol.file"/></target>
1064+
<target name="forkjoin.done" depends="init"> <simple-javac project="forkjoin" args="-XDignore.symbol.file" jar="no"/></target>
10651065

10661066
<!-- For local development only. We only allow released versions of Scala for STARR.
10671067
This builds quick (core only) and publishes it with a generated version number,

compare-build-dirs-ignore-patterns

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.DS_Store
2+
*.complete
3+
locker
4+
deps
5+
scala-continuations-*.jar
6+
scala-parser-combinators*.jar
7+
scala-swing*.jar
8+
scala-xml*.jar

compare-build-dirs.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Compares build directories generated by Ant and sbt build definitions
2+
# This let's us to see how far are we from achieving perfect parity
3+
# between the builds
4+
5+
diff -X compare-build-dirs-ignore-patterns -qr build/ build-sbt/

project/ScalaTool.scala

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import sbt._
2+
import org.apache.commons.lang3.StringUtils.replaceEach
3+
4+
/**
5+
* A class that generates a shell or batch script to execute a Scala program.
6+
*
7+
* This is a simplified copy of Ant task (see scala.tools.ant.ScalaTool).
8+
*/
9+
case class ScalaTool(mainClass: String,
10+
classpath: List[String],
11+
properties: Map[String, String],
12+
javaOpts: String,
13+
toolFlags: String) {
14+
// For classpath, the platform specific
15+
// demarcation of any script variables (e.g. `${SCALA_HOME}` or
16+
// `%SCALA_HOME%`) can be specified in a platform independent way (e.g.
17+
// `@SCALA_HOME@`) and automatically translated for you.
18+
def patchedToolScript(template: String, platform: String) = {
19+
val varRegex = """@(\w+)@""" // the group should be able to capture each of the keys of the map below
20+
21+
val variables = Map(
22+
("@@" -> "@"), // for backwards compatibility
23+
("@class@" -> mainClass),
24+
("@properties@" -> (properties map { case (k, v) => s"""-D$k="$v""""} mkString " ")),
25+
("@javaflags@" -> javaOpts),
26+
("@toolflags@" -> toolFlags),
27+
("@classpath@" -> (platform match {
28+
case "unix" => classpath.mkString(":").replace('\\', '/').replaceAll(varRegex, """\${$1}""")
29+
case "windows" => classpath.mkString(";").replace('/', '\\').replaceAll(varRegex, "%$1%")
30+
}))
31+
)
32+
33+
val (from, to) = variables.unzip
34+
replaceEach(template, from.toArray, to.toArray)
35+
}
36+
37+
def writeScript(file: String, platform: String, rootDir: File, outDir: File): File = {
38+
val templatePath = s"scala/tools/ant/templates/tool-$platform.tmpl"
39+
val suffix = platform match { case "windows" => ".bat" case _ => "" }
40+
val scriptFile = outDir / s"$file$suffix"
41+
IO.write(scriptFile, patchedToolScript(IO.read(rootDir / templatePath), platform))
42+
scriptFile
43+
}
44+
}

project/build.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version=0.13.7

project/plugins.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
libraryDependencies += "org.apache.commons" % "commons-lang3" % "3.3.2"

test/junit/scala/collection/mutable/VectorTest.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ class VectorTest {
3838
def iteratorCat() {
3939
def its = vecs.map(_.toList.toIterator)
4040
val cats = vecs.map(a => its.map(a ++ _))
41-
println(cats)
4241
assert( cats == ans )
4342
}
4443

0 commit comments

Comments
 (0)