Skip to content

Commit 04a8d16

Browse files
committed
cleanup
1 parent a04c07a commit 04a8d16

File tree

3 files changed

+69
-17
lines changed

3 files changed

+69
-17
lines changed

build.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ val `scala3-compiler-nonbootstrapped` = Build.`scala3-compiler-nonbootstrapped`
99
val `scala3-compiler-bootstrapped-new` = Build.`scala3-compiler-bootstrapped-new`
1010

1111
val `scala3-repl` = Build.`scala3-repl`
12+
val `scala3-repl-shaded` = Build.`scala3-repl-shaded`
1213
val `scala3-repl-embedded` = Build.`scala3-repl-embedded`
1314

1415
// The Standard Library

project/Build.scala

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,24 +1178,45 @@ object Build {
11781178
},
11791179
)
11801180

1181-
lazy val `scala3-repl-embedded` = project.in(file("repl-embedded"))
1181+
lazy val `scala3-repl-shaded` = project.in(file("repl-embedded"))
11821182
.dependsOn(`scala3-repl`)
1183-
.settings(publishSettings)
1183+
.enablePlugins(sbtassembly.AssemblyPlugin)
11841184
.settings(
1185-
name := "scala3-repl-embedded",
1186-
moduleName := "scala3-repl-embedded",
1185+
name := "scala3-repl-shaded",
1186+
moduleName := "scala3-repl-shaded",
11871187
version := dottyVersion,
11881188
versionScheme := Some("semver-spec"),
11891189
scalaVersion := referenceVersion,
11901190
crossPaths := true,
11911191
autoScalaLibrary := false,
1192+
// Expose assembly as packageBin for cross-project reference
1193+
Compile / packageBin := assembly.value,
11921194
// Source directories
11931195
Compile / unmanagedSourceDirectories := Seq(baseDirectory.value / "src"),
1196+
// Configure scalaInstance to use the bootstrapped compiler
1197+
scalaInstance := {
1198+
val scalaLibrary = (`scala-library-bootstrapped` / Compile / packageBin).value
1199+
val tastyCore = (`tasty-core-bootstrapped-new` / Compile / packageBin).value
1200+
val scala3Interfaces = (`scala3-interfaces` / Compile / packageBin).value
1201+
val scala3Compiler = (`scala3-compiler-bootstrapped-new` / Compile / packageBin).value
1202+
val externalCompilerDeps = (`scala3-compiler-bootstrapped-new` / Compile / externalDependencyClasspath).value.map(_.data).toSet
1203+
1204+
Defaults.makeScalaInstance(
1205+
dottyVersion,
1206+
libraryJars = Array(scalaLibrary),
1207+
allCompilerJars = Seq(tastyCore, scala3Interfaces, scala3Compiler) ++ externalCompilerDeps,
1208+
allDocJars = Seq.empty,
1209+
state.value,
1210+
scalaInstanceTopLoader.value
1211+
)
1212+
},
11941213
// Assembly configuration for shading
1195-
assembly / assemblyJarName := s"scala3-repl-embedded-${version.value}.jar",
1214+
assembly / assemblyJarName := s"scala3-repl-shaded-${version.value}.jar",
11961215
assembly / mainClass := Some("scala.tools.repl.EmbeddedReplMain"),
11971216
// Shading rules: relocate specific packages to dotty.tools.repl.shaded, except scala.*, java.*, javax.*
1217+
// Keep org.jline unshaded (needs to access native terminal libraries)
11981218
assembly / assemblyShadeRules := Seq(
1219+
ShadeRule.rename("org.jline.**" -> "org.jline.@1").inAll,
11991220
ShadeRule.rename("dotty.**" -> "dotty.tools.repl.shaded.dotty.@1").inAll,
12001221
ShadeRule.rename("org.**" -> "dotty.tools.repl.shaded.org.@1").inAll,
12011222
ShadeRule.rename("com.**" -> "dotty.tools.repl.shaded.com.@1").inAll,
@@ -1219,18 +1240,49 @@ object Build {
12191240
},
12201241
// Don't run tests for assembly
12211242
assembly / test := {},
1222-
// Publishing configuration: publish the assembly jar instead of regular jar
1223-
Compile / packageBin := assembly.value,
1243+
// Exclude scala-library and jline from assembly (users provide them on classpath)
1244+
assembly / assemblyExcludedJars := {
1245+
val cp = (assembly / fullClasspath).value
1246+
cp.filter { jar =>
1247+
val name = jar.data.getName
1248+
name.startsWith("scala-library") || name.startsWith("scala3-library") || name.startsWith("jline")
1249+
}
1250+
},
1251+
// Don't publish scala3-repl-shaded - it's an internal build artifact
1252+
publish / skip := true,
1253+
publishLocal / skip := true,
1254+
// Make assembly jar depend on compile
1255+
assembly := (assembly dependsOn (Compile / compile)).value,
1256+
)
1257+
1258+
lazy val `scala3-repl-embedded` = project.in(file("repl-embedded-publish"))
1259+
.dependsOn(`scala-library-bootstrapped`)
1260+
.settings(publishSettings)
1261+
.settings(
1262+
name := "scala3-repl-embedded",
1263+
moduleName := "scala3-repl-embedded",
1264+
version := dottyVersion,
1265+
versionScheme := Some("semver-spec"),
1266+
scalaVersion := referenceVersion,
1267+
crossPaths := true,
1268+
libraryDependencies ++= Seq(
1269+
"org.jline" % "jline-reader" % "3.29.0",
1270+
"org.jline" % "jline-terminal" % "3.29.0",
1271+
"org.jline" % "jline-terminal-jni" % "3.29.0",
1272+
),
1273+
// No source files in this project - just publishes the shaded jar
1274+
Compile / unmanagedSourceDirectories := Seq.empty,
1275+
// Use the shaded assembly jar as our packageBin
1276+
Compile / packageBin := (`scala3-repl-shaded` / Compile / packageBin).value,
12241277
Compile / packageBin / artifact := {
12251278
val art = (Compile / packageBin / artifact).value
12261279
art.withClassifier(None)
12271280
},
1281+
// Publish sources from scala3-repl-shaded
12281282
Compile / packageDoc / publishArtifact := false,
12291283
Compile / packageSrc / publishArtifact := true,
12301284
Test / publishArtifact := false,
12311285
publish / skip := false,
1232-
// Make assembly jar depend on packageBin in Compile scope
1233-
assembly := (assembly dependsOn (Compile / compile)).value,
12341286
)
12351287

12361288
// ==============================================================================================

repl-embedded/src/scala/tools/repl/EmbeddedReplMain.scala

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,15 @@ class UnshadingClassLoader(parent: ClassLoader) extends ClassLoader(parent) {
1919
// Packages that were shaded
2020
private val SHADED_PACKAGES = Seq("dotty.", "org.", "com.", "io.", "coursier.", "coursierapi.", "dependency.", "pprint.", "fansi.", "sourcecode.", "xsbti.")
2121

22+
// Packages that are NOT shaded (even though they match SHADED_PACKAGES patterns)
23+
private val UNSHADED_PACKAGES = Seq("scala.", "scala.tools.repl.", "org.jline.")
24+
2225
override def loadClass(name: String, resolve: Boolean): Class[?] = {
2326
// Check if this is a class from a package we shaded (and not already in the shaded package)
27+
// Also exclude packages that are explicitly not shaded
2428
val shouldUnshade = SHADED_PACKAGES.exists(pkg => name.startsWith(pkg)) &&
25-
!name.startsWith(SHADED_PREFIX)
29+
!name.startsWith(SHADED_PREFIX) &&
30+
!UNSHADED_PACKAGES.exists(pkg => name.startsWith(pkg))
2631

2732
if (shouldUnshade) {
2833
val loaded = findLoadedClass(name)
@@ -61,13 +66,7 @@ object EmbeddedReplMain {
6166
def main(args: Array[String]): Unit = {
6267
// Get the location of the current jar to use as classpath
6368
val codeSource = getClass.getProtectionDomain.getCodeSource
64-
val jarPath =
65-
if (codeSource == null) System.getProperty("java.class.path") // Fallback: try to extract from classpath
66-
else {
67-
val location = codeSource.getLocation
68-
if (location.getProtocol == "file") new java.io.File(location.toURI).getAbsolutePath
69-
else location.toString
70-
}
69+
val jarPath = System.getProperty("java.class.path")
7170

7271
// Add -classpath argument pointing to the shaded jar itself
7372
// This allows the ReplDriver's compiler to find scala.* classes

0 commit comments

Comments
 (0)