Skip to content

Commit 0c15f18

Browse files
committed
merged
1 parent eb45996 commit 0c15f18

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

core/exec/src/mill/exec/GroupExecution.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,10 @@ trait GroupExecution {
230230
exclusive: Boolean,
231231
upstreamPathRefs: Seq[PathRef]
232232
): GroupExecution.Results = {
233-
val sideHashes = group.iterator.map(_.sideHash).sum
233+
val (sideHashes, hasSideEffects) = group.iterator.foldLeft((0, false)) { case ((sum, has), t) =>
234+
val sideHash = t.sideHash
235+
(sum + sideHash, has || sideHash != 0)
236+
}
234237

235238
val inputsHash = {
236239
val externalInputsHash = MurmurHash3.orderedHash(
@@ -280,7 +283,7 @@ trait GroupExecution {
280283
// Helper to evaluate the task with full caching support
281284
def evaluateTaskWithCaching(): GroupExecution.Results = {
282285
val cached = Option
283-
.when(sideHashes == 0) { loadCachedJson(logger, inputsHash, labelled, paths) }
286+
.when(!hasSideEffects) { loadCachedJson(logger, inputsHash, labelled, paths) }
284287
.flatten
285288

286289
// `cached.isEmpty` means worker metadata file removed by user so recompute the worker
@@ -714,7 +717,7 @@ trait GroupExecution {
714717
def getValueHash(v: Val, task: Task[?], inputsHash: Int): Int = {
715718
if (task.isInstanceOf[Task.Worker[?]]) inputsHash
716719
else {
717-
task match {
720+
val base = task match {
718721
case named: Task.Named[_] =>
719722
named.writerOpt match {
720723
case Some(writer) =>
@@ -725,6 +728,7 @@ trait GroupExecution {
725728
}
726729
case _ => v.##
727730
}
731+
base + invalidateAllHashes
728732
}
729733
}
730734

core/internal/src/mill/internal/MillPathSerializer.scala

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
package mill.internal
22

3-
import java.nio.file.Files
3+
import java.nio.file.{Files, LinkOption}
44

55
object MillPathSerializer {
66
def setupSymlinks(wd: os.Path, workspace: os.Path): Unit = {
77
for ((base, link) <- defaultMapping(workspace)) {
8-
os.makeDir.all(wd / link / "..")
9-
os.remove(wd / link)
10-
Files.createSymbolicLink((wd / link).toNIO, base.wrapped)
8+
val target = wd / link
9+
val targetNio = target.toNIO
10+
os.makeDir.all(target / "..")
11+
12+
if (Files.isSymbolicLink(targetNio)) {
13+
val currentTarget = Files.readSymbolicLink(targetNio)
14+
if (currentTarget != base.wrapped) {
15+
os.remove(target)
16+
Files.createSymbolicLink(targetNio, base.wrapped)
17+
}
18+
} else if (Files.exists(targetNio, LinkOption.NOFOLLOW_LINKS)) {
19+
throw new IllegalStateException(
20+
s"Refusing to overwrite non-symlink path required for path serialization: $target"
21+
)
22+
} else {
23+
Files.createSymbolicLink(targetNio, base.wrapped)
24+
}
1125
}
1226
}
1327

runner/daemon/src/mill/daemon/MillBuildBootstrap.scala

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,18 +209,30 @@ class MillBuildBootstrap(
209209
// by codesig analysis, not by classLoaderSigHash.
210210
millClassloaderSigHash = nestedState.frames.headOption match {
211211
case Some(frame) =>
212+
def stablePathId(path: os.Path): String = {
213+
if (path.startsWith(currentRoot)) s"<workspace>/${path.subRelativeTo(currentRoot)}"
214+
else if (path.startsWith(os.home)) s"<home>/${path.subRelativeTo(os.home)}"
215+
else path.toString
216+
}
217+
212218
val compileDestPath = frame.compileOutput.map(p => os.Path(p.javaPath))
213219
frame.runClasspath
214220
.filter { p =>
215221
val path = os.Path(p.javaPath)
216222
!compileDestPath.contains(path) &&
217223
!path.toString.contains("generatedScriptSources.dest")
218224
}
219-
.map(p => (os.Path(p.javaPath), p.sig))
225+
.map(p => (stablePathId(os.Path(p.javaPath)), p.sig))
220226
.hashCode()
221227
case None =>
222228
millBootClasspathPathRefs
223-
.map(p => (os.Path(p.javaPath), p.sig))
229+
.map { p =>
230+
val path = os.Path(p.javaPath)
231+
val stable =
232+
if (path.startsWith(os.home)) s"<home>/${path.subRelativeTo(os.home)}"
233+
else path.toString
234+
(stable, p.sig)
235+
}
224236
.hashCode()
225237
},
226238
millClassloaderIdentityHash = nestedState

0 commit comments

Comments
 (0)