Skip to content

Commit 5b8dfcc

Browse files
eed3si9nKordyjan
authored andcommitted
Faster scripted test
Problem ------- edit-scripted cycle is painfully slow right now because `doc` is really slow (and or crashes after running out of memory), but scripted tests do not need scaladoc jars. Solution -------- This ports `PublishBinPlugin` from sbt/sbt (credits to dwijnand sbt/sbt#2725), which implements `publishLocalBin`, which skips scaladoc publishing, and makes edit-scripted cycle faster. [Cherry-picked 0c8dfae]
1 parent 41a8d29 commit 5b8dfcc

File tree

2 files changed

+78
-10
lines changed

2 files changed

+78
-10
lines changed

project/Build.scala

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import complete.DefaultParsers._
1111
import pl.project13.scala.sbt.JmhPlugin
1212
import pl.project13.scala.sbt.JmhPlugin.JmhKeys.Jmh
1313
import sbt.Package.ManifestAttributes
14+
import sbt.PublishBinPlugin.autoImport._
1415
import sbt.plugins.SbtPlugin
1516
import sbt.ScriptedPlugin.autoImport._
1617
import xerial.sbt.pack.PackPlugin
@@ -1594,16 +1595,16 @@ object Build {
15941595
},
15951596
scriptedBufferLog := true,
15961597
scripted := scripted.dependsOn(
1597-
(`scala3-sbt-bridge` / publishLocal),
1598-
(`scala3-interfaces` / publishLocal),
1599-
(`scala3-compiler-bootstrapped` / publishLocal),
1600-
(`scala3-library-bootstrapped` / publishLocal),
1601-
(`scala3-library-bootstrappedJS` / publishLocal),
1602-
(`tasty-core-bootstrapped` / publishLocal),
1603-
(`scala3-staging` / publishLocal),
1604-
(`scala3-tasty-inspector` / publishLocal),
1605-
(`scaladoc` / publishLocal),
1606-
(`scala3-bootstrapped` / publishLocal) // Needed because sbt currently hardcodes the dotty artifact
1598+
(`scala3-sbt-bridge` / publishLocalBin),
1599+
(`scala3-interfaces` / publishLocalBin),
1600+
(`scala3-compiler-bootstrapped` / publishLocalBin),
1601+
(`scala3-library-bootstrapped` / publishLocalBin),
1602+
(`scala3-library-bootstrappedJS` / publishLocalBin),
1603+
(`tasty-core-bootstrapped` / publishLocalBin),
1604+
(`scala3-staging` / publishLocalBin),
1605+
(`scala3-tasty-inspector` / publishLocalBin),
1606+
(`scaladoc` / publishLocalBin),
1607+
(`scala3-bootstrapped` / publishLocalBin) // Needed because sbt currently hardcodes the dotty artifact
16071608
).evaluated
16081609
)
16091610

project/PublishBinPlugin.scala

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package sbt
2+
3+
import java.nio.charset.StandardCharsets.UTF_8
4+
import java.nio.file.{ FileAlreadyExistsException, Files }
5+
6+
import org.apache.ivy.core.module.id.ModuleRevisionId
7+
import sbt.Keys._
8+
import sbt.internal.librarymanagement.{ IvySbt, IvyXml }
9+
10+
/** This local plugin provides ways of publishing just the binary jar. */
11+
object PublishBinPlugin extends AutoPlugin {
12+
override def trigger = allRequirements
13+
14+
object autoImport {
15+
val publishLocalBin = taskKey[Unit]("")
16+
val publishLocalBinConfig = taskKey[PublishConfiguration]("")
17+
}
18+
import autoImport._
19+
20+
private val dummyDoc = taskKey[File]("").withRank(Int.MaxValue)
21+
override val globalSettings = Seq(publishLocalBin := (()))
22+
23+
override val projectSettings: Seq[Def.Setting[_]] = Def settings (
24+
publishLocalBin := Classpaths.publishTask(publishLocalBinConfig).value,
25+
publishLocalBinConfig := Classpaths.publishConfig(
26+
false, // publishMavenStyle.value,
27+
Classpaths.deliverPattern(crossTarget.value),
28+
if (isSnapshot.value) "integration" else "release",
29+
ivyConfigurations.value.map(c => ConfigRef(c.name)).toVector,
30+
(publishLocalBin / packagedArtifacts).value.toVector,
31+
(publishLocalBin / checksums).value.toVector,
32+
logging = ivyLoggingLevel.value,
33+
overwrite = isSnapshot.value
34+
),
35+
publishLocalBinConfig := publishLocalBinConfig
36+
.dependsOn(
37+
// Copied from sbt.internal.
38+
Def.taskDyn {
39+
val doGen = useCoursier.value
40+
if (doGen)
41+
Def.task {
42+
val currentProject = {
43+
val proj = csrProject.value
44+
val publications = csrPublications.value
45+
proj.withPublications(publications)
46+
}
47+
IvyXml.writeFiles(currentProject, None, ivySbt.value, streams.value.log)
48+
} else
49+
Def.task(())
50+
}
51+
)
52+
.value,
53+
dummyDoc := {
54+
val dummyFile = streams.value.cacheDirectory / "doc.jar"
55+
try {
56+
Files.createDirectories(dummyFile.toPath.getParent)
57+
Files.createFile(dummyFile.toPath)
58+
} catch { case _: FileAlreadyExistsException => }
59+
dummyFile
60+
},
61+
dummyDoc / packagedArtifact := (Compile / packageDoc / artifact).value -> dummyDoc.value,
62+
publishLocalBin / packagedArtifacts :=
63+
Classpaths
64+
.packaged(Seq(Compile / packageBin, Compile / packageSrc, makePom, dummyDoc))
65+
.value
66+
)
67+
}

0 commit comments

Comments
 (0)