summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSequencer2020-02-14 02:56:19 +0800
committerGitHub2020-02-13 13:56:19 -0500
commit84e5e7785c75094bc90ff9d1e4b61331b97ab90a (patch)
tree808192608b75ec490a8274d7962cc51529e1bb07
parentbcad26c3fd9b9afdf9b27b0d489fec4e910d3d44 (diff)
Fix mill build (#1324)
* add mill build * add gitignore and mill version
-rw-r--r--.gitignore2
-rw-r--r--CommonBuild.sc94
-rw-r--r--build.sc292
3 files changed, 91 insertions, 297 deletions
diff --git a/.gitignore b/.gitignore
index 7be06c1b..12a8e6f9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,7 +1,9 @@
+out/
generated/
/lib/firrtl.jar
.classpath
.idea
+.idea_modules/
.project
target/
*.iml
diff --git a/CommonBuild.sc b/CommonBuild.sc
deleted file mode 100644
index a9a4e1a2..00000000
--- a/CommonBuild.sc
+++ /dev/null
@@ -1,94 +0,0 @@
-import ammonite.ops._
-import mill._
-import mill.scalalib._
-
-def scalacOptionsVersion(scalaVersion: String): Seq[String] = {
- Seq() ++ {
- // If we're building with Scala > 2.11, enable the compile option
- // switch to support our anonymous Bundle definitions:
- // https://github.com/scala/bug/issues/10047
- if (scalaVersion.startsWith("2.11.")) {
- Seq()
- } else {
- Seq(
- "-Xsource:2.11",
- "-Ywarn-unused:imports",
- "-Ywarn-unused:locals"
- )
- }
- }
-}
-
-def javacOptionsVersion(scalaVersion: String): Seq[String] = {
- Seq() ++ {
- // Scala 2.12 requires Java 8. We continue to generate
- // Java 7 compatible code for Scala 2.11
- // for compatibility with old clients.
- if (scalaVersion.startsWith("2.11.")) {
- Seq("-source", "1.7", "-target", "1.7")
- } else {
- Seq("-source", "1.8", "-target", "1.8")
- }
- }
-}
-
-// Define our own BuildInfo since mill doesn't currently have one.
-trait BuildInfo extends ScalaModule { outer =>
-
- def buildInfoObjectName: String = "BuildInfo"
-
- def buildInfoMembers: T[Map[String, String]] = T {
- Map.empty[String, String]
- }
-
- private def generateBuildInfo(outputPath: Path, members: Map[String, String]) = {
- val outputFile = outputPath / "BuildInfo.scala"
- val packageName = members.getOrElse("buildInfoPackage", "")
- val packageDef = if (packageName != "") {
- s"package ${packageName}"
- } else {
- ""
- }
- val internalMembers =
- members
- .map {
- case (name, value) => s""" val ${name}: String = "${value}""""
- }
- .mkString("\n")
- write(outputFile,
- s"""
- |${packageDef}
- |case object ${buildInfoObjectName}{
- |$internalMembers
- | override val toString: String = {
- | "buildInfoPackage: %s, version: %s, scalaVersion: %s" format (
- | buildInfoPackage, version, scalaVersion
- | )
- | }
- |}
- """.stripMargin)
- outputPath
- }
-
- override def generatedSources = T {
- super.generatedSources() :+ PathRef(generateBuildInfo(T.ctx().dest, buildInfoMembers()))
- }
-}
-
-// Define some file filters to exclude unwanted files from created jars.
-type JarFileFilter = (Path, RelPath) => Boolean
-// Exclude any `.DS_Store` files
-val noDS_StoreFiles: JarFileFilter = (p: Path, relPath: RelPath) => {
- relPath.last != ".DS_Store"
-}
-
-// Exclude non-source files - accept all resource files, but only *.{java,scala} from source paths
-val onlySourceFiles: JarFileFilter = (p: Path, relPath: RelPath) => {
- p.last == "resources" || (relPath.ext == "scala" || relPath.ext == "java")
-}
-
-// Apply a sequence of file filters - only accept files which satisfy all filters.
-// We expect this to be curried, the resulting file filter passed to createJar()
-def forallFilters(fileFilters: Seq[JarFileFilter])(p: Path, relPath: RelPath): Boolean = {
- fileFilters.forall(f => f(p, relPath))
-}
diff --git a/build.sc b/build.sc
index f828479e..814a1df5 100644
--- a/build.sc
+++ b/build.sc
@@ -1,249 +1,135 @@
-import ammonite.ops._
-import ammonite.ops.ImplicitWd._
-import coursier.MavenRepository
+// Build script for mill 0.6.0
import mill._
import mill.scalalib._
import mill.scalalib.publish._
-import mill.eval.{Evaluator, Result}
-import mill.define.Task
-import mill.modules.Jvm._
+import coursier.maven.MavenRepository
+import $ivy.`com.lihaoyi::mill-contrib-buildinfo:$MILL_VERSION`
+import mill.contrib.buildinfo.BuildInfo
-import $file.CommonBuild
+object chisel3 extends mill.Cross[chisel3CrossModule]("2.11.12", "2.12.10")
-/** Utility types for changing a dependency between Ivy and Module (source) */
-sealed trait IvyOrModuleDep
-case class IvyDep(dep: Dep) extends IvyOrModuleDep
-case class ModuleDep(dep: PublishModule) extends IvyOrModuleDep
+// Since chisel contains submodule chiselFrontend and coreMacros, a CommonModule is needed
+trait CommonModule extends ScalaModule with SbtModule with PublishModule {
+ def firrtlModule: Option[PublishModule]
-object chiselCompileOptions {
- def scalacOptions = Seq(
- "-deprecation",
- "-explaintypes",
- "-feature",
- "-language:reflectiveCalls",
- "-unchecked",
- "-Xlint:infer-any"
-/* "-Xlint:missing-interpolator" // this causes a:
-//[error] .../chisel3/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala:605:48: recursive value outer needs type
-//[error] val outer = clazz.getDeclaredField("$outer").get(this)
-//[error] ^
-//[error] one error found
- */
- )
-}
+ def publishVersion = "3.3-SNAPSHOT"
-val crossVersions = Seq("2.12.10", "2.11.12")
+ // 2.12.10 -> Array("2", "12", "10") -> "12" -> 12
+ protected def majorVersion = crossVersion.split('.')(1).toInt
-// Provide a managed dependency on X if -DXVersion="" is supplied on the command line.
-val defaultVersions = Map("firrtl" -> "1.3-SNAPSHOT")
+ def crossVersion: String
-def getVersion(dep: String, org: String = "edu.berkeley.cs") = {
- val version = sys.env.getOrElse(dep + "Version", defaultVersions(dep))
- ivy"$org::$dep:$version"
-}
+ def scalaVersion = crossVersion
-// Define the common chisel module.
-trait CommonChiselModule extends SbtModule {
- // Normally defined in CrossSbtModule, our submodules don't have it by default
- def crossScalaVersion: String
- // This build uses an ivy dependency but allows overriding with a module (source) dependency
- def firrtlDep: IvyOrModuleDep
- override def scalacOptions = chiselCompileOptions.scalacOptions ++ CommonBuild.scalacOptionsVersion(crossScalaVersion)
- override def javacOptions = CommonBuild.javacOptionsVersion(crossScalaVersion)
- val macroPlugins = Agg(ivy"org.scalamacros:::paradise:2.1.0")
- def scalacPluginIvyDeps = macroPlugins
- def compileIvyDeps = macroPlugins
- def chiselDeps = firrtlDep match {
- case IvyDep(dep) => Agg(dep)
- case ModuleDep(_) => Agg()
+ def repositories() = super.repositories ++ Seq(
+ MavenRepository("https://oss.sonatype.org/content/repositories/snapshots"),
+ MavenRepository("https://oss.sonatype.org/content/repositories/releases")
+ )
+
+ private def scalacCrossOptions = majorVersion match {
+ case i if i < 12 => Seq()
+ case _ => Seq("-Xsource:2.11")
}
- override def ivyDeps = T { chiselDeps }
+
+ def ivyDeps = if(firrtlModule.isEmpty) Agg(
+ ivy"edu.berkeley.cs::firrtl:1.3-SNAPSHOT",
+ ) else Agg.empty[Dep]
- // Include sonatype snapshots by default for parity with sbt
- def repositories = super.repositories ++ Seq(
- MavenRepository("https://oss.sonatype.org/content/repositories/snapshots")
- )
-}
+ def moduleDeps = Seq() ++ firrtlModule
-trait PublishChiselModule extends CommonChiselModule with PublishModule {
- override def artifactName = "chisel3"
- def publishVersion = "3.3-SNAPSHOT"
+ private def javacCrossOptions = majorVersion match {
+ case i if i < 12 => Seq("-source", "1.7", "-target", "1.7")
+ case _ => Seq("-source", "1.8", "-target", "1.8")
+ }
+
+ override def scalacOptions = super.scalacOptions() ++ Agg(
+ "-deprecation",
+ "-feature"
+ ) ++ scalacCrossOptions
+
+ override def javacOptions = super.javacOptions() ++ javacCrossOptions
+
+ private val macroParadise = ivy"org.scalamacros:::paradise:2.1.0"
+
+ override def compileIvyDeps = Agg(macroParadise)
+
+ override def scalacPluginIvyDeps = Agg(macroParadise)
def pomSettings = PomSettings(
description = artifactName(),
organization = "edu.berkeley.cs",
- url = "https://chisel.eecs.berkeley.edu",
+ url = "https://www.chisel-lang.org",
licenses = Seq(License.`BSD-3-Clause`),
versionControl = VersionControl.github("freechipsproject", "chisel3"),
developers = Seq(
- Developer("jackbackrack", "Jonathan Bachrach", "https://eecs.berkeley.edu/~jrb/")
+ Developer("jackbackrack", "Jonathan Bachrach", "https://eecs.berkeley.edu/~jrb/")
)
)
}
-// Make this available to external tools.
-object chisel3 extends Cross[ChiselTopModule](crossVersions: _*) {
- def defaultVersion(ev: Evaluator) = T.command{
- println(crossVersions.head)
- }
-
- def compile = T{
- chisel3(crossVersions.head).compile()
- }
-
- def jar = T{
- chisel3(crossVersions.head).jar()
- }
-
- def test = T{
- chisel3(crossVersions.head).test.test()
- }
-
- def testOne(args: String*) = T.command {
- chisel3(crossVersions.head).test.testOne(args: _*)
- }
-
- def publishLocal = T{
- chisel3(crossVersions.head).publishLocal()
- }
-
- def docJar = T{
- chisel3(crossVersions.head).docJar()
- }
-}
-
-class ChiselTopModule(val crossScalaVersion: String) extends AbstractChiselModule {
- // This build uses an ivy dependency but allows overriding with a module (source) dependency
- def firrtlDep: IvyOrModuleDep = IvyDep(getVersion("firrtl"))
-}
+class chisel3CrossModule(crossVersionValue: String) extends CommonModule with PublishModule with BuildInfo { m =>
+ // different scala version shares same sources
+ // mill use foo/2.11.12 foo/2.12.10 as millSourcePath by default
+ override def millSourcePath = super.millSourcePath / os.up / os.up
-trait AbstractChiselModule extends PublishChiselModule with CommonBuild.BuildInfo with CrossSbtModule { top =>
+ def crossVersion = crossVersionValue
- // If would be nice if we didn't need to do this, but PublishModule may only be dependent on
- // other PublishModules.
- trait UnpublishedChiselModule extends PublishChiselModule
+ def mainClass = Some("chisel3.stage.ChiselMain")
+ def firrtlModule: Option[PublishModule] = None
- object coreMacros extends UnpublishedChiselModule {
- def crossScalaVersion = top.crossScalaVersion
- def scalaVersion = crossScalaVersion
- def firrtlDep: IvyOrModuleDep = top.firrtlDep
- }
-
- object chiselFrontend extends UnpublishedChiselModule {
- def crossScalaVersion = top.crossScalaVersion
- def scalaVersion = crossScalaVersion
- def moduleDeps = Seq(coreMacros) ++ (firrtlDep match {
- case ModuleDep(dep) => Seq(dep)
- case IvyDep(_) => Seq()
- })
- def firrtlDep: IvyOrModuleDep = top.firrtlDep
- }
-
- override def moduleDeps = Seq(coreMacros, chiselFrontend)
-
- // This submodule is unrooted - its source directory is in the top level directory.
- override def millSourcePath = super.millSourcePath / ammonite.ops.up
-
- // In order to preserve our "all-in-one" policy for published jars,
- // we define allModuleSources() to include transitive sources, and define
- // allModuleClasspath() to include transitive classes.
- def transitiveSources = T {
- Task.traverse(moduleDeps)(m =>
- T.task{m.allSources()}
- )().flatten
- }
-
- def allModuleSources = T {
- allSources() ++ transitiveSources()
- }
-
- def transitiveResources = T {
- Task.traverse(moduleDeps)(m =>
- T.task{m.resources()}
- )().flatten
- }
-
- def allModuleResources = T {
- resources() ++ transitiveResources()
- }
-
- // We package all classes in a singe jar.
- def allModuleClasspath = T {
- localClasspath() ++ transitiveLocalClasspath()
- }
+ override def moduleDeps = super.moduleDeps ++ Seq(coreMacros, chiselFrontend) ++ firrtlModule
+
+ object test extends Tests {
+ private def ivyCrossDeps = majorVersion match {
+ case i if i < 12 => Agg(ivy"junit:junit:4.12")
+ case _ => Agg()
+ }
- // Override publishXmlDeps so we don't include dependencies on our sub-modules.
- override def publishXmlDeps = T.task {
- val ivyPomDeps = ivyDeps().map(resolvePublishDependency().apply(_))
- ivyPomDeps
- }
+ def ivyDeps = Agg(
+ ivy"org.scalatest::scalatest:3.0.8",
+ ivy"org.scalacheck::scalacheck:1.14.3",
+ ivy"com.github.scopt::scopt:3.7.1"
+ ) ++ ivyCrossDeps
- // We need to copy (and override) the `jar` and `docJar` targets so we can build
- // single jars implementing our "all-in-one" policy.
- override def jar = T {
- createJar(
- allModuleClasspath().map(_.path).filter(exists),
- mainClass()
- )
+ def testFrameworks = Seq("org.scalatest.tools.Framework")
}
+ override def buildInfoPackageName = Some("chisel3")
- override def docJar = T {
- val outDir = T.ctx().dest
-
- val javadocDir = outDir / 'javadoc
- mkdir(javadocDir)
-
- val files = for{
- ref <- allModuleSources()
- if exists(ref.path)
- p <- (if (ref.path.isDir) ls.rec(ref.path) else Seq(ref.path))
- if (p.isFile && ((p.ext == "scala") || (p.ext == "java")))
- } yield p.toNIO.toString
-
- val pluginOptions = scalacPluginClasspath().map(pluginPathRef => s"-Xplugin:${pluginPathRef.path}")
- val options = Seq("-d", javadocDir.toNIO.toString, "-usejavacp") ++ pluginOptions ++ scalacOptions()
-
- if (files.nonEmpty) runSubprocess(
- "scala.tools.nsc.ScalaDoc",
- scalaCompilerClasspath().map(_.path) ++ compileClasspath().filter(_.path.ext != "pom").map(_.path),
- mainArgs = (files ++ options).toSeq
+ override def buildInfoMembers: T[Map[String, String]] = T {
+ Map(
+ "buildInfoPackage" -> artifactName(),
+ "version" -> publishVersion(),
+ "scalaVersion" -> scalaVersion()
)
-
- createJar(Agg(javadocDir), None)(outDir)
}
- def sourceJar = T {
- createJar((allModuleSources() ++ allModuleResources()).map(_.path).filter(exists), None)
+ override def generatedSources = T {
+ Seq(generatedBuildInfo()._2)
}
- override def ivyDeps = Agg(
- ivy"com.github.scopt::scopt:3.7.1"
- ) ++ chiselDeps
+ object coreMacros extends CommonModule {
+ def firrtlModule = m.firrtlModule
- object test extends Tests {
- override def ivyDeps = Agg(
- ivy"org.scalatest::scalatest:3.0.8",
- ivy"org.scalacheck::scalacheck:1.14.3"
- )
- def testFrameworks = Seq("org.scalatest.tools.Framework")
+ def crossVersion = crossVersionValue
+ }
- def testOne(args: String*) = T.command {
- super.runMain("org.scalatest.run", args: _*)
- }
+ object chiselFrontend extends CommonModule {
+ def firrtlModule = m.firrtlModule
- }
+ def crossVersion = crossVersionValue
- // This is required for building a library, but not for a `run` target.
- // In the latter case, mill will determine this on its own.
- def mainClass = Some("chisel3.Driver")
+ def moduleDeps = super.moduleDeps ++ Seq(coreMacros) ++ firrtlModule
- override def buildInfoMembers = T {
- Map[String, String](
- "buildInfoPackage" -> artifactName(),
- "version" -> publishVersion(),
- "scalaVersion" -> scalaVersion()
+ def scalacOptions = super.scalacOptions() ++ Seq(
+ "-deprecation",
+ "-explaintypes",
+ "-feature",
+ "-language:reflectiveCalls",
+ "-unchecked",
+ "-Xcheckinit",
+ "-Xlint:infer-any"
)
}
}