Skip to content

Commit 6f680d2

Browse files
committed
Make package command output name fallback to actual compiled main class name if there's no default main class override present
1 parent 38fd674 commit 6f680d2

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

modules/cli/src/main/scala/scala/cli/commands/Package.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ object Package extends ScalaCommand[PackageOptions] {
188188
.map(_.stripSuffix("_sc"))
189189
.map(_ + extension)
190190
}
191+
.orElse(build.retainedMainClass.map(_.stripSuffix("_sc") + extension).toOption)
192+
.orElse(build.sources.paths.collectFirst(_._1.baseName + extension))
191193
.getOrElse(defaultName)
192194
val destPath = os.Path(dest, Os.pwd)
193195
val printableDest = CommandUtils.printablePath(destPath)

modules/integration/src/test/scala/scala/cli/integration/PackageTestDefinitions.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ abstract class PackageTestDefinitions(val scalaVersionOpt: Option[String])
7777
stdout = os.Inherit
7878
)
7979

80-
val outputName = if (Properties.isWin) "app.bat" else "app"
80+
val outputName = if (Properties.isWin) "simple.bat" else "simple"
8181
val launcher = root / outputName
8282

8383
expect(os.isFile(launcher))
@@ -109,7 +109,7 @@ abstract class PackageTestDefinitions(val scalaVersionOpt: Option[String])
109109
stdout = os.Inherit
110110
)
111111

112-
val outputName = if (Properties.isWin) "app.bat" else "app"
112+
val outputName = if (Properties.isWin) "hello.bat" else "hello"
113113
val launcher = root / outputName
114114

115115
val output = os.proc(launcher.toString).call(cwd = root).out.text().trim
@@ -171,7 +171,7 @@ abstract class PackageTestDefinitions(val scalaVersionOpt: Option[String])
171171
stdout = os.Inherit
172172
)
173173

174-
val outputName = if (Properties.isWin) "app.bat" else "app"
174+
val outputName = if (Properties.isWin) "hello.bat" else "hello"
175175
val launcher = root / outputName
176176

177177
val output = os.proc(launcher.toString).call(cwd = root).out.text().trim
@@ -324,7 +324,7 @@ abstract class PackageTestDefinitions(val scalaVersionOpt: Option[String])
324324
os.rel / fileName ->
325325
s"""|//> using jsHeader "$jsHeaderNewLine"
326326
|//> using jsMode "release"
327-
|
327+
|
328328
|object Hello extends App {
329329
| println("Hello")
330330
|}
@@ -480,7 +480,7 @@ abstract class PackageTestDefinitions(val scalaVersionOpt: Option[String])
480480
stdout = os.Inherit
481481
)
482482

483-
val outputName = if (Properties.isWin) "app.bat" else "app"
483+
val outputName = if (Properties.isWin) "Main.bat" else "Main"
484484
val launcher = root / outputName
485485

486486
val output = os.proc(launcher.toString).call(cwd = root).out.text().trim

website/docs/cookbooks/scala-package.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The JAR file only contains the byte code that’s generated from your source cod
88

99
As an example, the following snippet contains a short application to detect the OS:
1010
```scala title=DetectOsApp.scala
11-
object DetectOSApp extends App {
11+
object DetectOsApp extends App {
1212
def getOperatingSystem(): String = {
1313
val os: String = System.getProperty("os.name")
1414
os

0 commit comments

Comments
 (0)