Skip to content

Commit 5ca5420

Browse files
authored
Make --import flag work again (#2502)
Fixes #2485 We take the `config.imports` field and pass it to `MillIvy.processMillIvyDepSignature` inside `ivyDeps`. This was overlooked in #2377, but seems easy enough to put back Honestly not super sure how to test this. But when I run ``` ./mill -i dev.run example/tasks/3-anonymous-tasks -i --import ivy:com.lihaoyi::mill-contrib-bloop:0.11.0-M8 mill.contrib.bloop.Bloop/install ``` On main branch, I get ``` Cannot resolve external module mill.contrib.bloop.Bloop ``` On this PR I get ``` java.lang.NoSuchMethodError: 'java.lang.ThreadLocal mill.eval.Evaluator$.currentEvaluator()' mill.contrib.bloop.Bloop$$anonfun$$lessinit$greater$1.apply(Bloop.scala:8) mill.contrib.bloop.Bloop$$anonfun$$lessinit$greater$1.apply(Bloop.scala:8) ``` Seems like there's a binary incompatibility, but at least the `--import` flag took effect?
1 parent 514e014 commit 5ca5420

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

runner/src/mill/runner/MillBuildBootstrap.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@ class MillBuildBootstrap(
7272
} else {
7373

7474
val bootstrapModule =
75-
new MillBuildRootModule.BootstrapModule(projectRoot, recRoot(depth), millBootClasspath)(
75+
new MillBuildRootModule.BootstrapModule(
76+
projectRoot,
77+
recRoot(depth),
78+
millBootClasspath,
79+
config.imports.collect { case s"ivy:$rest" => rest }
80+
)(
7681
mill.main.RootModule.Info(
7782
recRoot(depth),
7883
Discover[MillBuildRootModule.BootstrapModule]

runner/src/mill/runner/MillBuildRootModule.scala

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,23 @@ class MillBuildRootModule()(implicit
8484
}
8585
}
8686

87+
def cliImports = T.input { millBuildRootModuleInfo.cliImports }
88+
8789
override def ivyDeps = T {
8890
Agg.from(
8991
MillIvy.processMillIvyDepSignature(parseBuildFiles().ivyDeps)
90-
.map(str =>
91-
mill.scalalib.Dep.parse(
92-
str
93-
.replace("$MILL_VERSION", mill.BuildInfo.millVersion)
94-
.replace("${MILL_VERSION}", mill.BuildInfo.millVersion)
95-
.replace("$MILL_BIN_PLATFORM", mill.BuildInfo.millBinPlatform)
96-
.replace("${MILL_BIN_PLATFORM}", mill.BuildInfo.millBinPlatform)
97-
)
98-
)
92+
.map(mill.scalalib.Dep.parse)
9993
) ++
10094
Seq(ivy"com.lihaoyi::mill-moduledefs:${Versions.millModuledefsVersion}")
10195
}
10296

97+
override def runIvyDeps = T {
98+
Agg.from(
99+
MillIvy.processMillIvyDepSignature(cliImports().toSet)
100+
.map(mill.scalalib.Dep.parse)
101+
)
102+
}
103+
103104
override def generatedSources: T[Seq[PathRef]] = T {
104105
generateScriptSources()
105106
}
@@ -114,7 +115,8 @@ class MillBuildRootModule()(implicit
114115
parsed.seenScripts,
115116
T.dest,
116117
millBuildRootModuleInfo.enclosingClasspath,
117-
millBuildRootModuleInfo.topLevelProjectRoot
118+
millBuildRootModuleInfo.topLevelProjectRoot,
119+
millBuildRootModuleInfo.cliImports
118120
)
119121
Result.Success(Seq(PathRef(T.dest)))
120122
}
@@ -168,13 +170,15 @@ object MillBuildRootModule {
168170
class BootstrapModule(
169171
topLevelProjectRoot0: os.Path,
170172
projectRoot: os.Path,
171-
enclosingClasspath: Seq[os.Path]
173+
enclosingClasspath: Seq[os.Path],
174+
cliImports: Seq[String]
172175
)(implicit baseModuleInfo: RootModule.Info) extends RootModule {
173176

174177
implicit private def millBuildRootModuleInfo = MillBuildRootModule.Info(
175178
enclosingClasspath,
176179
projectRoot,
177-
topLevelProjectRoot0
180+
topLevelProjectRoot0,
181+
cliImports
178182
)
179183
object build extends MillBuildRootModule
180184

@@ -185,7 +189,8 @@ object MillBuildRootModule {
185189
case class Info(
186190
enclosingClasspath: Seq[os.Path],
187191
projectRoot: os.Path,
188-
topLevelProjectRoot: os.Path
192+
topLevelProjectRoot: os.Path,
193+
cliImports: Seq[String]
189194
)
190195

191196
def parseBuildFiles(millBuildRootModuleInfo: MillBuildRootModule.Info) = {
@@ -201,7 +206,8 @@ object MillBuildRootModule {
201206
scriptCode: Map[os.Path, String],
202207
targetDest: os.Path,
203208
enclosingClasspath: Seq[os.Path],
204-
millTopLevelProjectRoot: os.Path
209+
millTopLevelProjectRoot: os.Path,
210+
cliImports: Seq[String]
205211
) = {
206212
for (scriptSource <- scriptSources) {
207213
val relative = scriptSource.path.relativeTo(base)
@@ -214,7 +220,8 @@ object MillBuildRootModule {
214220
scriptSource.path.baseName,
215221
enclosingClasspath,
216222
millTopLevelProjectRoot,
217-
scriptSource.path
223+
scriptSource.path,
224+
cliImports
218225
) +
219226
scriptCode(scriptSource.path) +
220227
MillBuildRootModule.bottom
@@ -230,7 +237,8 @@ object MillBuildRootModule {
230237
name: String,
231238
enclosingClasspath: Seq[os.Path],
232239
millTopLevelProjectRoot: os.Path,
233-
originalFilePath: os.Path
240+
originalFilePath: os.Path,
241+
cliImports: Seq[String]
234242
) = {
235243

236244
val superClass =
@@ -259,7 +267,8 @@ object MillBuildRootModule {
259267
| implicit val millBuildRootModuleInfo: _root_.mill.runner.MillBuildRootModule.Info = _root_.mill.runner.MillBuildRootModule.Info(
260268
| ${enclosingClasspath.map(p => literalize(p.toString))}.map(_root_.os.Path(_)),
261269
| _root_.os.Path(${literalize(base.toString)}),
262-
| _root_.os.Path(${literalize(millTopLevelProjectRoot.toString)})
270+
| _root_.os.Path(${literalize(millTopLevelProjectRoot.toString)}),
271+
| _root_.scala.Seq(${cliImports.map(literalize(_)).mkString(", ")})
263272
| )
264273
| implicit val millBaseModuleInfo: _root_.mill.main.RootModule.Info = _root_.mill.main.RootModule.Info(
265274
| millBuildRootModuleInfo.projectRoot,

0 commit comments

Comments
 (0)