This repository was archived by the owner on Apr 24, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbuild.sbt
125 lines (116 loc) · 3.99 KB
/
build.sbt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import Version._
import sbt.Def
version in ThisBuild ~= (_.replace('+', '-'))
name := "scalamacrosRoot"
onLoadMessage := s"Welcome to Scala Macros ${version.value}"
noPublish
lazy val scalamacros = project
.in(file("core"))
.settings(
moduleName := "scalamacros",
description := "Platform-independent interfaces for new-style Scala macros"
)
.enablePlugins(BuildInfoPlugin)
lazy val enginesScalac = project
.in(file("engines/scalac"))
.settings(
moduleName := "scalac-engine",
description := "Scalac implementation of interfaces for new-style Scala macros",
crossScalaVersions := List(scala212, scala213),
libraryDependencies += "org.scala-lang" % "scala-compiler" % scalaVersion.value
)
.dependsOn(scalamacros)
lazy val enginesDotc = project
.in(file("engines/dotc"))
.settings(
moduleName := "dotc-engine",
description := "Dotc implementation of interfaces for new-style Scala macros",
// default is scala212 for IntelliJ import, use `sbt enableDotty ...`
// to compile the project with dotty-compiler.
scalaVersion := scala212,
crossScalaVersions := List(dotty),
libraryDependencies += "ch.epfl.lamp" %% "dotty-compiler" % {
if (scalaVersion.value == scala212) s"$dotty-nonbootstrapped"
else dotty
}
)
.dependsOn(scalamacros)
lazy val pluginsScalac = project
.in(file("plugins/scalac"))
.settings(
pluginSettings,
crossScalaVersions := List(scala212),
moduleName := "scalac-plugin",
description := "Scalac integration for new-style Scala macros",
libraryDependencies += "org.scala-lang" % "scala-compiler" % scalaVersion.value,
libraryDependencies += "org.scalameta" %% "scalameta" % "2.0.1"
)
.dependsOn(enginesScalac)
lazy val testsApi = project
.in(file("tests/api"))
.settings(
noPublish,
description := "Tests of interfaces for new-style Scala macros",
libraryDependencies += "junit" % "junit" % "4.12",
libraryDependencies ++= (
if (isDotty.value) Seq("ch.epfl.lamp" %% "dotty-compiler" % scalaVersion.value)
else Seq("org.scala-lang" % "scala-reflect" % scalaVersion.value)
)
)
.dependsOn(scalamacros)
lazy val testsMacros = project
.in(file("tests/macros"))
.settings(
noPublish,
description := "Tests of new-style Scala macros",
crossScalaVersions := List(scala212, dotty),
scalacOptions += "-language:experimental.macros",
libraryDependencies ++= {
if (isDotty.value) {
Nil
} else {
"org.scala-lang" % "scala-reflect" % scalaVersion.value ::
compilerPlugin("org.scalamacros" %% "paradise" % "2.1.0" cross CrossVersion.full) ::
Nil
}
},
dependencyClasspath.in(Test) ++= dotcEngineClasspath.value,
scalacOptions ++= usesMacroSettings.value
)
.dependsOn(scalamacros)
lazy val usesMacroSettings: Def.Initialize[Task[Seq[String]]] = Def.taskDyn {
if (isDotty.value) {
Def.task {
if (sys.env.contains("CI")) {
// assert transformations respect Dotty compiler invariants
"-Ycheck:all" ::
Nil
} else Nil
}
} else {
Def.task {
val jar = Keys.`package`.in(pluginsScalac).in(Compile).value
val addPlugin = "-Xplugin:" + jar.getAbsolutePath
// Thanks Jason for this cool idea (taken from https://github.com/retronym/boxer)
// add plugin timestamp to compiler options to trigger recompile of
// main after editing the plugin. (Otherwise a 'clean' is needed.)
val dummy = "-Jdummy=" + jar.lastModified
Seq(addPlugin, dummy)
}
}
}
lazy val dotcEngineClasspath = Def.taskDyn[Classpath] {
if (isDotty.value) {
Def.task {
// NOTE(olafur) this is a temporary workaround to dynamically
// dependsOn(enginesDotc) only when scalaVersion:=dotty.
val _ = compile.in(enginesDotc, Compile).value
val cp =
classDirectory.in(enginesDotc, Compile).value
streams.value.log.info(cp.getAbsolutePath)
Attributed(cp)(AttributeMap.empty) :: Nil
}
} else {
Def.task(Nil)
}
}