Skip to content

Commit

Permalink
ScalaCompiler: Include plug-ins from platform modules
Browse files Browse the repository at this point in the history
Closes #16.
  • Loading branch information
tindzk committed Jul 19, 2019
1 parent e85a3d0 commit d5dfa68
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/main/scala/seed/generation/util/ScalaCompiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ object ScalaCompiler {
(if (platform == JavaScript) List(Artefact.ScalaJsCompiler)
else if (platform == Native) List(Artefact.ScalaNativePlugin)
else List()
) ++ modules.flatMap(_.compilerDeps.map(Artefact.fromDep))
) ++
// TODO Make sure that the plug-ins are not added twice
modules
.flatMap(m => BuildConfig.platformModule(m, platform).toList :+ m)
.flatMap(_.compilerDeps.map(Artefact.fromDep))

artefacts.map(a => resolveCompiler(
build, module, compilerResolution, a, platform, compilerVer)
Expand Down
14 changes: 13 additions & 1 deletion src/test/scala/seed/generation/BloopIntegrationSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ object BloopIntegrationSpec extends TestSuite[Unit] {
compileAndRun(projectPath)
}

testAsync("Build project with compiler plug-in") { _ =>
testAsync("Build project with compiler plug-in defined on cross-platform module") { _ =>
val BuildConfig.Result(build, projectPath, _) = BuildConfig.load(
Paths.get("test/example-paradise"), Log.urgent).get
val buildPath = projectPath.resolve("build")
Expand All @@ -59,6 +59,18 @@ object BloopIntegrationSpec extends TestSuite[Unit] {
compileAndRun(projectPath)
}

testAsync("Build project with compiler plug-in defined on platform modules") { _ =>
val BuildConfig.Result(build, projectPath, _) = BuildConfig.load(
Paths.get("test/example-paradise-platform"), Log.urgent).get
val buildPath = projectPath.resolve("build")
if (Files.exists(buildPath)) FileUtils.deleteDirectory(buildPath.toFile)
val packageConfig = PackageConfig(tmpfs = false, silent = false,
ivyPath = None, cachePath = None)
cli.Generate.ui(Config(), projectPath, build, Command.Bloop(packageConfig),
Log.urgent)
compileAndRun(projectPath)
}

testAsync("Build modules with different Scala versions") { _ =>
val BuildConfig.Result(build, projectPath, _) = BuildConfig.load(
Paths.get("test/multiple-scala-versions"), Log.urgent).get
Expand Down
26 changes: 26 additions & 0 deletions test/example-paradise-platform/build.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# See https://github.com/tindzk/seed/issues/16
[project]
scalaVersion = "2.11.12"
scalaJsVersion = "0.6.26"
scalaOptions = ["-encoding", "UTF-8", "-unchecked", "-deprecation", "-Xfuture"]

[module.macros]
root = "macros"
sources = ["macros"]
targets = ["jvm", "js"]

[module.macros.jvm]
compilerDeps = [
["org.scalamacros", "paradise", "2.1.1", "full"]
]

[module.macros.js]
compilerDeps = [
["org.scalamacros", "paradise", "2.1.1", "full"]
]

[module.example]
root = "example"
sources = ["example"]
targets = ["jvm", "js"]
moduleDeps = ["macros"]
4 changes: 4 additions & 0 deletions test/example-paradise-platform/example/Test.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@hello
object Test extends App {
println(this.hello)
}
26 changes: 26 additions & 0 deletions test/example-paradise-platform/macros/Macros.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import scala.reflect.macros.blackbox
import scala.language.experimental.macros
import scala.annotation.StaticAnnotation

object helloMacro {
def impl(c: blackbox.Context)(annottees: c.Expr[Any]*): c.Expr[Any] = {
import c.universe._
import Flag._
val result = {
annottees.map(_.tree).toList match {
case q"object $name extends ..$parents { ..$body }" :: Nil =>
q"""
object $name extends ..$parents {
def hello: ${typeOf[String]} = "hello"
..$body
}
"""
}
}
c.Expr[Any](result)
}
}

class hello extends StaticAnnotation {
def macroTransform(annottees: Any*): Any = macro helloMacro.impl
}

0 comments on commit d5dfa68

Please sign in to comment.