Skip to content

Commit 0e1b381

Browse files
committed
download and cache launcher, add scalajs library
1 parent c496bac commit 0e1b381

File tree

5 files changed

+86
-15
lines changed

5 files changed

+86
-15
lines changed

dist/bin/cli-common

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ find_lib () {
151151
done
152152
}
153153

154-
SCALA_CLI_JAR=$(find_lib "*scala-cli*")
154+
SCALA_CLI_JAR="$PROG_HOME/etc/scala-cli.jar"
155155

156156
declare -a scala_args
157157

dist/bin/scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ if [ -z "$SCALA_VERSION" ]; then
4444
exit 1
4545
fi
4646

47-
MVN_REPOSITORY="file://$PROG_HOME/local/maven2"
47+
MVN_REPOSITORY="file://$PROG_HOME/maven2"
4848

4949
# escape all script arguments
5050
while [[ $# -gt 0 ]]; do

project/Build.scala

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ object Build {
118118
*/
119119
val mimaPreviousLTSDottyVersion = "3.3.0"
120120

121+
/** Version of Scala CLI to download */
122+
val scalaCliLauncherVersion = "1.3.0"
123+
121124
object CompatMode {
122125
final val BinaryCompatible = 0
123126
final val SourceAndBinaryCompatible = 1
@@ -2108,17 +2111,21 @@ object Build {
21082111
publishArtifact := false,
21092112
packGenerateMakefile := false,
21102113
packArchiveName := "scala3-" + dottyVersion,
2111-
republishRepo := target.value / "local-repo",
2112-
Compile / pack := {
2113-
val localRepo = republishClasspath.value // republish all artifacts to local repo
2114-
(Compile / pack).value
2115-
}
2114+
republishRepo := target.value / "republish",
2115+
republishLaunchers := {
2116+
val cliV = scalaCliLauncherVersion
2117+
Seq(
2118+
("scala-cli.jar", cliV, url(s"https://github.com/VirtusLab/scala-cli/releases/download/v$cliV/scala-cli.jar"))
2119+
)
2120+
},
2121+
Compile / pack := (Compile / pack).dependsOn(republish).value,
21162122
)
21172123

21182124
lazy val dist = project.asDist(Bootstrapped)
21192125
.settings(
21202126
packResourceDir += (baseDirectory.value / "bin" -> "bin"),
2121-
packResourceDir += (target.value / "local-repo" -> "local"),
2127+
packResourceDir += (republishRepo.value / "maven2" -> "maven2"),
2128+
packResourceDir += (republishRepo.value / "etc" -> "etc"),
21222129
)
21232130

21242131
private def customMimaReportBinaryIssues(issueFilterLocation: String) = mimaReportBinaryIssues := {
@@ -2249,6 +2256,7 @@ object Build {
22492256
def asDist(implicit mode: Mode): Project = project.
22502257
enablePlugins(PackPlugin).
22512258
enablePlugins(RepublishPlugin).
2259+
bootstrappedEnablePlugins(DottyJSPlugin).
22522260
withCommonSettings.
22532261
settings(commonDistSettings).
22542262
dependsOn(
@@ -2261,6 +2269,9 @@ object Build {
22612269
scaladoc,
22622270
`scala3-sbt-bridge`, // for scala-cli
22632271
).
2272+
bootstrappedDependsOn(
2273+
`scala3-library-bootstrappedJS` // for scala-cli
2274+
).
22642275
bootstrappedSettings(
22652276
target := baseDirectory.value / "target" // override setting in commonBootstrappedSettings
22662277
)

project/Modes.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import sbt.{Project, ProjectReference, SettingsDefinition}
1+
import sbt.{Project, ProjectReference, SettingsDefinition, Plugins}
22

33
object Modes {
44

@@ -25,5 +25,9 @@ object Modes {
2525
def bootstrappedDependsOn(s: sbt.ClasspathDep[ProjectReference]*)(implicit mode: Mode): Project =
2626
if (mode == NonBootstrapped) project else project.dependsOn(s: _*)
2727

28+
/** Plugins only if the mode is bootstrapped */
29+
def bootstrappedEnablePlugins(ns: Plugins*)(implicit mode: Mode): Project =
30+
if (mode == NonBootstrapped) project else project.enablePlugins(ns: _*)
31+
2832
}
2933
}

project/RepublishPlugin.scala

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import sbt.Keys._
66
import sbt.AutoPlugin
77
import sbt.PublishBinPlugin
88
import sbt.PublishBinPlugin.autoImport._
9+
import sbt.io.Using
10+
import sbt.util.CacheImplicits._
911

1012
import scala.collection.mutable
1113
import java.nio.file.Files
@@ -20,8 +22,11 @@ object RepublishPlugin extends AutoPlugin {
2022
val republishProjectRefs = taskKey[Seq[ProjectRef]]("fetch the classpath deps from the project.")
2123
val republishLocalResolved = taskKey[Seq[ResolvedArtifacts]]("resolve local artifacts for distribution.")
2224
val republishAllResolved = taskKey[Seq[ResolvedArtifacts]]("Resolve the dependencies for the distribution")
23-
val republishClasspath = taskKey[File]("cache the dependencies for the distribution")
25+
val republishClasspath = taskKey[Set[File]]("cache the dependencies for the distribution")
26+
val republishFetchLaunchers = taskKey[Set[File]]("cache the launcher deps for the distribution")
27+
val republish = taskKey[File]("cache the dependencies and download launchers for the distribution")
2428
val republishRepo = settingKey[File]("the location to store the republished artifacts.")
29+
val republishLaunchers = settingKey[Seq[(String, String, URL)]]("launchers to download. Sequence of (name, version, URL).")
2530
}
2631

2732
import autoImport._
@@ -43,17 +48,17 @@ object RepublishPlugin extends AutoPlugin {
4348
val publishAllLocalBin = deps.map({ d => ((d / publishLocalBin / packagedArtifacts)) }).join
4449
val resolveId = deps.map({ d => ((d / projectID)) }).join
4550
Def.task {
46-
val s = streams.value
47-
val log = s.log
4851
val published = publishAllLocalBin.value
4952
val ids = resolveId.value
5053

5154
ids.zip(published).map({ case (id, as) =>
5255
val simpleId = {
56+
val disabled = CrossVersion.disabled
5357
val name0 = id.crossVersion match {
54-
case _: CrossVersion.Binary =>
58+
case cv: CrossVersion.Binary =>
5559
// projectID does not add binary suffix
56-
(id.name + "_3").ensuring(!id.name.endsWith("_3") && id.revision.startsWith("3."))
60+
(s"${id.name}_${cv.prefix}${cv.suffix}3")
61+
.ensuring(!id.name.endsWith("_3") && id.revision.startsWith("3."))
5762
case _ => id.name
5863
}
5964
SimpleModuleId(id.organization, name0, id.revision)
@@ -117,11 +122,15 @@ object RepublishPlugin extends AutoPlugin {
117122
found.values.toSeq
118123
},
119124
republishClasspath := {
125+
val s = streams.value
120126
val resolved = republishAllResolved.value
121127
val cacheDir = republishRepo.value
128+
129+
val log = s.log
122130
val mavenRepo = cacheDir / "maven2"
123131
IO.createDirectory(mavenRepo)
124-
resolved.foreach { ra =>
132+
resolved.map { ra =>
133+
log.info(s"[republish] publishing ${ra.id} to $mavenRepo...")
125134
val jar = ra.jar
126135
val pom = ra.pom
127136

@@ -130,7 +139,54 @@ object RepublishPlugin extends AutoPlugin {
130139
IO.createDirectory(artifactDir)
131140
IO.copyFile(jar, artifactDir / jar.getName)
132141
IO.copyFile(pom, artifactDir / pom.getName)
142+
artifactDir
143+
}.toSet
144+
},
145+
republishFetchLaunchers := {
146+
val s = streams.value
147+
val log = s.log
148+
val repoDir = republishRepo.value
149+
val launcherVersions = republishLaunchers.value
150+
151+
val etc = repoDir / "etc"
152+
153+
val store = s.cacheStoreFactory / "versions"
154+
155+
def work(dest: File, launcher: URL) = {
156+
IO.delete(dest)
157+
Using.urlInputStream(launcher) { in =>
158+
IO.createDirectory(etc)
159+
log.info(s"[republish] Downloading $launcher to $dest...")
160+
IO.transfer(in, dest)
161+
log.info(s"[republish] Downloaded $launcher to $dest...")
162+
}
163+
dest
164+
}
165+
166+
val allLaunchers = {
167+
for ((name, version, launcher) <- launcherVersions) yield {
168+
val dest = etc / name
169+
170+
val id = name.replaceAll("[^a-zA-Z0-9]", "_")
171+
172+
val fetchAction = Tracked.inputChanged[String, File](store.make(id)) { (inChanged, version) =>
173+
if (inChanged || !Files.exists(dest.toPath)) {
174+
work(dest, launcher)
175+
} else {
176+
log.info(s"[republish] Using cached $launcher at $dest...")
177+
dest
178+
}
179+
}
180+
181+
fetchAction(version)
182+
}
133183
}
184+
allLaunchers.toSet
185+
},
186+
republish := {
187+
val cacheDir = republishRepo.value
188+
val artifacts = republishClasspath.value
189+
val launchers = republishFetchLaunchers.value
134190
cacheDir
135191
}
136192
)

0 commit comments

Comments
 (0)