Skip to content

Commit 90eb9d2

Browse files
authored
Merge pull request #2101 from dotty-staging/upgrade/sbt0.13.14
Upgrade to sbt 0.13.14-RC2, switch to build.sbt
2 parents 5fd7a95 + 70c072a commit 90eb9d2

8 files changed

+201
-54
lines changed

build.sbt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
val dotty = Build.dotty
2+
val `dotty-bootstrapped` = Build.`dotty-bootstrapped`
3+
val `dotty-interfaces` = Build.`dotty-interfaces`
4+
val `dotty-doc` = Build.`dotty-doc`
5+
val `dotty-bot` = Build.`dotty-bot`
6+
val `dotty-compiler` = Build.`dotty-compiler`
7+
val `dotty-compiler-bootstrapped` = Build.`dotty-compiler-bootstrapped`
8+
val `dotty-bin-tests` = Build.`dotty-bin-tests`
9+
val `dotty-library` = Build.`dotty-library`
10+
val `dotty-library-bootstrapped` = Build.`dotty-library-bootstrapped`
11+
val `dotty-sbt-bridge` = Build.`dotty-sbt-bridge`
12+
val sjsSandbox = Build.sjsSandbox
13+
val `dotty-bench` = Build.`dotty-bench`
14+
val `scala-library` = Build.`scala-library`
15+
val `scala-compiler` = Build.`scala-compiler`
16+
val `scala-reflect` = Build.`scala-reflect`
17+
val scalap = Build.scalap
18+
19+
inThisBuild(Build.thisBuildSettings)

project/Build.scala

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import org.scalajs.sbtplugin.ScalaJSPlugin
1010
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._
1111
import sbt.Package.ManifestAttributes
1212

13-
object DottyBuild extends Build {
13+
object Build {
1414

1515
val scalacVersion = "2.11.5" // Do not rename, this is grepped in bin/common.
1616

@@ -59,26 +59,25 @@ object DottyBuild extends Build {
5959
// Shorthand for compiling a docs site
6060
lazy val dottydoc = inputKey[Unit]("run dottydoc")
6161

62-
override def settings: Seq[Setting[_]] = {
63-
super.settings ++ Seq(
64-
scalaVersion in Global := scalacVersion,
65-
version in Global := dottyVersion,
66-
organization in Global := dottyOrganization,
67-
organizationName in Global := "LAMP/EPFL",
68-
organizationHomepage in Global := Some(url("http://lamp.epfl.ch")),
69-
homepage in Global := Some(url("https://github.com/lampepfl/dotty")),
70-
71-
// scalac options
72-
scalacOptions in Global ++= Seq(
73-
"-feature",
74-
"-deprecation",
75-
"-encoding", "UTF8",
76-
"-language:existentials,higherKinds,implicitConversions"
77-
),
78-
79-
javacOptions in Global ++= Seq("-Xlint:unchecked", "-Xlint:deprecation")
80-
)
81-
}
62+
// Used in build.sbt
63+
val thisBuildSettings = Seq(
64+
scalaVersion in Global := scalacVersion,
65+
version in Global := dottyVersion,
66+
organization in Global := dottyOrganization,
67+
organizationName in Global := "LAMP/EPFL",
68+
organizationHomepage in Global := Some(url("http://lamp.epfl.ch")),
69+
homepage in Global := Some(url("https://github.com/lampepfl/dotty")),
70+
71+
// scalac options
72+
scalacOptions in Global ++= Seq(
73+
"-feature",
74+
"-deprecation",
75+
"-encoding", "UTF8",
76+
"-language:existentials,higherKinds,implicitConversions"
77+
),
78+
79+
javacOptions in Global ++= Seq("-Xlint:unchecked", "-Xlint:deprecation")
80+
)
8281

8382
/** Enforce 2.11.5. Do not let it be upgraded by dependencies. */
8483
private val overrideScalaVersionSetting =
@@ -124,7 +123,7 @@ object DottyBuild extends Build {
124123
lazy val dotty = project.in(file(".")).
125124
// FIXME: we do not aggregate `bin` because its tests delete jars, thus breaking other tests
126125
aggregate(`dotty-interfaces`, `dotty-library`, `dotty-compiler`, `dotty-doc`, dottySbtBridgeRef,
127-
`scala-library`, `scala-compiler`, `scala-reflect`, `scalap`).
126+
`scala-library`, `scala-compiler`, `scala-reflect`, scalap).
128127
dependsOn(`dotty-compiler`).
129128
dependsOn(`dotty-library`).
130129
settings(
@@ -281,8 +280,11 @@ object DottyBuild extends Build {
281280
libraryDependencies ++= partestDeps.value,
282281
libraryDependencies ++= Seq("org.scala-lang.modules" %% "scala-xml" % "1.0.1",
283282
"org.scala-lang.modules" %% "scala-partest" % "1.0.11" % "test",
284-
"com.novocode" % "junit-interface" % "0.11" % "test",
285-
"com.typesafe.sbt" % "sbt-interface" % sbtVersion.value),
283+
"com.novocode" % "junit-interface" % "0.11" % "test"),
284+
285+
resolvers += Resolver.typesafeIvyRepo("releases"), // For org.scala-sbt:interface
286+
libraryDependencies += "org.scala-sbt" % "interface" % sbtVersion.value,
287+
286288
// enable improved incremental compilation algorithm
287289
incOptions := incOptions.value.withNameHashing(true),
288290

@@ -428,7 +430,7 @@ object DottyBuild extends Build {
428430
// FIXME: should go away when xml literal parsing is removed
429431
path.contains("scala-xml") ||
430432
// needed for the xsbti interface
431-
path.contains("sbt-interface")
433+
path.contains("org.scala-sbt/interface/")
432434
} yield "-Xbootclasspath/p:" + path
433435

434436
val ci_build = // propagate if this is a ci build
@@ -552,9 +554,9 @@ object DottyBuild extends Build {
552554
},
553555
publishLocal := (publishLocal.dependsOn(cleanSbtBridge)).value,
554556
description := "sbt compiler bridge for Dotty",
555-
resolvers += Resolver.typesafeIvyRepo("releases"),
557+
resolvers += Resolver.typesafeIvyRepo("releases"), // For org.scala-sbt stuff
556558
libraryDependencies ++= Seq(
557-
"com.typesafe.sbt" % "sbt-interface" % sbtVersion.value,
559+
"org.scala-sbt" % "interface" % sbtVersion.value,
558560
"org.scala-sbt" % "api" % sbtVersion.value % "test",
559561
"org.specs2" %% "specs2" % "2.3.11" % "test"
560562
),
@@ -725,7 +727,7 @@ object DottyInjectedPlugin extends AutoPlugin {
725727
libraryDependencies := Seq("org.scala-lang" % "scala-reflect" % scalaVersion.value)
726728
).
727729
settings(publishing)
728-
lazy val `scalap` = project.
730+
lazy val scalap = project.
729731
settings(
730732
crossPaths := false,
731733
libraryDependencies := Seq("org.scala-lang" % "scalap" % scalaVersion.value)

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=0.13.11
1+
sbt.version=0.13.14-RC2

project/plugins.sbt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
// e.g. addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.1.0")
44

55
// Scala IDE project file generator
6-
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "4.0.0")
6+
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "5.1.0")
77

8-
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.8.0")
8+
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.14")
99

10-
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.8")
11-
12-
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.3")
10+
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.4")

sbt-bridge/test/xsbt/ExtractAPISpecification.scala

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
package xsbt
33

44
import org.junit.runner.RunWith
5-
import xsbti.api.ClassLike
6-
import xsbti.api.Def
7-
import xsbt.api.ShowAPI
5+
import xsbti.api._
6+
import xsbt.api.DefaultShowAPI
87
import org.specs2.mutable.Specification
98
import org.specs2.runner.JUnitRunner
109

@@ -17,7 +16,7 @@ class ExtractAPISpecification extends Specification {
1716

1817
def stableExistentialNames: Boolean = {
1918
def compileAndGetFooMethodApi(src: String): Def = {
20-
val compilerForTesting = new ScalaCompilerForUnitTesting
19+
val compilerForTesting = new ScalaCompilerForUnitTesting(nameHashing = false)
2120
val sourceApi = compilerForTesting.extractApiFromSrc(src)
2221
val FooApi = sourceApi.definitions().find(_.name() == "Foo").get.asInstanceOf[ClassLike]
2322
val fooMethodApi = FooApi.structure().declared().find(_.name == "foo").get
@@ -38,8 +37,81 @@ class ExtractAPISpecification extends Specification {
3837
|
3938
}""".stripMargin
4039
val fooMethodApi2 = compileAndGetFooMethodApi(src2)
40+
4141
fooMethodApi1 == fooMethodApi2
4242
// Fails because xsbt.api is compiled with Scala 2.10
4343
// SameAPI.apply(fooMethodApi1, fooMethodApi2)
4444
}
45+
46+
/**
47+
* Checks if representation of the inherited Namer class (with a declared self variable) in Global.Foo
48+
* is stable between compiling from source and unpickling. We compare extracted APIs of Global when Global
49+
* is compiled together with Namers or Namers is compiled first and then Global refers
50+
* to Namers by unpickling types from class files.
51+
*
52+
* See https://github.com/sbt/sbt/issues/2504
53+
*/
54+
"Self variable and no self type" in {
55+
def selectNamer(api: SourceAPI): ClassLike = {
56+
def selectClass(defs: Iterable[Definition], name: String): ClassLike = defs.collectFirst {
57+
case cls: ClassLike if cls.name == name => cls
58+
}.get
59+
val global = selectClass(api.definitions, "Global")
60+
val foo = selectClass(global.structure.declared, "Global.Foo")
61+
selectClass(foo.structure.inherited, "Namers.Namer")
62+
}
63+
val src1 =
64+
"""|class Namers {
65+
| class Namer { thisNamer => }
66+
|}
67+
|""".stripMargin
68+
val src2 =
69+
"""|class Global {
70+
| class Foo extends Namers
71+
|}
72+
|""".stripMargin
73+
val compilerForTesting = new ScalaCompilerForUnitTesting(nameHashing = false)
74+
val apis = compilerForTesting.extractApisFromSrcs(reuseCompilerInstance = false)(List(src1, src2), List(src2))
75+
val _ :: src2Api1 :: src2Api2 :: Nil = apis.toList
76+
val namerApi1 = selectNamer(src2Api1)
77+
val namerApi2 = selectNamer(src2Api2)
78+
79+
DefaultShowAPI(namerApi1) == DefaultShowAPI(namerApi2)
80+
// Fails because xsbt.api is compiled with Scala 2.10
81+
// SameAPI(namerApi1, namerApi2)
82+
}
83+
84+
/**
85+
* Checks if self type is properly extracted in various cases of declaring a self type
86+
* with our without a self variable.
87+
*/
88+
"Self type" in {
89+
def collectFirstClass(defs: Array[Definition]): ClassLike = defs.collectFirst {
90+
case c: ClassLike => c
91+
}.get
92+
val srcX = "trait X"
93+
val srcY = "trait Y"
94+
val srcC1 = "class C1 { this: C1 => }"
95+
val srcC2 = "class C2 { thisC: C2 => }"
96+
val srcC3 = "class C3 { this: X => }"
97+
val srcC4 = "class C4 { thisC: X => }"
98+
val srcC5 = "class C5 extends AnyRef with X with Y { self: X with Y => }"
99+
val srcC6 = "class C6 extends AnyRef with X { self: X with Y => }"
100+
// val srcC7 = "class C7 { _ => }" // DOTTY: Syntax not supported
101+
val srcC8 = "class C8 { self => }"
102+
val compilerForTesting = new ScalaCompilerForUnitTesting(nameHashing = false)
103+
val apis = compilerForTesting.extractApisFromSrcs(reuseCompilerInstance = true)(
104+
List(srcX, srcY, srcC1, srcC2, srcC3, srcC4, srcC5, srcC6, srcC8)
105+
).map(x => collectFirstClass(x.definitions))
106+
val emptyType = new EmptyType
107+
def hasSelfType(c: ClassLike): Boolean =
108+
c.selfType != emptyType
109+
val (withSelfType, withoutSelfType) = apis.partition(hasSelfType)
110+
// DOTTY: In the scalac ExtractAPI phase, the self-type is only
111+
// extracted if it differs from the type of the class for stability
112+
// reasons. This isn't necessary in dotty because we always pickle
113+
// the self type.
114+
withSelfType.map(_.name).toSet === Set("C1", "C2", "C3", "C4", "C5", "C6", "C8")
115+
withoutSelfType.map(_.name).toSet === Set("X", "Y")
116+
}
45117
}

sbt-bridge/test/xsbt/ExtractUsedNamesSpecification.scala

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class ExtractUsedNamesSpecification extends Specification {
7575
|}""".stripMargin
7676
val compilerForTesting = new ScalaCompilerForUnitTesting(nameHashing = true)
7777
val usedNames = compilerForTesting.extractUsedNamesFromSrc(srcA, srcB)
78+
7879
// DOTTY TODO: "Int" is not actually used, but we collect it because
7980
// it's the inferred return type so it appears in a TypeTree
8081
// We could avoid this by checking if the untyped tree has a return type
@@ -84,6 +85,44 @@ class ExtractUsedNamesSpecification extends Specification {
8485
usedNames === expectedNames
8586
}
8687

88+
"extract names in the types of trees" in {
89+
val src1 = """|class X0
90+
|class X1 extends X0
91+
|class Y
92+
|class A {
93+
| type T >: X1 <: X0
94+
|}
95+
|class M
96+
|class N
97+
|class P0
98+
|class P1 extends P0
99+
|object B {
100+
| type S = Y
101+
| val lista: List[A] = ???
102+
| val at: A#T = ???
103+
| val as: S = ???
104+
| def foo(m: M): N = ???
105+
| def bar[Param >: P1 <: P0](p: Param): Param = ???
106+
|}""".stripMargin
107+
val src2 = """|object Test {
108+
| val x = B.lista
109+
| val y = B.at
110+
| val z = B.as
111+
| B.foo(???)
112+
| B.bar(???)
113+
|}""".stripMargin
114+
val compilerForTesting = new ScalaCompilerForUnitTesting(nameHashing = true)
115+
val usedNames = compilerForTesting.extractUsedNamesFromSrc(src1, src2)
116+
val expectedNames = standardNames ++ Set("Test", "Test$", "B", "B$",
117+
"Predef", "Predef$", "$qmark$qmark$qmark", "Nothing",
118+
"lista", "List", "A",
119+
"at", "T", "X1", "X0",
120+
"as", "S", "Y",
121+
"foo", "M", "N",
122+
"bar", "P1", "P0")
123+
usedNames === expectedNames
124+
}
125+
87126
// test for https://github.com/gkossakowski/sbt/issues/3
88127
"used names from the same compilation unit" in {
89128
val src = "class A { def foo: Int = 0; def bar: Int = foo }"

0 commit comments

Comments
 (0)