Skip to content

Fix how we invalidate the sbt bridge cache #5050

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 28, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ object Build {
// on a task. Instead, we make `compile` below depend on the bridge `packageSrc`
Some((artifactPath in (`dotty-sbt-bridge`, Compile, packageSrc)).value.toURI.toURL))),
compile in Compile := (compile in Compile)
.dependsOn(packageSrc in (`dotty-sbt-bridge`, Compile)).value,
.dependsOn(packageSrc in (`dotty-sbt-bridge`, Compile))
.dependsOn(compile in (`dotty-sbt-bridge`, Compile))
.value,

// Use the same name as the non-bootstrapped projects for the artifacts
moduleName ~= { _.stripSuffix("-bootstrapped") },
Expand Down Expand Up @@ -746,18 +748,29 @@ object Build {
// until sbt/sbt#2402 is fixed (https://github.com/sbt/sbt/issues/2402)
lazy val cleanSbtBridge = TaskKey[Unit]("cleanSbtBridge", "delete dotty-sbt-bridge cache")

def cleanSbtBridgeImpl(): Unit = {
val home = System.getProperty("user.home")
val sbtOrg = "org.scala-sbt"
val bridgePattern = s"*dotty-sbt-bridge*$dottyVersion*"

IO.delete((file(home) / ".sbt" / "1.0" / "zinc" / sbtOrg * bridgePattern).get)
IO.delete((file(home) / ".sbt" / "boot" * "scala-*" / sbtOrg / "sbt" * "*" * bridgePattern).get)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How safe is deleting wildcard files under the home directory? Looks a bit scary (both the code and especially that it's allowed). Tho apparently we already did it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The paths used are as precise as I can reasonably make them to limit the use of wildcards. Suggestions on making this better are welcome but I think it's fine as is.

}

lazy val dottySbtBridgeSettings = Seq(
cleanSbtBridge := {
val home = System.getProperty("user.home")
val sbtOrg = "org.scala-sbt"
val bridgeDirectoryPattern = s"*$dottyVersion*"

cleanSbtBridgeImpl()
},
compile in Compile := {
val log = streams.value.log
log.info("Cleaning the dotty-sbt-bridge cache")
IO.delete((file(home) / ".ivy2" / "cache" / sbtOrg * bridgeDirectoryPattern).get)
IO.delete((file(home) / ".sbt" / "boot" * "scala-*" / sbtOrg / "sbt" * "*" * bridgeDirectoryPattern).get)
val prev = (previousCompile in Compile).value.analysis.orElse(null)
val cur = (compile in Compile).value
if (prev != cur) {
log.info("Cleaning the dotty-sbt-bridge cache because it was recompiled.")
cleanSbtBridgeImpl()
}
cur
},
compile in Compile := (compile in Compile).dependsOn(cleanSbtBridge).value,
description := "sbt compiler bridge for Dotty",
resolvers += Resolver.typesafeIvyRepo("releases"), // For org.scala-sbt:api
libraryDependencies ++= Seq(
Expand Down