From 791cb363b77332e3abdf4039102dfcdb863ce6c3 Mon Sep 17 00:00:00 2001 From: Jakob Odersky Date: Mon, 2 May 2016 05:19:07 -0700 Subject: Use macro annotation to load native library This also removes the need for third projects to depend on a "loader library". --- project/Build.scala | 64 ----------------------------------- project/SbtJniBuild.scala | 86 +++++++++++++++++++++++++++++++++++++++++++++++ project/build.properties | 2 +- project/plugins.sbt | 9 +++-- 4 files changed, 94 insertions(+), 67 deletions(-) delete mode 100644 project/Build.scala create mode 100644 project/SbtJniBuild.scala (limited to 'project') diff --git a/project/Build.scala b/project/Build.scala deleted file mode 100644 index 377730d..0000000 --- a/project/Build.scala +++ /dev/null @@ -1,64 +0,0 @@ -import sbt._ -import sbt.Keys._ - -import bintray.BintrayPlugin.autoImport._ -import sbtdoge.CrossPerProjectPlugin - -object JniBuild extends Build { - - val scalaVersions = List("2.11.8", "2.12.0-M4", "2.12.0-M3", "2.10.6") - - val commonSettings = Seq( - version := "0.4.5-SNAPSHOT", - organization := "ch.jodersky", - licenses := Seq(("BSD New", url("http://opensource.org/licenses/BSD-3-Clause"))), - scalacOptions ++= Seq("-deprecation", "-feature") - ) - - lazy val root = Project( - id = "root", - base = file("."), - aggregate = Seq( - library, plugin - ), - settings = Seq( - publish := {}, - publishLocal := {}, - publishTo := Some(Resolver.file("Unused transient repository", target.value / "unusedrepo")) // make sbt-pgp happy - ) - ).enablePlugins(CrossPerProjectPlugin) - - lazy val library = Project( - id = "jni-library", - base = file("jni-library"), - settings = commonSettings ++ Seq( - scalaVersion := scalaVersions.head, - crossScalaVersions := scalaVersions - ) - ) - - lazy val plugin = Project( - id = "sbt-jni", - base = file("jni-plugin"), - dependencies = Seq(library), - settings = commonSettings ++ Seq( - sbtPlugin := true, - sourceGenerators in Compile += Def.task{ - val src = s"""|package ch.jodersky.sbt.jni - | - |private object Version { - | final val PluginVersion = "${version.value}" - |} - |""".stripMargin - val file = sourceManaged.value / "ch" / "jodersky" / "sbt" / "jni" / "Version.scala" - IO.write(file, src) - Seq(file) - }.taskValue, - libraryDependencies += "org.ow2.asm" % "asm" % "5.0.4", - publishMavenStyle := false, - bintrayRepository := "sbt-plugins", - bintrayOrganization in bintray := None - ) - ) - -} diff --git a/project/SbtJniBuild.scala b/project/SbtJniBuild.scala new file mode 100644 index 0000000..3961eda --- /dev/null +++ b/project/SbtJniBuild.scala @@ -0,0 +1,86 @@ +import sbt._ +import sbt.Keys._ +import sbt.ScriptedPlugin._ + +import sbtdoge.CrossPerProjectPlugin + +import scalariform.formatter.preferences._ +import com.typesafe.sbt.SbtScalariform +import com.typesafe.sbt.SbtScalariform.ScalariformKeys + +object SbtJniBuild extends Build { + + val scalaVersions: Seq[String] = List("2.11.8", "2.12.0-M4") + val macrosParadiseVersion = "2.1.0" + + val commonSettings = Seq( + version := "1.0.0-SNAPSHOT", + organization := "ch.jodersky", + licenses := Seq(("BSD New", url("http://opensource.org/licenses/BSD-3-Clause"))), + scalacOptions ++= Seq("-deprecation", "-feature"), + resolvers += Resolver.sonatypeRepo("releases"), + ScalariformKeys.preferences := ScalariformKeys.preferences.value + .setPreference(DoubleIndentClassDeclaration, true) + .setPreference(DanglingCloseParenthesis, Preserve) + .setPreference(MultilineScaladocCommentsStartOnFirstLine, true) + .setPreference(PlaceScaladocAsterisksBeneathSecondAsterisk, true) + ) + + lazy val root = Project( + id = "root", + base = file("."), + aggregate = Seq( + macros, plugin + ), + settings = commonSettings ++ Seq( + publish := {}, + publishLocal := {}, + // make sbt-pgp happy + publishTo := Some(Resolver.file("Unused transient repository", target.value / "unusedrepo")) + ) ++ addCommandAlias("test-plugin", ";+sbt-jni-macros/publishLocal;scripted") + ).enablePlugins(CrossPerProjectPlugin) + + lazy val macros = Project( + id = "sbt-jni-macros", + base = file("macros"), + settings = commonSettings ++ Seq( + scalaVersion := scalaVersions.head, + crossScalaVersions := scalaVersions, + addCompilerPlugin("org.scalamacros" % "paradise" % macrosParadiseVersion cross CrossVersion.full), + libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value + ) + ) + + lazy val plugin = Project( + id = "sbt-jni", + base = file("plugin"), + settings = commonSettings ++ scriptedSettings ++ Seq( + sbtPlugin := true, + publishMavenStyle := false, + scalaVersion := "2.10.6", + crossScalaVersions := Seq(scalaVersion.value), + + libraryDependencies += "org.ow2.asm" % "asm" % "5.0.4", + + // make project settings available to source + sourceGenerators in Compile += Def.task{ + val src = s"""|/* Generated by sbt */ + |package ch.jodersky.sbt.jni + | + |private[jni] object ProjectVersion { + | final val MacrosParadise = "${macrosParadiseVersion}" + | final val Macros = "${version.value}" + |} + |""".stripMargin + val file = sourceManaged.value / "ch" / "jodersky" / "sbt" / "jni" / "ProjectVersion.scala" + IO.write(file, src) + Seq(file) + }.taskValue, + scriptedLaunchOpts := Seq( + "-Dplugin.version=" + version.value, + "-XX:MaxPermSize=256m", "-Xmx2g", "-Xss2m" + ) + ) + ) + +} diff --git a/project/build.properties b/project/build.properties index 817bc38..43b8278 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=0.13.9 +sbt.version=0.13.11 diff --git a/project/plugins.sbt b/project/plugins.sbt index 391c9ab..19a16f4 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,3 +1,8 @@ -addSbtPlugin("me.lessis" % "bintray-sbt" % "0.3.0") - +// cross-compile subprojects with differing scala versions addSbtPlugin("com.eed3si9n" % "sbt-doge" % "0.1.5") + +// testing for sbt plugins +libraryDependencies += "org.scala-sbt" % "scripted-plugin" % sbtVersion.value + +// formatting +addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.6.0") -- cgit v1.2.3