From 0c8aeb14324142aece22a247ddc4e66ecc27219e Mon Sep 17 00:00:00 2001 From: Adam Rosenberger Date: Fri, 16 May 2014 13:16:00 -0400 Subject: [PATCH 1/2] Add `make` as a compile task in the generator project, remove capnpc-java binary when `sbt clean` is run --- .gitignore | 2 ++ Makefile | 5 ++--- project/build.scala | 29 ++++++++++++++++++----------- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 22e1a96..6769493 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ project/target .idea *.ipr *.iws +capnpc-java +generated/ \ No newline at end of file diff --git a/Makefile b/Makefile index 375d713..2b3860e 100644 --- a/Makefile +++ b/Makefile @@ -5,11 +5,10 @@ CAPNPC_JAVA_SOURCES=generator/src/main/cpp/compiler/capnpc-java.c++ .PHONY: all clean addressbook -all : capnpc-java addressbook +all : capnpc-java clean : rm capnpc-java - sbt clean capnpc-java : $(CAPNPC_JAVA_SOURCES) $(CXX) $(CAPNPC_JAVA_SOURCES) $(CXX_FLAGS) -g -o capnpc-java @@ -18,4 +17,4 @@ addressbook : capnpc-java PWD=pwd mkdir -p examples/src/main/generated capnp compile -I$(PWD)/generator/src/main/cpp/compiler --src-prefix=examples/src/main/schema -o./capnpc-java:examples/src/main/generated examples/src/main/schema/addressbook.capnp - sbt examples/"compile" + sbt examples/compile diff --git a/project/build.scala b/project/build.scala index 4a66949..e019cb8 100644 --- a/project/build.scala +++ b/project/build.scala @@ -1,6 +1,5 @@ import sbt.Keys._ import sbt._ -import org.sbtidea.SbtIdeaPlugin._ object Build extends sbt.Build { @@ -9,25 +8,27 @@ object Build extends sbt.Build { id = "capnproto-java", base = file(".") ).aggregate(generator, examples) + .settings(cleanFiles <+= baseDirectory { base => base / "capnpc-java"}) lazy val generator = project( id = "generator", base = file("generator") ).settings(Defaults.itSettings: _*) - .settings(compile <<= compile in Compile dependsOn(compile in Test, compile in IntegrationTest)) + .settings(makeCppTask) + .settings(compile <<= compile in Compile dependsOn makeCpp) lazy val examples = project( id = "examples", base = file("examples") ).dependsOn(generator) - .settings(unmanagedSourceDirectories in Compile += sourceDirectory.value / "main" / "generated") - .settings(publish := {}) - .settings(publishLocal := {}) - .settings(fork in run := true) - .settings(outputStrategy := Some(StdoutOutput)) - .settings(javaOptions in run ++= Seq( + .settings(unmanagedSourceDirectories in Compile += sourceDirectory.value / "main" / "generated") + .settings(publish := {}) + .settings(publishLocal := {}) + .settings(fork in run := true) + .settings(outputStrategy := Some(StdoutOutput)) + .settings(javaOptions in run ++= Seq( "-ms2g", "-mx2g", "-XX:+AlwaysPreTouch", @@ -43,6 +44,12 @@ object Build extends sbt.Build { Shared.settings ++ Seq(libraryDependencies ++= Shared.testDeps) ).configs(IntegrationTest) + + val makeCpp = taskKey[Unit]("Run make against the C++ code to create the Java code generator") + val makeCppTask = makeCpp := { + val makeResult = "make".!! + println(s"**** C++ Build Started\n$makeResult\n**** C++ Build Complete") + } } object Shared { @@ -76,9 +83,9 @@ object ShellPrompt { } def currBranch = ( - ("git status -sb" lines_! devnull headOption) - getOrElse "-" stripPrefix "## " - ) + ("git status -sb" lines_! devnull headOption) + getOrElse "-" stripPrefix "## " + ) val buildShellPrompt = { (state: State) => { From 37698ab8b670de4ece554b15062c67587bc3ae72 Mon Sep 17 00:00:00 2001 From: Adam Rosenberger Date: Fri, 16 May 2014 17:03:03 -0400 Subject: [PATCH 2/2] Fix bug where clean doesn't remove generated code, then fix the resulting compile which requires code generation to complete. --- Makefile | 1 - project/build.scala | 20 ++++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 2b3860e..aab59ed 100644 --- a/Makefile +++ b/Makefile @@ -17,4 +17,3 @@ addressbook : capnpc-java PWD=pwd mkdir -p examples/src/main/generated capnp compile -I$(PWD)/generator/src/main/cpp/compiler --src-prefix=examples/src/main/schema -o./capnpc-java:examples/src/main/generated examples/src/main/schema/addressbook.capnp - sbt examples/compile diff --git a/project/build.scala b/project/build.scala index e019cb8..9a826f9 100644 --- a/project/build.scala +++ b/project/build.scala @@ -23,17 +23,10 @@ object Build extends sbt.Build { id = "examples", base = file("examples") ).dependsOn(generator) + .settings(makeExamplesTask) + .settings(compile <<= compile in Compile dependsOn makeExamples) .settings(unmanagedSourceDirectories in Compile += sourceDirectory.value / "main" / "generated") - .settings(publish := {}) - .settings(publishLocal := {}) - .settings(fork in run := true) - .settings(outputStrategy := Some(StdoutOutput)) - .settings(javaOptions in run ++= Seq( - "-ms2g", - "-mx2g", - "-XX:+AlwaysPreTouch", - "-XX:+TieredCompilation" - )) + .settings(cleanFiles += sourceDirectory.value / "main" / "generated") def project(id: String, base: File) = Project( @@ -50,6 +43,13 @@ object Build extends sbt.Build { val makeResult = "make".!! println(s"**** C++ Build Started\n$makeResult\n**** C++ Build Complete") } + + val makeExamples = taskKey[Unit]("Run capnp-java compiler against the addressbook schema") + val makeExamplesTask = makeExamples := { + Thread.sleep(1000) + val makeResult = "make addressbook".!! + println(s"**** CodeGen for Addressbook Started\n$makeResult\n**** CodeGen for Addressbook Complete") + } } object Shared {