Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark test module as test sources; change sbt module root #298

Merged
merged 3 commits into from
Apr 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions scalalib/src/mill/scalalib/GenIdeaImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -214,16 +214,19 @@ object GenIdeaImpl {
mod.generatedSources.ctx.segments
)

val isTest = mod.isInstanceOf[TestModule]

val elem = moduleXmlTemplate(
mod.millModuleBasePath.value,
mod.intellijModulePath,
scalaVersionOpt,
Strict.Agg.from(resourcesPathRefs.map(_.path)),
Strict.Agg.from(normalSourcePaths),
Strict.Agg.from(generatedSourcePaths),
paths.out,
generatedSourceOutPath.dest,
Strict.Agg.from(resolvedDeps.map(pathToLibName)),
Strict.Agg.from(mod.moduleDeps.map{ m => moduleName(moduleLabels(m))}.distinct)
Strict.Agg.from(mod.moduleDeps.map{ m => moduleName(moduleLabels(m))}.distinct),
isTest
)
Tuple2(".idea_modules"/s"${moduleName(path)}.iml", elem)
}
Expand Down Expand Up @@ -321,7 +324,9 @@ object GenIdeaImpl {
compileOutputPath: Path,
generatedSourceOutputPath: Path,
libNames: Strict.Agg[String],
depNames: Strict.Agg[String]) = {
depNames: Strict.Agg[String],
isTest: Boolean
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows us to display test sources nicely in sources tree,
image

and split them from ordinary sources in search

) = {
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager">
<output url={"file://$MODULE_DIR$/" + relify(compileOutputPath) + "/dest/classes"} />
Expand All @@ -331,17 +336,17 @@ object GenIdeaImpl {
{
for (normalSourcePath <- normalSourcePaths.toSeq.sorted)
yield
<sourceFolder url={"file://$MODULE_DIR$/" + relify(normalSourcePath)} isTestSource="false" />
<sourceFolder url={"file://$MODULE_DIR$/" + relify(normalSourcePath)} isTestSource={isTest.toString} />
}
{
for (generatedSourcePath <- generatedSourcePaths.toSeq.sorted)
yield
<sourceFolder url={"file://$MODULE_DIR$/" + relify(generatedSourcePath)} isTestSource="false" generated="true" />
<sourceFolder url={"file://$MODULE_DIR$/" + relify(generatedSourcePath)} isTestSource={isTest.toString} generated="true" />
}
{
for (resourcePath <- resourcePaths.toSeq.sorted)
yield
<sourceFolder url={"file://$MODULE_DIR$/" + relify(resourcePath)} isTestSource="false" type="java-resource" />
<sourceFolder url={"file://$MODULE_DIR$/" + relify(resourcePath)} isTestSource={isTest.toString} type="java-resource" />
}
<excludeFolder url={"file://$MODULE_DIR$/" + relify(basePath) + "/target"} />
</content>
Expand Down
2 changes: 2 additions & 0 deletions scalalib/src/mill/scalalib/JavaModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ trait JavaModule extends mill.Module with TaskModule { outer =>
def artifactName: T[String] = millModuleSegments.parts.mkString("-")

def artifactId: T[String] = artifactName()

def intellijModulePath: Path = millSourcePath
}

trait TestModule extends JavaModule with TaskModule {
Expand Down
2 changes: 2 additions & 0 deletions scalalib/src/mill/scalalib/MiscModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@ trait MavenModule extends JavaModule{outer =>
override def resources = T.sources{ millSourcePath / 'src / 'main / 'resources }
trait Tests extends super.Tests with MavenTests {
override def millSourcePath = outer.millSourcePath
override def intellijModulePath = outer.millSourcePath / 'src / 'test
}
}

trait SbtModule extends MavenModule with ScalaModule{ outer =>
trait Tests extends super.Tests with MavenTests {
override def millSourcePath = outer.millSourcePath
override def intellijModulePath = outer.millSourcePath / 'src / 'test
}
}

Expand Down
3 changes: 2 additions & 1 deletion scalalib/test/resources/gen-idea/idea/modules.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea_modules/mill-build.iml" filepath="$PROJECT_DIR$/.idea_modules/mill-build.iml"/>
<module fileurl="file://$PROJECT_DIR$/.idea_modules/.iml" filepath="$PROJECT_DIR$/.idea_modules/.iml"/>
<module fileurl="file://$PROJECT_DIR$/.idea_modules/test.iml" filepath="$PROJECT_DIR$/.idea_modules/test.iml"/>
</modules>
</component>
</project>
</project>
18 changes: 18 additions & 0 deletions scalalib/test/resources/gen-idea/idea_modules/test.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager">
<output url="file://$MODULE_DIR$/../target/workspace/mill/scalalib/GenIdeaTests/helloWorldEvaluator/test/compile/dest/classes"/>
<exclude-output/>
<content url="file://$MODULE_DIR$/../target/workspace/mill/scalalib/GenIdeaTests/helloWorldEvaluator/test/generatedSources/dest"/>
<content url="file://$MODULE_DIR$/../target/workspace/gen-idea/test">
<sourceFolder url="file://$MODULE_DIR$/../target/workspace/gen-idea/test/src" isTestSource="true"/>
<sourceFolder url="file://$MODULE_DIR$/../target/workspace/gen-idea/test/resources" isTestSource="true" type="java-resource"/>
<excludeFolder url="file://$MODULE_DIR$/../target/workspace/gen-idea/test/target"/>
</content>
<orderEntry type="inheritedJdk"/>
<orderEntry type="sourceFolder" forTests="false"/>
<orderEntry type="library" name="scala-sdk-2.12.4" level="application"/>
<orderEntry type="library" name="scala-library-2.12.4-sources.jar" level="project"/>
<orderEntry type="library" name="scala-library-2.12.4.jar" level="project"/>
<orderEntry type="module" module-name="" exported=""/>
</component>
</module>
5 changes: 5 additions & 0 deletions scalalib/test/src/mill/scalalib/GenIdeaTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ object GenIdeaTests extends TestSuite {
trait HelloWorldModule extends scalalib.ScalaModule {
def scalaVersion = "2.12.4"
def millSourcePath = GenIdeaTests.millSourcePath
object test extends super.Tests {
def testFrameworks = Seq("utest.runner.Framework")
}
}

object HelloWorld extends TestUtil.BaseModule with HelloWorldModule
Expand All @@ -34,6 +37,8 @@ object GenIdeaTests extends TestSuite {
Seq(
"gen-idea/idea_modules/iml" ->
millSourcePath / "generated" / ".idea_modules" /".iml",
"gen-idea/idea_modules/test.iml" ->
millSourcePath / "generated" / ".idea_modules" /"test.iml",
"gen-idea/idea_modules/mill-build.iml" ->
millSourcePath / "generated" / ".idea_modules" /"mill-build.iml",
"gen-idea/idea/libraries/scala-library-2.12.4.jar.xml" ->
Expand Down