Skip to content

Commit

Permalink
Fix the scala-library dependency for (generic) platform modules (#2739)
Browse files Browse the repository at this point in the history
In Scala 3 modules, that also define a platform, the scala3-library is
not correctly resolved.
The current implementation exists merely as a convenience for JS and
Native modules. `ScalaNativeModule` already handles a correct scala
library by overriding `scalaLibraryIvyDeps`. This pull request overrides
the same in `ScalaJSModule` and removed the faulty platfrom dependency
from `ScalaModule`.

E.g. imagine, someone tries to build a Mill plugin with Scala 3 (which
is currently not supported) and sets the platform to `_mill0.11`, then
you would run into the following issue:

```scala
object root extends ScalaModule {
  override def scalaVersion = "3.3.0"
  override def platformSuffix = "_mill0.11"
  // ..
}
```

```
>> mill ivyDepsTree
1 targets failed
resolvedIvyDeps
Resolution failed for 1 modules:
--------------------------------------------
  org.scala-lang:scala3-library_mill0.11_3:3.3.0
	not found: /Users/me/ivy2/local/org.scala-lang/scala3-library_mill0.11_3/3.3.0/ivys/ivy.xml
	not found: https://repo1.maven.org/maven2/org/scala-lang/scala3-library_mill0.11_3/3.3.0/scala3-library_mill0.11_3-3.3.0.pom
```

Pull request: #2739
  • Loading branch information
lefou authored Sep 15, 2023
1 parent 9747a8f commit 19625f5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
8 changes: 5 additions & 3 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -364,14 +364,16 @@ trait MillPublishScalaModule extends MillScalaModule with MillPublishJavaModule
/** Publishable module which contains strictly handled API. */
trait MillStableScalaModule extends MillPublishScalaModule with Mima {
import com.github.lolgab.mill.mima._
// MIMA doesn't properly ignore things which are nested inside other private things
// so we have to put explicit ignores here (https://github.com/lightbend/mima/issues/771)
override def mimaBinaryIssueFilters: T[Seq[ProblemFilter]] = Seq(
// MIMA doesn't properly ignore things which are nested inside other private things
// so we have to put explicit ignores here (https://github.com/lightbend/mima/issues/771)
ProblemFilter.exclude[Problem]("mill.eval.ProfileLogger*"),
ProblemFilter.exclude[Problem]("mill.eval.GroupEvaluator*"),
ProblemFilter.exclude[Problem]("mill.eval.Tarjans*"),
ProblemFilter.exclude[Problem]("mill.define.Ctx#Impl*"),
ProblemFilter.exclude[Problem]("mill.resolve.ResolveNotFoundHandler*")
ProblemFilter.exclude[Problem]("mill.resolve.ResolveNotFoundHandler*"),
// See https://github.com/com-lihaoyi/mill/pull/2739
ProblemFilter.exclude[ReversedMissingMethodProblem]("mill.scalajslib.ScalaJSModule.mill$scalajslib$ScalaJSModule$$super$scalaLibraryIvyDeps")
)
def mimaPreviousVersions: T[Seq[String]] = Settings.mimaBaseVersions

Expand Down
16 changes: 15 additions & 1 deletion scalajslib/src/mill/scalajslib/ScalaJSModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import mainargs.Flag
import mill.api.{Loose, PathRef, Result, internal}
import mill.scalalib.api.ZincWorkerUtil
import mill.scalalib.Lib.resolveDependencies
import mill.scalalib.{Dep, DepSyntax, Lib, TestModule}
import mill.scalalib.{CrossVersion, Dep, DepSyntax, Lib, TestModule}
import mill.testrunner.{TestResult, TestRunner, TestRunnerUtils}
import mill.define.{Command, Target, Task}
import mill.scalajslib.api._
Expand Down Expand Up @@ -34,6 +34,20 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer =>

def scalaJSWorkerVersion = T { ZincWorkerUtil.scalaJSWorkerVersion(scalaJSVersion()) }

override def scalaLibraryIvyDeps = T {
val deps = super.scalaLibraryIvyDeps()
if (ZincWorkerUtil.isScala3(scalaVersion())) {
// Since Dotty/Scala3, Scala.JS is published with a platform suffix
deps.map(dep =>
dep.copy(cross = dep.cross match {
case c: CrossVersion.Constant => c.copy(platformed = true)
case c: CrossVersion.Binary => c.copy(platformed = true)
case c: CrossVersion.Full => c.copy(platformed = true)
})
)
} else deps
}

def scalaJSWorkerClasspath = T {
mill.util.Util.millProjectModule(
artifact = s"mill-scalajslib-worker-${scalaJSWorkerVersion()}",
Expand Down
2 changes: 1 addition & 1 deletion scalalib/src/mill/scalalib/Dep.scala
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ object CrossVersion {
implicit def rw: RW[Full] = macroRW
}

def empty(platformed: Boolean) = Constant(value = "", platformed)
def empty(platformed: Boolean): Constant = Constant(value = "", platformed)

implicit def rw: RW[CrossVersion] = RW.merge(Constant.rw, Binary.rw, Full.rw)
}
Expand Down
4 changes: 1 addition & 3 deletions scalalib/src/mill/scalalib/Lib.scala
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,11 @@ object Lib {
def scalaRuntimeIvyDeps(scalaOrganization: String, scalaVersion: String): Loose.Agg[Dep] =
if (ZincWorkerUtil.isDotty(scalaVersion)) {
Agg(
// note that dotty-library has a binary version suffix, hence the :: is necessary here
ivy"$scalaOrganization::dotty-library:$scalaVersion".forceVersion()
)
} else if (ZincWorkerUtil.isScala3(scalaVersion))
Agg(
// note that dotty-library has a binary version suffix, hence the :: is necessary here
ivy"$scalaOrganization::scala3-library::$scalaVersion".forceVersion()
ivy"$scalaOrganization::scala3-library:$scalaVersion".forceVersion()
)
else
Agg(
Expand Down

0 comments on commit 19625f5

Please # to comment.