Skip to content

Commit

Permalink
Don't fetch sources when not explicitly requested for (#2701)
Browse files Browse the repository at this point in the history
Also fixed use of hardcoded repositories set. This code was previously
located in the GenIdea and moved here. But we now have proper access to
the build module repositories, so using hardcoded repos is no longer
justified.

Pull request: #2701
  • Loading branch information
lefou authored Aug 24, 2023
1 parent c275cc5 commit d257f5d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 51 deletions.
26 changes: 14 additions & 12 deletions bsp/worker/src/mill/bsp/worker/MillBuildServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -327,23 +327,25 @@ private class MillBuildServer(
completableTasks(
hint = s"buildTargetDependencySources ${p}",
targetIds = _ => p.getTargets.asScala.toSeq,
tasks = { case m: JavaModule =>
T.task {
(
m.resolveDeps(
T.task(m.transitiveCompileIvyDeps() ++ m.transitiveIvyDeps()),
sources = true
)(),
m.unmanagedClasspath()
)
}
tasks = {
case m: JavaModule =>
T.task {
(
m.resolveDeps(
T.task(m.transitiveCompileIvyDeps() ++ m.transitiveIvyDeps()),
sources = true
)(),
m.unmanagedClasspath(),
m.repositoriesTask()
)
}
}
) {
case (ev, state, id, m: JavaModule, (resolveDepsSources, unmanagedClasspath)) =>
case (ev, state, id, m: JavaModule, (resolveDepsSources, unmanagedClasspath, repos)) =>
val buildSources =
if (!m.isInstanceOf[MillBuildRootModule]) Nil
else mill.scalalib.Lib
.resolveMillBuildDeps(Nil, None, useSources = true)
.resolveMillBuildDeps(repos, None, useSources = true)
.map(sanitizeUri(_))

val cp = (resolveDepsSources ++ unmanagedClasspath).map(sanitizeUri).toSeq ++ buildSources
Expand Down
17 changes: 0 additions & 17 deletions runner/src/mill/runner/MillBuildRootModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,6 @@ class MillBuildRootModule()(implicit
override def millSourcePath = millBuildRootModuleInfo.projectRoot / os.up / "mill-build"
override def intellijModulePath: os.Path = millSourcePath / os.up

override def resolveDeps(
deps: Task[Agg[BoundDep]],
sources: Boolean = false
): Task[Agg[PathRef]] =
T.task {
if (sources == true) super.resolveDeps(deps, true)()
else {
// We need to resolve the sources to make GenIdeaExtendedTests pass,
// because those do not call `resolveDeps` explicitly for build file
// `import $ivy`s but instead rely on the deps that are resolved as
// part of the bootstrapping process. We thus need to make sure
// bootstrapping the rootModule ends up putting the sources on disk
val unused = super.resolveDeps(deps, true)()
super.resolveDeps(deps, false)()
}
}

override def scalaVersion: T[String] = "2.13.10"

/**
Expand Down
28 changes: 6 additions & 22 deletions scalalib/src/mill/scalalib/Lib.scala
Original file line number Diff line number Diff line change
Expand Up @@ -138,20 +138,18 @@ object Lib {
}

def resolveMillBuildDeps(
repos0: Seq[Repository],
repos: Seq[Repository],
ctx: Option[mill.api.Ctx.Log],
useSources: Boolean
): Seq[os.Path] = {
Util.millProperty("MILL_BUILD_LIBRARIES") match {
case Some(found) => found.split(',').map(os.Path(_)).distinct.toList
case None =>
val repos = (repos0 ++ Seq(
LocalRepositories.ivy2Local,
Repositories.central
)).distinct
val millDeps = BuildInfo.millEmbeddedDeps.split(",").map(d => ivy"$d").map(dep =>
BoundDep(Lib.depToDependency(dep, BuildInfo.scalaVersion, ""), dep.force)
)
val millDeps = BuildInfo.millEmbeddedDeps
.split(",")
.map(d => ivy"$d")
.map(dep => Lib.depToBoundDep(dep, BuildInfo.scalaVersion))

val Result.Success(res) = scalalib.Lib.resolveDependencies(
repositories = repos.toList,
deps = millDeps,
Expand All @@ -161,20 +159,6 @@ object Lib {
coursierCacheCustomizer = None,
ctx = ctx
)

// Also trigger resolve sources, but don't use them (will happen implicitly by Idea)
if (!useSources) {
scalalib.Lib.resolveDependencies(
repositories = repos.toList,
deps = millDeps,
sources = true,
mapDependencies = None,
customizer = None,
coursierCacheCustomizer = None,
ctx = ctx
)
}

res.items.toList.map(_.path)
}
}
Expand Down

0 comments on commit d257f5d

Please sign in to comment.