Skip to content

Commit 27e6d31

Browse files
committed
review tweaks
1 parent 29b5ef2 commit 27e6d31

File tree

4 files changed

+32
-45
lines changed

4 files changed

+32
-45
lines changed

build.sc

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import $file.project.settings, settings.{
1212
PublishLocalNoFluff,
1313
ScalaCliCrossSbtModule,
1414
ScalaCliScalafixModule,
15+
ScalaCliCompile,
1516
localRepoResourcePath,
1617
platformExecutableJarExtension,
1718
workspaceDirName
@@ -418,22 +419,14 @@ class Options(val crossScalaVersion: String) extends BuildLikeModule {
418419
}
419420
}
420421

421-
trait ScalaParse extends SbtModule with ScalaCliPublishModule with settings.ScalaCliCompile {
422+
trait ScalaParse extends SbtModule with ScalaCliPublishModule with ScalaCliCompile {
422423
def ivyDeps = super.ivyDeps() ++ Agg(Deps.scalaparse)
423424
def scalaVersion = Scala.defaultInternal
424425
}
425426

426-
trait Scala3Runtime extends SbtModule with ScalaCliPublishModule with settings.ScalaCliCompile {
427-
def ivyDeps = super.ivyDeps() ++ Agg(Deps.scalaparse)
427+
trait Scala3Runtime extends SbtModule with ScalaCliPublishModule with ScalaCliCompile {
428+
def ivyDeps = super.ivyDeps()
428429
def scalaVersion = Scala.scala3
429-
def jar = T {
430-
val original = super.jar().path
431-
// scala3RuntimeFixes.jar is also used within
432-
// resource-config.json and BytecodeProcessor.scala
433-
val dest = original / os.up / "scala3RuntimeFixes.jar"
434-
os.copy(original, dest)
435-
PathRef(dest)
436-
}
437430
}
438431

439432
class Scala3Graal(val crossScalaVersion: String) extends BuildLikeModule {
@@ -443,15 +436,21 @@ class Scala3Graal(val crossScalaVersion: String) extends BuildLikeModule {
443436
)
444437

445438
def resources = T.sources {
446-
super.resources() ++ Seq(`scala3-runtime`.jar())
439+
val extraResourceDir = T.dest / "extra"
440+
// scala3RuntimeFixes.jar is also used within
441+
// resource-config.json and BytecodeProcessor.scala
442+
os.copy.over(
443+
`scala3-runtime`.jar().path,
444+
extraResourceDir / "scala3RuntimeFixes.jar",
445+
createFolders = true
446+
)
447+
super.resources() ++ Seq(mill.PathRef(extraResourceDir))
447448
}
448449
}
449450

450451
trait Scala3GraalProcessor extends ScalaModule {
451-
def moduleDeps = Seq(`scala3-graal`(Scala.scala3))
452-
def scalaVersion = Scala.scala3
453-
// Make sure that we put jar on run classpath
454-
def runClasspath = T(`scala3-graal`(Scala.scala3).jar() +: super.runClasspath())
452+
def moduleDeps = Seq(`scala3-graal`(Scala.scala3))
453+
def scalaVersion = Scala.scala3
455454
def finalMainClass = "scala.cli.graal.CoursierCacheProcessor"
456455
}
457456

@@ -519,7 +518,7 @@ class Build(val crossScalaVersion: String) extends BuildLikeModule {
519518
}
520519
}
521520

522-
trait CliOptions extends SbtModule with ScalaCliPublishModule with settings.ScalaCliCompile {
521+
trait CliOptions extends SbtModule with ScalaCliPublishModule with ScalaCliCompile {
523522
def ivyDeps = super.ivyDeps() ++ Agg(
524523
Deps.caseApp,
525524
Deps.jsoniterCore,
@@ -553,9 +552,6 @@ trait Cli extends SbtModule with ProtoBuildModule with CliLaunchers
553552
`scala3-graal`(myScalaVersion)
554553
)
555554

556-
// We are adding graal as compile deps and adding jat on classpath since we want to build a native image from jar not from directories
557-
def runClasspath = T(Seq(`scala3-graal`(myScalaVersion).jar()) ++ super.runClasspath())
558-
559555
def repositories = super.repositories ++ customRepositories
560556

561557
def ivyDeps = super.ivyDeps() ++ Agg(
@@ -587,8 +583,6 @@ trait Cli extends SbtModule with ProtoBuildModule with CliLaunchers
587583
trait Cli3 extends Cli {
588584
override def myScalaVersion = Scala.scala3
589585

590-
val argsFile = os.pwd / os.RelPath("out") / ".graal-cp-args"
591-
592586
override def nativeImageClassPath = T {
593587
// TODO - results are cached - need to add inputs or caching method
594588
val classpath = super.nativeImageClassPath().map(_.path).mkString(File.pathSeparator)

modules/cli/src/main/scala/scala/cli/packaging/NativeImage.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,15 +234,15 @@ object NativeImage {
234234
maybeWithManifestClassPath(
235235
createManifest = Properties.isWin,
236236
classPath = originalClasspath.map(os.Path(_, os.pwd))
237-
) { processedClasspath =>
237+
) { processedClassPath =>
238238
val (classPath, toClean, scala3extraOptions) =
239239
if (!build.scalaParams.scalaBinaryVersion.startsWith("3"))
240-
(processedClasspath, Seq[os.Path](), Seq[String]())
240+
(processedClassPath, Seq[os.Path](), Seq[String]())
241241
else {
242242
val coursierCacheLocation = os.Path(FileCache().location.toPath())
243243
val cache = CoursierCache(coursierCacheLocation)
244-
val cpString = processedClasspath.mkString(File.pathSeparator)
245-
val processed = BytecodeProcessor.processClasspath(cpString, cache).toSeq
244+
val cpString = processedClassPath.mkString(File.pathSeparator)
245+
val processed = BytecodeProcessor.processClassPath(cpString, cache).toSeq
246246
val nativeConfigFile = os.temp(suffix = ".json")
247247
os.write.over(
248248
nativeConfigFile,

modules/scala3-graal/src/main/scala/scala/cli/graal/BytecodeProcessor.scala

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ object BytecodeProcessor {
5252
}
5353

5454
def processPathingJar(pathingJar: String, cache: JarCache): Seq[ClassPathEntry] = {
55-
val originalJar = toPath(pathingJar)
55+
val originalJar = os.Path(pathingJar, os.pwd)
5656
val jarFile = new JarFile(originalJar.toIO)
5757
try {
5858
val cp = jarFile.getManifest().getMainAttributes().getValue(Attributes.Name.CLASS_PATH)
5959
if (cp != null && cp.nonEmpty) {
6060
// paths in pathing jars are spectated by spaces
6161
val entries = cp.split(" +").toSeq
62-
val processedCp = processClasspathEntries(entries, cache)
62+
val processedCp = processClassPathEntries(entries, cache)
6363
val dest = os.temp(suffix = ".jar")
6464
val outStream = Files.newOutputStream(dest.toNIO, StandardOpenOption.CREATE)
6565
try {
@@ -73,22 +73,22 @@ object BytecodeProcessor {
7373
}
7474
finally outStream.close()
7575
}
76-
else processClasspathEntries(Seq(pathingJar), cache)
76+
else processClassPathEntries(Seq(pathingJar), cache)
7777
}
7878
finally jarFile.close()
7979
}
8080

81-
def processClasspath(classpath: String, cache: JarCache = TempCache): Seq[ClassPathEntry] = {
82-
val cp = classpath.split(File.pathSeparator)
83-
if (cp.size == 1 && cp.head.endsWith(".jar"))
84-
processPathingJar(cp.head, cache)
85-
else
86-
processClasspathEntries(cp.toSeq, cache)
87-
}
81+
def processClassPath(classPath: String, cache: JarCache = TempCache): Seq[ClassPathEntry] =
82+
classPath.split(File.pathSeparator) match {
83+
case Array(maybePathingJar) if maybePathingJar.endsWith(".jar") =>
84+
processPathingJar(maybePathingJar, cache)
85+
case cp =>
86+
processClassPathEntries(cp.toSeq, cache)
87+
}
8888

89-
def processClasspathEntries(entries: Seq[String], cache: JarCache): Seq[ClassPathEntry] = {
89+
def processClassPathEntries(entries: Seq[String], cache: JarCache): Seq[ClassPathEntry] = {
9090
val cp = entries.map { str =>
91-
val path = toPath(str)
91+
val path = os.Path(str, os.pwd)
9292
cache.cache(path) { dest =>
9393
if (path.ext == "jar" && os.isFile(path)) processJar(path, dest, cache)
9494
else if (os.isDir(path)) processDir(path, dest, cache)
@@ -244,10 +244,4 @@ object BytecodeProcessor {
244244
else
245245
super.visitMethod(access, name, desc, sig, exceptions)
246246
}
247-
248-
def toPath(str: String) = os.FilePath(str) match {
249-
case p: os.Path => p
250-
case r: os.RelPath => os.pwd / r
251-
case s: os.SubPath => os.pwd / s
252-
}
253247
}

project/settings.sc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ trait CliLaunchers extends SbtModule { self =>
198198
else staticLibDir().path.toString
199199
Seq(
200200
s"-H:IncludeResources=$localRepoResourcePath",
201-
"-H:IncludeResources='.*scala3RuntimeFixes.jar$'",
202201
"-H:-ParseRuntimeOptions",
203202
s"-H:CLibraryPath=$cLibPath"
204203
)

0 commit comments

Comments
 (0)