summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMinghao Liu <molikto@gmail.com>2018-01-12 14:43:53 +0800
committerLi Haoyi <haoyi.sg@gmail.com>2018-01-11 22:43:53 -0800
commite8f53585e555cec800063cddc763a2837f4c5260 (patch)
treed52052274fc63f8e8dfdeddb67baaea2959ba2cd
parentf084c2059f1c21c3ac7726f4d06881d6fba7d341 (diff)
downloadmill-e8f53585e555cec800063cddc763a2837f4c5260.tar.gz
mill-e8f53585e555cec800063cddc763a2837f4c5260.tar.bz2
mill-e8f53585e555cec800063cddc763a2837f4c5260.zip
Add generated sources target (#109)
* add generated source * naming * multiple content root * no message * fix output classes path
-rw-r--r--build.sbt4
-rwxr-xr-xbuild.sc14
-rw-r--r--scalalib/src/main/scala/mill/scalalib/GenIdea.scala34
-rw-r--r--scalalib/src/main/scala/mill/scalalib/Module.scala5
-rw-r--r--shared.sc4
5 files changed, 40 insertions, 21 deletions
diff --git a/build.sbt b/build.sbt
index 856972dd..bd4c0bb7 100644
--- a/build.sbt
+++ b/build.sbt
@@ -96,13 +96,13 @@ lazy val core = project
"org.scala-sbt" % "test-interface" % "1.0"
),
sourceGenerators in Compile += {
- ammoniteRun(sourceManaged in Compile, List("shared.sc", "generateSources", _))
+ ammoniteRun(sourceManaged in Compile, List("shared.sc", "generateCoreSources", _))
.taskValue
.map(x => (x ** "*.scala").get)
},
sourceGenerators in Test += {
- ammoniteRun(sourceManaged in Test, List("shared.sc", "generateTests", _))
+ ammoniteRun(sourceManaged in Test, List("shared.sc", "generateCoreTestSources", _))
.taskValue
.map(x => (x ** "*.scala").get)
}
diff --git a/build.sc b/build.sc
index 29eb53bf..234f24a9 100755
--- a/build.sc
+++ b/build.sc
@@ -58,22 +58,22 @@ object core extends MillModule {
Dep.Java("org.scala-sbt", "test-interface", "1.0")
)
- def generatedSources = T{
+ def generatedCoreSources = T{
mkdir(T.ctx().dest)
- shared.generateSources(T.ctx().dest)
+ shared.generateCoreSources(T.ctx().dest)
PathRef(T.ctx().dest)
}
- def allSources = super.allSources() ++ Seq(generatedSources())
+ def generatedSources = T { super.generatedSources() ++ Seq(generatedCoreSources()) }
+
val test = new Tests(implicitly)
class Tests(ctx0: mill.Module.Ctx) extends super.Tests(ctx0){
- def generatedSources = T{
+ def generatedCoreTestSources = T{
mkdir(T.ctx().dest)
- shared.generateTests(T.ctx().dest)
+ shared.generateCoreTestSources(T.ctx().dest)
PathRef(T.ctx().dest)
-
}
- def allSources = super.allSources() ++ Seq(generatedSources())
+ def generatedSources = T { super.generatedSources() ++ Seq(generatedCoreTestSources()) }
}
}
diff --git a/scalalib/src/main/scala/mill/scalalib/GenIdea.scala b/scalalib/src/main/scala/mill/scalalib/GenIdea.scala
index 54c1b3ac..24daef2c 100644
--- a/scalalib/src/main/scala/mill/scalalib/GenIdea.scala
+++ b/scalalib/src/main/scala/mill/scalalib/GenIdea.scala
@@ -72,8 +72,11 @@ object GenIdea {
}
val moduleFiles = resolved.map{ case (path, resolvedDeps, mod) =>
- val Seq(sourcePath: PathRef) =
- evaluator.evaluate(OSet(mod.sources)).values
+ val Seq(sourcesPathRef: PathRef, generatedSourcePathRefs: Seq[PathRef], allSourcesPathRefs: Seq[PathRef]) =
+ evaluator.evaluate(OSet(mod.sources, mod.generatedSources, mod.allSources)).values
+
+ val generatedSourcePaths = generatedSourcePathRefs.map(_.path)
+ val normalSourcePaths = (allSourcesPathRefs.map(_.path).toSet -- generatedSourcePaths.toSet).toSeq
val paths = Evaluator.resolveDestPaths(
evaluator.workspacePath,
@@ -81,7 +84,9 @@ object GenIdea {
)
val elem = moduleXmlTemplate(
- sourcePath.path,
+ sourcesPathRef.path,
+ normalSourcePaths,
+ generatedSourcePaths,
Seq(paths.out),
resolvedDeps.map(pathToLibName),
for(m <- mod.projectDeps)
@@ -150,7 +155,9 @@ object GenIdea {
</library>
</component>
}
- def moduleXmlTemplate(sourcePath: Path,
+ def moduleXmlTemplate(basePath: Path,
+ normalSourcePaths: Seq[Path],
+ generatedSourcePaths: Seq[Path],
outputPaths: Seq[Path],
libNames: Seq[String],
depNames: Seq[String]) = {
@@ -158,13 +165,24 @@ object GenIdea {
<component name="NewModuleRootManager">
{
for(outputPath <- outputPaths)
- yield <output url={"file://$MODULE_DIR$/" + relify(outputPath)} />
+ yield <output url={"file://$MODULE_DIR$/" + relify(outputPath) + "/dest/classes"} />
}
<exclude-output />
- <content url={"file://$MODULE_DIR$/" + relify(sourcePath)}>
- <sourceFolder url={"file://$MODULE_DIR$/" + relify(sourcePath)} isTestSource="false" />
- </content>
+ {
+ for (normalSourcePath <- normalSourcePaths)
+ yield
+ <content url={"file://$MODULE_DIR$/" + relify(normalSourcePath)}>
+ <sourceFolder url={"file://$MODULE_DIR$/" + relify(normalSourcePath)} isTestSource="false" />
+ </content>
+ }
+ {
+ for (generatedSourcePath <- generatedSourcePaths)
+ yield
+ <content url={"file://$MODULE_DIR$/" + relify(generatedSourcePath)}>
+ <sourceFolder url={"file://$MODULE_DIR$/" + relify(generatedSourcePath)} isTestSource="false" generated="true" />
+ </content>
+ }
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
diff --git a/scalalib/src/main/scala/mill/scalalib/Module.scala b/scalalib/src/main/scala/mill/scalalib/Module.scala
index dbccbec1..4437c08f 100644
--- a/scalalib/src/main/scala/mill/scalalib/Module.scala
+++ b/scalalib/src/main/scala/mill/scalalib/Module.scala
@@ -193,7 +193,8 @@ trait Module extends mill.Module with TaskModule { outer =>
def sources = T.source{ basePath / 'src }
def resources = T.source{ basePath / 'resources }
- def allSources = T{ Seq(sources()) }
+ def generatedSources = T { Seq.empty[PathRef] }
+ def allSources = T{ Seq(sources()) ++ generatedSources() }
def compile: T[CompilationResult] = T.persistent{
compileScala(
ZincWorker(),
@@ -361,7 +362,7 @@ trait PublishModule extends Module { outer =>
trait SbtModule extends Module { outer =>
override def sources = T.source{ basePath / 'src / 'main / 'scala }
override def resources = T.source{ basePath / 'src / 'main / 'resources }
- trait Tests extends super.Tests{
+ trait Tests extends super.Tests {
override def basePath = outer.basePath
override def sources = T.source{ basePath / 'src / 'test / 'scala }
override def resources = T.source{ basePath / 'src / 'test / 'resources }
diff --git a/shared.sc b/shared.sc
index a0061f65..ef2f26d3 100644
--- a/shared.sc
+++ b/shared.sc
@@ -133,14 +133,14 @@ def unpackZip(zipDest: Path, url: String) = {
}
@main
-def generateSources(p: Path) = {
+def generateCoreSources(p: Path) = {
generateApplyer(p)
generateTarget(p)
generateEval(p)
}
@main
-def generateTests(p: Path) = {
+def generateCoreTestSources(p: Path) = {
generateApplicativeTest(p)
}