aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Odersky <jodersky@gmail.com>2013-06-30 14:53:08 +0200
committerJakob Odersky <jodersky@gmail.com>2013-06-30 14:53:08 +0200
commit6fa2c93ca687e8900b00bb1403588107c7f63cbd (patch)
treedfa1eeb1699785430071713cac4c0dbff00a11fd
parentfd4f431ed68b8d073ed36eeafc7d8a2b80d99c10 (diff)
downloadakka-serial-6fa2c93ca687e8900b00bb1403588107c7f63cbd.tar.gz
akka-serial-6fa2c93ca687e8900b00bb1403588107c7f63cbd.tar.bz2
akka-serial-6fa2c93ca687e8900b00bb1403588107c7f63cbd.zip
build automatically pulls in newest binaries
-rw-r--r--project/Build.scala78
1 files changed, 60 insertions, 18 deletions
diff --git a/project/Build.scala b/project/Build.scala
index d80e0f4..ab2e42a 100644
--- a/project/Build.scala
+++ b/project/Build.scala
@@ -33,14 +33,43 @@ object FlowBuild extends Build {
Dependencies.ioCore,
Dependencies.ioFile),
compileOrder in Compile := CompileOrder.Mixed,
- resourceGenerators in Compile <+= (resourceManaged in Compile, link in Native in getOsProject) map { (resDir, binary) =>
- val file = canonicalBinaryPath(resDir / "native", binary.getName)
- IO.copyFile(binary, file)
- Seq(file)
+ resourceGenerators in Compile <+= (resourceManaged in Compile, binariesDirectory in ThisBuild) map { (resDir, binDir) =>
+ val binaries: Seq[(File, File)] = getLatestBinaries(binDir, BinaryMajorVersion)
+ val resources = for (binary <- binaries) yield {
+ val versionedBinary = binary._1
+ val unversionedBinary = binary._2
+
+ val relative = (unversionedBinary relativeTo binDir).get.getPath
+
+ val resource = resDir / "native" / relative
+ IO.copyFile(versionedBinary, resource)
+ resource
+ }
+ resources
}
)
)
+ def getLatestBinaries(base: File, majorVersion: Int): Seq[(File, File)] = {
+ def latest(platform: File) = {
+ val Pattern = "(.+)\\.(\\d+)\\.(\\d+)".r
+ val MajorVersion = majorVersion.toString
+ val majorCompatible = platform.listFiles.map(_.getAbsolutePath) collect {
+ case path @ Pattern(strippedPath, MajorVersion, minorVersion) => (path, strippedPath, minorVersion)
+ }
+ val latestMinor = majorCompatible.sortBy(_._3).lastOption
+ latestMinor map { case (path, strippedPath, _) =>
+ (file(path), file(strippedPath))
+ }
+ }
+
+ val oSs = base.listFiles
+ val platforms = oSs.flatMap(_.listFiles)
+
+ platforms.flatMap(latest(_))
+ }
+
+
lazy val rwc = (
Project("flow-samples-rwc", file("flow-samples") / "rwc")
settings(commonSettings: _*)
@@ -51,28 +80,24 @@ object FlowBuild extends Build {
//--- native settings --------------------------------------------------
- def getOsProject = {
- sys.props("os.name").toLowerCase match {
- case "linux" => LocalProject("flow-native-linux") //use local project to avoid stackoverflow on cyclic dependencies
- case _ => throw new Exception("There is no native project defined for your current OS." +
- " Have a look at the project flow-native-linux to see how to create one yourself. You may ignore this error by commenting " +
- "the relevant lines in project/Build.scala, however by doing so, compiling native sources may miserably fail!")
- }
- }
-
+ val binariesDirectory = settingKey[File]("Directory containing published native binaries.")
+ override lazy val settings = super.settings ++ Seq(
+ (binariesDirectory in ThisBuild) := (baseDirectory in ThisBuild).value / "flow-binaries"
+ )
+
def canonicalBinaryPath(base: File, binaryName: String) = {
base / sys.props("os.name").toLowerCase / sys.props("os.arch").toLowerCase / binaryName
- }
-
+ }
val publishNative = taskKey[File]("Publish native binary compiled on current OS to flow-binaries project so that it may be packaged in a distribution of flow.")
val publishNativeImpl = Def.task{
val in = (link in Native).value
- val out = canonicalBinaryPath((baseDirectory in ThisBuild).value / "flow-binaries", in.getName)
+ val out = canonicalBinaryPath((binariesDirectory in ThisBuild).value, in.getName)
IO.copyFile(in, out)
out
}
lazy val commonNativeSettings: Seq[Setting[_]] = Seq(
+ nativeSource in Native := baseDirectory.value / "src",
includeDirectories in Native += file("flow-native") / "shared" / "include",
nativeCompile in Native := ((nativeCompile in Native) dependsOn (compile in Compile in main)).value,
publishNative := publishNativeImpl.value,
@@ -87,8 +112,7 @@ object FlowBuild extends Build {
lazy val unixNativeSettings: Seq[Setting[_]] = commonNativeSettings ++ Seq(
flags in Native := Seq("-fPIC", "-O2"),
linkFlags in Native ++= Seq("-shared", s"-Wl,-soname,libflow.so.${BinaryMajorVersion}"),
- binaryName in Native := s"libflow.so.${BinaryMajorVersion}.${UnixBinaryMinorVersion}",
- nativeSource in Native := baseDirectory.value / "src")
+ binaryName in Native := s"libflow.so.${BinaryMajorVersion}.${UnixBinaryMinorVersion}")
lazy val nativeLinux = (
NativeProject("flow-native-linux", file("flow-native") / "unix")
@@ -109,4 +133,22 @@ object FlowBuild extends Build {
dependsOn (main)
)*/
+
+ /* stub for native project on windows, I don't know if this would actually work...
+ *
+ * val WindowsBinaryMinorVersion = 0
+ *
+ lazy val nativeWindows = (
+ NativeProject("flow-native-windows", file("flow-native") / "windows") //note: change from unix to windows
+ settings (
+ //windows is not a unix-like OS, several default settings need to be changed
+ cCompiler in Native := "???",
+ flags in Native := Seq("-fPIC", "-O2"),
+ linkFlags in Native ++= ???,
+ binaryName in Native := s"flow.dll.${BinaryMajorVersion}.${WindowsBinaryMinorVersion}"
+ includeDirectories in Native += jdkHome.value / "include" / "windows"
+ )
+ dependsOn (main)
+ )*/
+
}