@@ -12,6 +12,8 @@ import pl.project13.scala.sbt.JmhPlugin
12
12
import pl .project13 .scala .sbt .JmhPlugin .JmhKeys .Jmh
13
13
import sbt .Package .ManifestAttributes
14
14
import sbt .PublishBinPlugin .autoImport ._
15
+ import dotty .tools .sbtplugin .RepublishPlugin
16
+ import dotty .tools .sbtplugin .RepublishPlugin .autoImport ._
15
17
import sbt .plugins .SbtPlugin
16
18
import sbt .ScriptedPlugin .autoImport ._
17
19
import xerial .sbt .pack .PackPlugin
@@ -2104,120 +2106,14 @@ object Build {
2104
2106
)
2105
2107
)
2106
2108
2107
- lazy val DistCacheConfig = config(" DistCacheConfig" ) extend Compile
2108
-
2109
- val distModules = taskKey[Seq [(ModuleID , Map [Artifact , File ])]](" fetch local artifacts for distribution." )
2110
- val distResolvedArtifacts = taskKey[Seq [ResolvedArtifacts ]](" Resolve the dependencies for the distribution" )
2111
- val distCaching = taskKey[File ](" cache the dependencies for the distribution" )
2112
-
2113
- def evalPublishSteps (dependencies : Seq [ProjectReference ]): Def .Initialize [Task [Seq [(ModuleID , Map [Artifact , File ])]]] = {
2114
- val publishAllLocalBin = dependencies.map({ d => ((d / publishLocalBin / packagedArtifacts)) }).join
2115
- val resolveId = dependencies.map({ d => ((d / projectID)) }).join
2116
- Def .task {
2117
- val s = streams.value
2118
- val log = s.log
2119
- val published = publishAllLocalBin.value
2120
- val ids = resolveId.value
2121
-
2122
- ids.zip(published)
2123
- }
2124
- }
2125
-
2126
- case class SimpleModuleId (org : String , name : String , revision : String ) {
2127
- override def toString = s " $org: $name: $revision"
2128
- }
2129
- case class ResolvedArtifacts (id : SimpleModuleId , jar : File , pom : File )
2130
-
2131
- def commonDistSettings (dependencies : Seq [ClasspathDep [ProjectReference ]]) = Seq (
2109
+ lazy val commonDistSettings = Seq (
2132
2110
packMain := Map (),
2133
2111
publishArtifact := false ,
2134
2112
packGenerateMakefile := false ,
2135
2113
packArchiveName := " scala3-" + dottyVersion,
2136
- DistCacheConfig / distModules := {
2137
- evalPublishSteps(dependencies.map(_.project)).value
2138
- },
2139
- DistCacheConfig / distResolvedArtifacts := {
2140
- val localArtifactIds = (DistCacheConfig / distModules).value
2141
- val report = (thisProjectRef / updateFull).value
2142
-
2143
- val found = mutable.Map .empty[SimpleModuleId , ResolvedArtifacts ]
2144
- val evicted = mutable.Set .empty[SimpleModuleId ]
2145
-
2146
- localArtifactIds.foreach({ case (id, as) =>
2147
- val simpleId = {
2148
- val name0 = id.crossVersion match {
2149
- case _ : CrossVersion .Binary =>
2150
- // projectID does not add binary suffix
2151
- (id.name + " _3" ).ensuring(! id.name.endsWith(" _3" ) && id.revision.startsWith(" 3." ))
2152
- case _ => id.name
2153
- }
2154
- SimpleModuleId (id.organization, name0, id.revision)
2155
- }
2156
- var jarOrNull : File = null
2157
- var pomOrNull : File = null
2158
- as.foreach({ case (a, f) =>
2159
- if (a.`type` == " jar" ) {
2160
- jarOrNull = f
2161
- } else if (a.`type` == " pom" ) {
2162
- pomOrNull = f
2163
- }
2164
- })
2165
- assert(jarOrNull != null , s " Could not find jar for ${id}" )
2166
- assert(pomOrNull != null , s " Could not find pom for ${id}" )
2167
- evicted += simpleId.copy(revision = simpleId.revision + " -nonbootstrapped" )
2168
- found(simpleId) = ResolvedArtifacts (simpleId, jarOrNull, pomOrNull)
2169
- })
2170
-
2171
- report.allModuleReports.foreach { mr =>
2172
- val simpleId = {
2173
- val id = mr.module
2174
- SimpleModuleId (id.organization, id.name, id.revision)
2175
- }
2176
-
2177
- if (! found.contains(simpleId) && ! evicted(simpleId)) {
2178
- var jarOrNull : File = null
2179
- var pomOrNull : File = null
2180
- mr.artifacts.foreach({ case (a, f) =>
2181
- if (a.`type` == " jar" || a.`type` == " bundle" ) {
2182
- jarOrNull = f
2183
- } else if (a.`type` == " pom" ) {
2184
- pomOrNull = f
2185
- }
2186
- })
2187
- assert(jarOrNull != null , s " Could not find jar for ${simpleId}" )
2188
- if (pomOrNull == null ) {
2189
- val jarPath = jarOrNull.toPath
2190
- // we found the jar, so assume we can resolve a sibling pom file
2191
- val pomPath = jarPath.resolveSibling(jarPath.getFileName.toString.stripSuffix(" .jar" ) + " .pom" )
2192
- assert(Files .exists(pomPath), s " Could not find pom for ${simpleId}" )
2193
- pomOrNull = pomPath.toFile
2194
- }
2195
- found(simpleId) = ResolvedArtifacts (simpleId, jarOrNull, pomOrNull)
2196
- }
2197
-
2198
- }
2199
- found.values.toSeq
2200
- },
2201
- DistCacheConfig / distCaching := {
2202
- val resolved = (DistCacheConfig / distResolvedArtifacts).value
2203
- val targetDir = target.value
2204
- val cacheDir = targetDir / " local-repo"
2205
- val mavenRepo = cacheDir / " maven2"
2206
- IO .createDirectory(mavenRepo)
2207
- resolved.foreach { ra =>
2208
- val jar = ra.jar
2209
- val pom = ra.pom
2210
-
2211
- val pathElems = ra.id.org.split('.' ).toVector :+ ra.id.name :+ ra.id.revision
2212
- val artifactDir = pathElems.foldLeft(mavenRepo)(_ / _)
2213
- IO .createDirectory(artifactDir)
2214
- IO .copyFile(jar, artifactDir / jar.getName)
2215
- IO .copyFile(pom, artifactDir / pom.getName)
2216
- }
2217
- cacheDir
2218
- },
2114
+ republishRepo := target.value / " local-repo" ,
2219
2115
Compile / pack := {
2220
- val localRepo = ( DistCacheConfig / distCaching).value
2116
+ val localRepo = republishClasspath.value // republish all artifacts to local repo
2221
2117
(Compile / pack).value
2222
2118
}
2223
2119
)
@@ -2355,7 +2251,9 @@ object Build {
2355
2251
2356
2252
def asDist (implicit mode : Mode ): Project = project.
2357
2253
enablePlugins(PackPlugin ).
2254
+ enablePlugins(RepublishPlugin ).
2358
2255
withCommonSettings.
2256
+ settings(commonDistSettings).
2359
2257
dependsOn(
2360
2258
`scala3-interfaces`,
2361
2259
dottyCompiler,
@@ -2366,14 +2264,10 @@ object Build {
2366
2264
scaladoc,
2367
2265
`scala3-sbt-bridge`, // for scala-cli
2368
2266
).
2369
- withDepSettings(commonDistSettings).
2370
2267
bootstrappedSettings(
2371
2268
target := baseDirectory.value / " target" // override setting in commonBootstrappedSettings
2372
2269
)
2373
2270
2374
- def withDepSettings (f : Seq [ClasspathDep [ProjectReference ]] => Seq [Setting [? ]]): Project =
2375
- project.settings(f(project.dependencies))
2376
-
2377
2271
def withCommonSettings (implicit mode : Mode ): Project = project.settings(mode match {
2378
2272
case NonBootstrapped => commonNonBootstrappedSettings
2379
2273
case Bootstrapped => commonBootstrappedSettings
0 commit comments