Skip to content

Commit

Permalink
Ensure directories are created recursively when calling package (#1371
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Gedochao authored Sep 19, 2022
1 parent 880242e commit 54aefdd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
10 changes: 5 additions & 5 deletions modules/cli/src/main/scala/scala/cli/commands/Package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -304,20 +304,20 @@ object Package extends ScalaCommand[PackageOptions] with BuildCommandHelpers {
val content = Library.libraryJar(build)
alreadyExistsCheck()
if (force) os.write.over(destPath, content)
else os.write(destPath, content)
else os.write(destPath, content, createFolders = true)
destPath
case PackageType.SourceJar =>
val now = System.currentTimeMillis()
val content = sourceJar(build, now)
alreadyExistsCheck()
if (force) os.write.over(destPath, content)
else os.write(destPath, content)
if (force) os.write.over(destPath, content, createFolders = true)
else os.write(destPath, content, createFolders = true)
destPath
case PackageType.DocJar =>
val docJarPath = value(docJar(build, logger, extraArgs))
alreadyExistsCheck()
if (force) os.copy.over(docJarPath, destPath)
else os.copy(docJarPath, destPath)
if (force) os.copy.over(docJarPath, destPath, createFolders = true)
else os.copy(docJarPath, destPath, createFolders = true)
destPath
case a: PackageType.Assembly =>
value {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ object ProcUtil {
content.drop("#!/bin/sh".length)
else
sys.error("Can't happen")
os.write.over(file, updatedContent)
os.write.over(file, updatedContent, createFolders = true)
}

usesSh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,24 @@ abstract class PackageTestDefinitions(val scalaVersionOpt: Option[String])
}
}

test("ensure directories are created recursively when packaging a jar") {
TestInputs(
os.rel / "Simple.scala" -> s"""object Simple extends App { println() }"""
).fromRoot { (root: os.Path) =>
val jarPath =
os.rel / "out" / "inner-out" / "Simple.jar" // the `out` directory doesn't exist and should be created
os.proc(
TestUtil.cli,
"package",
".",
"--library",
"-o",
jarPath,
extraOptions
).call(cwd = root)
}
}

def javaOptionsDockerTest(): Unit = {
val fileName = "Hello.scala"
val imageName = "hello"
Expand Down

0 comments on commit 54aefdd

Please sign in to comment.