@@ -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
@@ -2112,120 +2114,14 @@ object Build {
2112
2114
)
2113
2115
)
2114
2116
2115
- lazy val DistCacheConfig = config(" DistCacheConfig" ) extend Compile
2116
-
2117
- val distModules = taskKey[Seq [(ModuleID , Map [Artifact , File ])]](" fetch local artifacts for distribution." )
2118
- val distResolvedArtifacts = taskKey[Seq [ResolvedArtifacts ]](" Resolve the dependencies for the distribution" )
2119
- val distCaching = taskKey[File ](" cache the dependencies for the distribution" )
2120
-
2121
- def evalPublishSteps (dependencies : Seq [ProjectReference ]): Def .Initialize [Task [Seq [(ModuleID , Map [Artifact , File ])]]] = {
2122
- val publishAllLocalBin = dependencies.map({ d => ((d / publishLocalBin / packagedArtifacts)) }).join
2123
- val resolveId = dependencies.map({ d => ((d / projectID)) }).join
2124
- Def .task {
2125
- val s = streams.value
2126
- val log = s.log
2127
- val published = publishAllLocalBin.value
2128
- val ids = resolveId.value
2129
-
2130
- ids.zip(published)
2131
- }
2132
- }
2133
-
2134
- case class SimpleModuleId (org : String , name : String , revision : String ) {
2135
- override def toString = s " $org: $name: $revision"
2136
- }
2137
- case class ResolvedArtifacts (id : SimpleModuleId , jar : File , pom : File )
2138
-
2139
- def commonDistSettings (dependencies : Seq [ClasspathDep [ProjectReference ]]) = Seq (
2117
+ lazy val commonDistSettings = Seq (
2140
2118
packMain := Map (),
2141
2119
publishArtifact := false ,
2142
2120
packGenerateMakefile := false ,
2143
2121
packArchiveName := " scala3-" + dottyVersion,
2144
- DistCacheConfig / distModules := {
2145
- evalPublishSteps(dependencies.map(_.project)).value
2146
- },
2147
- DistCacheConfig / distResolvedArtifacts := {
2148
- val localArtifactIds = (DistCacheConfig / distModules).value
2149
- val report = (thisProjectRef / updateFull).value
2150
-
2151
- val found = mutable.Map .empty[SimpleModuleId , ResolvedArtifacts ]
2152
- val evicted = mutable.Set .empty[SimpleModuleId ]
2153
-
2154
- localArtifactIds.foreach({ case (id, as) =>
2155
- val simpleId = {
2156
- val name0 = id.crossVersion match {
2157
- case _ : CrossVersion .Binary =>
2158
- // projectID does not add binary suffix
2159
- (id.name + " _3" ).ensuring(! id.name.endsWith(" _3" ) && id.revision.startsWith(" 3." ))
2160
- case _ => id.name
2161
- }
2162
- SimpleModuleId (id.organization, name0, id.revision)
2163
- }
2164
- var jarOrNull : File = null
2165
- var pomOrNull : File = null
2166
- as.foreach({ case (a, f) =>
2167
- if (a.`type` == " jar" ) {
2168
- jarOrNull = f
2169
- } else if (a.`type` == " pom" ) {
2170
- pomOrNull = f
2171
- }
2172
- })
2173
- assert(jarOrNull != null , s " Could not find jar for ${id}" )
2174
- assert(pomOrNull != null , s " Could not find pom for ${id}" )
2175
- evicted += simpleId.copy(revision = simpleId.revision + " -nonbootstrapped" )
2176
- found(simpleId) = ResolvedArtifacts (simpleId, jarOrNull, pomOrNull)
2177
- })
2178
-
2179
- report.allModuleReports.foreach { mr =>
2180
- val simpleId = {
2181
- val id = mr.module
2182
- SimpleModuleId (id.organization, id.name, id.revision)
2183
- }
2184
-
2185
- if (! found.contains(simpleId) && ! evicted(simpleId)) {
2186
- var jarOrNull : File = null
2187
- var pomOrNull : File = null
2188
- mr.artifacts.foreach({ case (a, f) =>
2189
- if (a.`type` == " jar" || a.`type` == " bundle" ) {
2190
- jarOrNull = f
2191
- } else if (a.`type` == " pom" ) {
2192
- pomOrNull = f
2193
- }
2194
- })
2195
- assert(jarOrNull != null , s " Could not find jar for ${simpleId}" )
2196
- if (pomOrNull == null ) {
2197
- val jarPath = jarOrNull.toPath
2198
- // we found the jar, so assume we can resolve a sibling pom file
2199
- val pomPath = jarPath.resolveSibling(jarPath.getFileName.toString.stripSuffix(" .jar" ) + " .pom" )
2200
- assert(Files .exists(pomPath), s " Could not find pom for ${simpleId}" )
2201
- pomOrNull = pomPath.toFile
2202
- }
2203
- found(simpleId) = ResolvedArtifacts (simpleId, jarOrNull, pomOrNull)
2204
- }
2205
-
2206
- }
2207
- found.values.toSeq
2208
- },
2209
- DistCacheConfig / distCaching := {
2210
- val resolved = (DistCacheConfig / distResolvedArtifacts).value
2211
- val targetDir = target.value
2212
- val cacheDir = targetDir / " local-repo"
2213
- val mavenRepo = cacheDir / " maven2"
2214
- IO .createDirectory(mavenRepo)
2215
- resolved.foreach { ra =>
2216
- val jar = ra.jar
2217
- val pom = ra.pom
2218
-
2219
- val pathElems = ra.id.org.split('.' ).toVector :+ ra.id.name :+ ra.id.revision
2220
- val artifactDir = pathElems.foldLeft(mavenRepo)(_ / _)
2221
- IO .createDirectory(artifactDir)
2222
- IO .copyFile(jar, artifactDir / jar.getName)
2223
- IO .copyFile(pom, artifactDir / pom.getName)
2224
- }
2225
- cacheDir
2226
- },
2122
+ republishRepo := target.value / " local-repo" ,
2227
2123
Compile / pack := {
2228
- val localRepo = ( DistCacheConfig / distCaching).value
2124
+ val localRepo = republishClasspath.value // republish all artifacts to local repo
2229
2125
(Compile / pack).value
2230
2126
}
2231
2127
)
@@ -2363,7 +2259,9 @@ object Build {
2363
2259
2364
2260
def asDist (implicit mode : Mode ): Project = project.
2365
2261
enablePlugins(PackPlugin ).
2262
+ enablePlugins(RepublishPlugin ).
2366
2263
withCommonSettings.
2264
+ settings(commonDistSettings).
2367
2265
dependsOn(
2368
2266
`scala3-interfaces`,
2369
2267
dottyCompiler,
@@ -2374,14 +2272,10 @@ object Build {
2374
2272
scaladoc,
2375
2273
`scala3-sbt-bridge`, // for scala-cli
2376
2274
).
2377
- withDepSettings(commonDistSettings).
2378
2275
bootstrappedSettings(
2379
2276
target := baseDirectory.value / " target" // override setting in commonBootstrappedSettings
2380
2277
)
2381
2278
2382
- def withDepSettings (f : Seq [ClasspathDep [ProjectReference ]] => Seq [Setting [? ]]): Project =
2383
- project.settings(f(project.dependencies))
2384
-
2385
2279
def withCommonSettings (implicit mode : Mode ): Project = project.settings(mode match {
2386
2280
case NonBootstrapped => commonNonBootstrappedSettings
2387
2281
case Bootstrapped => commonBootstrappedSettings
0 commit comments