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

Add JavaModule.mandatoryJavacOptions #3503

Merged
merged 11 commits into from
Sep 10, 2024
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
8 changes: 7 additions & 1 deletion bsp/worker/src/mill/bsp/worker/MillJavaBuildServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ private trait MillJavaBuildServer extends JavaBuildServer { this: MillBuildServe
sem.bspCompiledClassesAndSemanticDbFiles
case _ => m.bspCompileClassesPath
}
T.task { (classesPathTask(), m.javacOptions(), m.bspCompileClasspath()) }
T.task {
(
classesPathTask(),
m.javacOptions() ++ m.mandatoryJavacOptions(),
m.bspCompileClasspath()
)
}
}
) {
// We ignore all non-JavaModule
Expand Down
6 changes: 5 additions & 1 deletion build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,11 @@ trait MillStableScalaModule extends MillPublishScalaModule with Mima {
),
ProblemFilter.exclude[InheritedNewAbstractMethodProblem](
"mill.main.MainModule.mill$define$BaseModule0$_setter_$evalWatchedValues_="
),

// https://github.com/com-lihaoyi/mill/pull/3503
ProblemFilter.exclude[ReversedMissingMethodProblem](
"mill.scalalib.ScalaModule#ScalaTests.mill$scalalib$ScalaModule$ScalaTests$$super$mandatoryScalacOptions"
)
)
def mimaPreviousVersions: T[Seq[String]] = Settings.mimaBaseVersions
Expand Down Expand Up @@ -875,7 +880,6 @@ object dist extends MillPublishJavaModule {
}
}


/**
* Build and install Mill locally.
*
Expand Down
6 changes: 4 additions & 2 deletions contrib/bloop/src/mill/contrib/bloop/BloopImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,10 @@ class BloopImpl(evs: () => Seq[Evaluator], wd: os.Path) extends ExternalModule {
def out(m: JavaModule) = bloopDir / "out" / name(m)
def classes(m: JavaModule) = out(m) / "classes"

val javaConfig =
module.javacOptions.map(opts => Some(Config.Java(options = opts.toList)))
val javaConfig = T.task {
val opts = module.javacOptions() ++ module.mandatoryJavacOptions()
Some(Config.Java(options = opts.toList))
}

// //////////////////////////////////////////////////////////////////////////
// Scalac
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ trait ErrorProneModule extends JavaModule {
* The classpath of the `error-prone` compiler plugin.
*/
def errorProneClasspath: T[Agg[PathRef]] = T {
resolveDeps(T.task { errorProneDeps().map(bindDependency()) })()
defaultResolver().resolveDeps(errorProneDeps())
}

/**
Expand Down Expand Up @@ -70,12 +70,7 @@ trait ErrorProneModule extends JavaModule {
/**
* Appends the [[errorProneJavacEnableOptions]] to the Java compiler options.
*/
override def javacOptions: T[Seq[String]] = T {
val supOpts = super.javacOptions()
val enableOpts = Option
.when(!supOpts.exists(o => o.startsWith("-Xplugin:ErrorProne")))(
errorProneJavacEnableOptions()
)
supOpts ++ enableOpts.toSeq.flatten
override def mandatoryJavacOptions: T[Seq[String]] = T {
super.mandatoryJavacOptions() ++ errorProneJavacEnableOptions()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ object ErrorProneTests extends TestSuite {
}
test("compileWarn") {
val eval = UnitTester(errorProneCustom, testModuleSourcesPath, debugEnabled = true)
val Right(opts) = eval(errorProneCustom.javacOptions)
val Right(opts) = eval(errorProneCustom.mandatoryJavacOptions)
assert(opts.value.exists(_.contains("-XepAllErrorsAsWarnings")))
val res = eval(errorProneCustom.compile)
assert(res.isRight)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ trait HelloWorldTests extends utest.TestSuite {
def scalaVersion = testScalaVersion
def scoverageVersion = testScoverageVersion

object test extends SbtModuleTests with ScoverageTests with TestModule.ScalaTest {
object test extends SbtTests with ScoverageTests with TestModule.ScalaTest {
override def ivyDeps = Agg(ivy"org.scalatest::scalatest:${testScalatestVersion}")
}
}
Expand Down
3 changes: 1 addition & 2 deletions contrib/testng/test/src/mill/testng/TestNGTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import mill.util.Util.millProjectModule
import mill.scalalib._
import mill.testkit.UnitTester
import mill.testkit.TestBaseModule
import utest.framework.TestPath
import utest.{TestSuite, Tests, assert, _}

object TestNGTests extends TestSuite {

object demo extends TestBaseModule with JavaModule {

object test extends JavaModuleTests {
object test extends JavaTests {
def testngClasspath = T {
millProjectModule(
"mill-contrib-testng",
Expand Down
4 changes: 0 additions & 4 deletions scalajslib/test/src/mill/scalajslib/HelloJSWorldTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ object HelloJSWorldTests extends TestSuite {
object inherited extends ScalaJSModule {
val (scala, scalaJS) = matrix.head
def scalacOptions = Seq("-deprecation")
def mandatoryScalacOptions = Seq("-mandatory")
def scalaOrganization = "org.example"
def scalaVersion = scala
def scalaJSVersion = scalaJS
Expand Down Expand Up @@ -292,9 +291,6 @@ object HelloJSWorldTests extends TestSuite {
test("test-scalacOptions") {
checkInheritedTargets(_.scalacOptions, Seq("-deprecation"))
}
test("test-mandatoryScalacOptions") {
checkInheritedTargets(_.mandatoryScalacOptions, Seq("-mandatory"))
}
test("test-scalaOrganization") {
checkInheritedTargets(_.scalaOrganization, "org.example")
}
Expand Down
6 changes: 5 additions & 1 deletion scalalib/src/mill/scalalib/CrossSbtModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import mill.api.PathRef
import mill.T
import mill.scalalib.{CrossModuleBase, SbtModule}

import scala.annotation.nowarn

trait CrossSbtModule extends SbtModule with CrossModuleBase { outer =>

override def sources: T[Seq[PathRef]] = T.sources {
Expand All @@ -12,15 +14,17 @@ trait CrossSbtModule extends SbtModule with CrossModuleBase { outer =>
)
}

@nowarn
type CrossSbtTests = CrossSbtModuleTests
@deprecated("Use CrossSbtTests instead", since = "Mill 0.11.10")
trait CrossSbtModuleTests extends SbtModuleTests {
trait CrossSbtModuleTests extends SbtTests {
override def millSourcePath = outer.millSourcePath
override def sources = T.sources {
super.sources() ++ scalaVersionDirectoryNames.map(s =>
PathRef(millSourcePath / "src" / "test" / s"scala-$s")
)
}
}
@deprecated("Use CrossTests instead", since = "Mill after 0.12.0-RC1")
trait Tests extends CrossSbtModuleTests
}
10 changes: 8 additions & 2 deletions scalalib/src/mill/scalalib/JavaModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ trait JavaModule
with BspModule
with SemanticDbJavaModule { outer =>

def zincWorker: ModuleRef[ZincWorkerModule] = super.zincWorker
override def zincWorker: ModuleRef[ZincWorkerModule] = super.zincWorker
@nowarn
type JavaTests = JavaModuleTests
@deprecated("Use JavaTests instead", since = "Mill 0.11.10")
trait JavaModuleTests extends JavaModule with TestModule {
Expand Down Expand Up @@ -160,6 +161,11 @@ trait JavaModule
*/
def javacOptions: T[Seq[String]] = T { Seq.empty[String] }

/**
* Additional options for the java compiler derived from other module settings.
*/
def mandatoryJavacOptions: T[Seq[String]] = T { Seq.empty[String] }

/**
* The direct dependencies of this module.
* This is meant to be overridden to add dependencies.
Expand Down Expand Up @@ -422,7 +428,7 @@ trait JavaModule
upstreamCompileOutput = upstreamCompileOutput(),
sources = allSourceFiles().map(_.path),
compileClasspath = compileClasspath().map(_.path),
javacOptions = javacOptions(),
javacOptions = javacOptions() ++ mandatoryJavacOptions(),
reporter = T.reporter.apply(hashCode),
reportCachedProblems = zincReportCachedProblems(),
incrementalCompilation = zincIncrementalCompilation()
Expand Down
5 changes: 4 additions & 1 deletion scalalib/src/mill/scalalib/MavenModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package mill.scalalib

import mill.T

import scala.annotation.nowarn

/**
* A [[JavaModule]] with a Maven compatible directory layout.
*
Expand All @@ -16,9 +18,10 @@ trait MavenModule extends JavaModule { outer =>
millSourcePath / "src" / "main" / "resources"
}

@nowarn
type MavenTests = MavenModuleTests
@deprecated("Use JavaTests instead", since = "Mill 0.11.10")
trait MavenModuleTests extends JavaModuleTests {
trait MavenModuleTests extends JavaTests {
override def millSourcePath = outer.millSourcePath
override def intellijModulePath: os.Path = outer.millSourcePath / "src" / "test"

Expand Down
3 changes: 3 additions & 0 deletions scalalib/src/mill/scalalib/SbtModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package mill.scalalib

import mill.T

import scala.annotation.nowarn

/**
* A [[ScalaModule]] with sbt compatible directory layout.
*/
Expand All @@ -12,6 +14,7 @@ trait SbtModule extends ScalaModule with MavenModule {
millSourcePath / "src" / "main" / "java"
)

@nowarn
type SbtTests = SbtModuleTests
@deprecated("Use SbtTests instead", since = "Mill 0.11.10")
trait SbtModuleTests extends ScalaTests with MavenTests {
Expand Down
6 changes: 3 additions & 3 deletions scalalib/src/mill/scalalib/ScalaModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer =>
@deprecated("use ScalaTests", "0.11.0")
type ScalaModuleTests = ScalaTests

trait ScalaTests extends JavaModuleTests with ScalaModule {
trait ScalaTests extends JavaTests with ScalaModule {
override def scalaOrganization: Target[String] = outer.scalaOrganization()
override def scalaVersion: Target[String] = outer.scalaVersion()
override def scalacPluginIvyDeps: Target[Agg[Dep]] = outer.scalacPluginIvyDeps()
override def scalacPluginClasspath: Target[Agg[PathRef]] = outer.scalacPluginClasspath()
override def scalacOptions: Target[Seq[String]] = outer.scalacOptions()
override def mandatoryScalacOptions: Target[Seq[String]] = outer.mandatoryScalacOptions()
override def mandatoryScalacOptions: Target[Seq[String]] = T { super.mandatoryScalacOptions() }
}

/**
Expand Down Expand Up @@ -279,7 +279,7 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer =>
upstreamCompileOutput = upstreamCompileOutput(),
sources = allSourceFiles().map(_.path),
compileClasspath = compileClasspath().map(_.path),
javacOptions = javacOptions(),
javacOptions = javacOptions() ++ mandatoryJavacOptions(),
scalaVersion = sv,
scalaOrganization = scalaOrganization(),
scalacOptions = allScalacOptions(),
Expand Down
6 changes: 5 additions & 1 deletion scalalib/src/mill/scalalib/SemanticDbJavaModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ trait SemanticDbJavaModule extends CoursierModule {
def compile: T[mill.scalalib.api.CompilationResult]
def bspBuildTarget: BspBuildTarget
def javacOptions: T[Seq[String]]
def mandatoryJavacOptions: T[Seq[String]]
def compileClasspath: T[Agg[PathRef]]

def semanticDbVersion: T[String] = T.input {
Expand Down Expand Up @@ -98,7 +99,10 @@ trait SemanticDbJavaModule extends CoursierModule {
}

def semanticDbData: T[PathRef] = T.persistent {
val javacOpts = SemanticDbJavaModule.javacOptionsTask(javacOptions(), semanticDbJavaVersion())
val javacOpts = SemanticDbJavaModule.javacOptionsTask(
javacOptions() ++ mandatoryJavacOptions(),
semanticDbJavaVersion()
)

// we currently assume, we don't do incremental java compilation
os.remove.all(T.dest / "classes")
Expand Down
6 changes: 3 additions & 3 deletions scalalib/test/src/mill/scalalib/HelloJavaTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ object HelloJavaTests extends TestSuite {
object HelloJava extends TestBaseModule {
object core extends JavaModule {
override def docJarUseArgsFile = false
object test extends JavaModuleTests with TestModule.Junit4
object test extends JavaTests with TestModule.Junit4
}
object app extends JavaModule {
override def docJarUseArgsFile = true
override def moduleDeps = Seq(core)
object test extends JavaModuleTests with TestModule.Junit4
object testJunit5 extends JavaModuleTests with TestModule.Junit5 {
object test extends JavaTests with TestModule.Junit4
object testJunit5 extends JavaTests with TestModule.Junit5 {
override def ivyDeps: T[Agg[Dep]] = T {
super.ivyDeps() ++ Agg(ivy"org.junit.jupiter:junit-jupiter-params:5.7.0")
}
Expand Down
Loading