From 69d765744c92c4802856b18f3b72dfe1d8bd8454 Mon Sep 17 00:00:00 2001 From: Stephen Twigg Date: Thu, 18 Sep 2014 16:24:19 -0700 Subject: [PATCH] Adjustments to the build structure (see below) All 'addon' subprojects now have their sources aggregated into the addons subproject. This is done via a source copy (so that sbt will only rebuild sources that actually changed). To prevent caching issues the addons/src directory is CLEARED and then refilled every time addons is compiled. Thus, it is CRUCIAL NO SOURCES ARE MANUALLY ADDED TO addons/src AS THEY WILL BE WIPED BY addons/prepare. Due to sbt source caching, sbt will still be able to tell which sources have changed. (Strangely, sbt would not cache sources in extra unmanaged source directories and thus would always recompile them.) Also, cleaned up project/build.scala a bit to remove some warnings: Added import scala.language/postFixOps (so make! at the bottom no longer errors) and .toURI.toURL (as straight .toURL has been deprecated by the java standard library). --- addons/.gitignore | 2 ++ addons/DO_NOT_ADD_FILES_HERE.README | 3 +++ project/build.scala | 39 ++++++++++++++++++----------- 3 files changed, 29 insertions(+), 15 deletions(-) create mode 100644 addons/.gitignore create mode 100644 addons/DO_NOT_ADD_FILES_HERE.README diff --git a/addons/.gitignore b/addons/.gitignore new file mode 100644 index 00000000..28e79c2d --- /dev/null +++ b/addons/.gitignore @@ -0,0 +1,2 @@ +src +target diff --git a/addons/DO_NOT_ADD_FILES_HERE.README b/addons/DO_NOT_ADD_FILES_HERE.README new file mode 100644 index 00000000..b9b106dd --- /dev/null +++ b/addons/DO_NOT_ADD_FILES_HERE.README @@ -0,0 +1,3 @@ +ANY FILES ADDED HERE WILL BE DELETED + +The src directory is dynamically refreshed by the rocketchip project as part of the addons/prepare task. diff --git a/project/build.scala b/project/build.scala index b59b7685..aadd597e 100644 --- a/project/build.scala +++ b/project/build.scala @@ -1,5 +1,6 @@ import sbt._ import Keys._ +import scala.language.postfixOps //val extracted: Extracted = Project.extract(state) //import extracted._ @@ -26,27 +27,35 @@ object BuildSettings extends Build { //) ) - lazy val chisel = Project("chisel", file("chisel"), settings = buildSettings) - lazy val hardfloat = Project("hardfloat", file("hardfloat"), settings = buildSettings) dependsOn(chisel) - lazy val uncore = Project("uncore", file("uncore"), settings = buildSettings) dependsOn(hardfloat) - lazy val rocket = Project("rocket", file("rocket"), settings = buildSettings) dependsOn(uncore) + lazy val chisel = Project("chisel", file("chisel"), settings = buildSettings) + lazy val hardfloat = Project("hardfloat", file("hardfloat"), settings = buildSettings) dependsOn(chisel) + lazy val uncore = Project("uncore", file("uncore"), settings = buildSettings) dependsOn(hardfloat) + lazy val rocket = Project("rocket", file("rocket"), settings = buildSettings) dependsOn(uncore) val baselist = Vector("chisel", "uncore", "rocket", "hardfloat") - def show[A](in: Seq[A]) = in.map(_.toString).foldRight("")(_+" "+_) def getsubdirs = { - val blacklist = (baselist ++ Vector("target", "project")) + val blacklist = (baselist ++ Vector("target", "project", "addons")) IO.listFiles(file(".")) map (_.toString.split("/").last) filter (f=> !blacklist.contains(f)) filter (f=> !IO.listFiles(file(f+"/src/main/scala")).isEmpty) } - // def buildsubproj(sproj: String) = Project(sproj, file(sproj), settings = buildSettings).dependsOn(chisel, uncore, rocket, hardfloat) - // val subprojs = (getsubprojs map (sproj=>buildsubproj(sproj))) - // unfortunately, creating projects on the fly doesn't seem to quite work in sbt + val addonsources = getsubdirs map (f=>s"${f}/src/main/scala") map (f=>file(f)) + addonsources.foreach(a => println(s"[info] Found addon: " + a.toString.split("/").head)) - val othersources = getsubdirs map (f=>s"${f}/src/main/scala") map (f=>file(f)) - val addOtherFiles = Seq ( - unmanagedSourceDirectories in Compile ++= othersources.toSeq - ) // so instead, for dynamically expanding projects, just compile them all at once with rocket chip + val prepareTask = TaskKey[Unit]("prepare","Remove old sources and copy over new ones to addon/src") + def prepareTaskImpl = { + import IO._ + delete(file("addons/src")) + createDirectory(file("addons/src/main/scala")) + addonsources.foreach(as => { + val addonname = as.toString.split("/").head + copyDirectory(as, file("addons/src/main/scala/"+addonname)) + }) + } - lazy val rocketchip = Project("rocketchip", file("."), settings = buildSettings ++ chipSettings ++ addOtherFiles).dependsOn(chisel, hardfloat, uncore, rocket) + lazy val addons = Project("addons", file("addons"), settings = buildSettings ++ Seq( + prepareTask := prepareTaskImpl, + (compile in Compile) <<= (compile in Compile) dependsOn (prepareTask) + )) dependsOn(chisel, hardfloat, uncore, rocket) + lazy val rocketchip = Project("rocketchip", file("."), settings = buildSettings ++ chipSettings).dependsOn(chisel, uncore, rocket, addons) val elaborateTask = InputKey[Unit]("elaborate", "convert chisel components into backend source code") val makeTask = InputKey[Unit]("make", "trigger backend-specific makefile command") @@ -57,7 +66,7 @@ object BuildSettings extends Build { val projectName = pr.id val packageName = projectName //TODO: valid convention? val componentName = args(0) - val classLoader = new java.net.URLClassLoader(cp.map(_.data.toURL).toArray, cp.getClass.getClassLoader) + val classLoader = new java.net.URLClassLoader(cp.map(_.data.toURI.toURL).toArray, cp.getClass.getClassLoader) val chiselMainClass = classLoader.loadClass("Chisel.chiselMain$") val chiselMainObject = chiselMainClass.getDeclaredFields.head.get(null) val chiselMain = chiselMainClass.getMethod("run", classOf[Array[String]], classOf[Function0[_]])