From d257f5d232ef9c12f8f492f70a80887f77b73842 Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Thu, 24 Aug 2023 12:44:27 +0200 Subject: [PATCH] Don't fetch sources when not explicitly requested for (#2701) 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: https://github.com/com-lihaoyi/mill/pull/2701 --- .../src/mill/bsp/worker/MillBuildServer.scala | 26 +++++++++-------- .../src/mill/runner/MillBuildRootModule.scala | 17 ----------- scalalib/src/mill/scalalib/Lib.scala | 28 ++++--------------- 3 files changed, 20 insertions(+), 51 deletions(-) diff --git a/bsp/worker/src/mill/bsp/worker/MillBuildServer.scala b/bsp/worker/src/mill/bsp/worker/MillBuildServer.scala index 1b972f05dc4..1ea291f3c5d 100644 --- a/bsp/worker/src/mill/bsp/worker/MillBuildServer.scala +++ b/bsp/worker/src/mill/bsp/worker/MillBuildServer.scala @@ -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 diff --git a/runner/src/mill/runner/MillBuildRootModule.scala b/runner/src/mill/runner/MillBuildRootModule.scala index 61d1e2f0f3c..f0974754fa9 100644 --- a/runner/src/mill/runner/MillBuildRootModule.scala +++ b/runner/src/mill/runner/MillBuildRootModule.scala @@ -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" /** diff --git a/scalalib/src/mill/scalalib/Lib.scala b/scalalib/src/mill/scalalib/Lib.scala index 9bdd87308b4..722ccd9f7cc 100644 --- a/scalalib/src/mill/scalalib/Lib.scala +++ b/scalalib/src/mill/scalalib/Lib.scala @@ -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, @@ -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) } }