-
Notifications
You must be signed in to change notification settings - Fork 30
/
CrossProjectExtra.scala
89 lines (75 loc) · 2.36 KB
/
CrossProjectExtra.scala
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
package sbtcrossproject
import java.io.File
import scala.reflect.macros.Context
import scala.language.experimental.macros
object CrossProjectExtra {
private[sbtcrossproject] def crossProject_impl(c: Context)(
platformsArgs: List[c.Expr[Platform]]): c.Expr[CrossProject.Builder] = {
import c.universe._
val enclosingValName = MacroUtils.definingValName(
c,
methodName =>
s"""$methodName must be directly assigned to a val, such as `val x = $methodName`.""")
val name = Literal(Constant(enclosingValName))
def javaIoFile =
reify { new _root_.java.io.File(c.Expr[String](name).splice) }.tree
val platforms =
if (!platformsArgs.isEmpty) platformsArgs.map(_.tree).toList
else {
// compatibility
val jsPlatform =
Select(
Select(
Ident(newTermName("_root_")),
newTermName("scalajscrossproject")
),
newTermName("JSPlatform")
)
val jvmPlatform =
Select(
Select(
Ident(newTermName("_root_")),
newTermName("sbtcrossproject")
),
newTermName("JVMPlatform")
)
List(jsPlatform, jvmPlatform)
}
val builderTerm =
Select(
Select(
Select(
Ident(newTermName("_root_")),
newTermName("sbtcrossproject")
),
newTermName("CrossProject")
),
newTypeName("Builder")
)
val constructor =
Select(
New(builderTerm),
nme.CONSTRUCTOR
)
c.Expr[CrossProject.Builder](
Apply(
constructor,
List(name, javaIoFile) ::: platforms
))
}
def oldCrossProject_impl(c: Context): c.Expr[CrossProject.Builder] = {
c.warning(c.enclosingPosition, "use crossProject(JSPlatform, JVMPlatform)")
crossProject_impl(c)(Nil)
}
def vargCrossProject_impl(c: Context)(
platforms: c.Expr[Platform]*): c.Expr[CrossProject.Builder] = {
import c.universe._
crossProject_impl(c)(platforms.toList)
}
}
trait CrossProjectExtra {
@deprecated("use crossProject(JSPlatform, JVMPlatform)", "0.1.0") def crossProject: CrossProject.Builder =
macro CrossProjectExtra.oldCrossProject_impl
def crossProject(platforms: Platform*): CrossProject.Builder =
macro CrossProjectExtra.vargCrossProject_impl
}