Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
lihaoyi committed Oct 20, 2024
1 parent 451ec65 commit 269f73d
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 51 deletions.
54 changes: 27 additions & 27 deletions os/src/ProcessOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ object call {
* @see [[os.proc.call]]
*/
def apply(
cmd: Shellable,
env: Map[String, String] = null,
// Make sure `cwd` only comes after `env`, so `os.call("foo", path)` is a compile error
// since the correct syntax is `os.call(("foo", path))`
cwd: Path = null,
stdin: ProcessInput = Pipe,
stdout: ProcessOutput = Pipe,
stderr: ProcessOutput = os.Inherit,
mergeErrIntoOut: Boolean = false,
timeout: Long = -1,
check: Boolean = true,
propagateEnv: Boolean = true,
shutdownGracePeriod: Long = 100,
shutdownHook: Boolean = false
cmd: Shellable,
env: Map[String, String] = null,
// Make sure `cwd` only comes after `env`, so `os.call("foo", path)` is a compile error
// since the correct syntax is `os.call(("foo", path))`
cwd: Path = null,
stdin: ProcessInput = Pipe,
stdout: ProcessOutput = Pipe,
stderr: ProcessOutput = os.Inherit,
mergeErrIntoOut: Boolean = false,
timeout: Long = -1,
check: Boolean = true,
propagateEnv: Boolean = true,
shutdownGracePeriod: Long = 100,
shutdownHook: Boolean = false
): CommandResult = {
os.proc(cmd).call(
cwd = cwd,
Expand Down Expand Up @@ -186,18 +186,18 @@ case class proc(command: Shellable*) {
* issued. Check the documentation for your JDK's `Process.destroy`.
*/
def call(
cwd: Path = null,
env: Map[String, String] = null,
stdin: ProcessInput = Pipe,
stdout: ProcessOutput = Pipe,
stderr: ProcessOutput = os.Inherit,
mergeErrIntoOut: Boolean = false,
timeout: Long = -1,
check: Boolean = true,
propagateEnv: Boolean = true,
// this cannot be next to `timeout` as this will introduce a bin-compat break (default arguments are numbered in the bytecode)
shutdownGracePeriod: Long = 100,
shutdownHook: Boolean = false
cwd: Path = null,
env: Map[String, String] = null,
stdin: ProcessInput = Pipe,
stdout: ProcessOutput = Pipe,
stderr: ProcessOutput = os.Inherit,
mergeErrIntoOut: Boolean = false,
timeout: Long = -1,
check: Boolean = true,
propagateEnv: Boolean = true,
// this cannot be next to `timeout` as this will introduce a bin-compat break (default arguments are numbered in the bytecode)
shutdownGracePeriod: Long = 100,
shutdownHook: Boolean = false
): CommandResult = {

val chunks = new java.util.concurrent.ConcurrentLinkedQueue[Either[geny.Bytes, geny.Bytes]]
Expand Down Expand Up @@ -327,7 +327,7 @@ case class proc(command: Shellable*) {
override def run(): Unit = {
while (proc.wrapped.isAlive) Thread.sleep(1)
try Runtime.getRuntime().removeShutdownHook(t)
catch{case e: Throwable => /*do nothing*/}
catch { case e: Throwable => /*do nothing*/ }
}
}
)
Expand Down
5 changes: 4 additions & 1 deletion os/src/SubProcess.scala
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ class SubProcess(
* (i.e. force exit immediately) or Long.MaxValue (i.e. never force exit)
* or anything in between. Typically defaults to 100 milliseconds
*/
def destroy(shutdownGracePeriod: Long = this.shutdownGracePeriod, async: Boolean = false): Unit = {
def destroy(
shutdownGracePeriod: Long = this.shutdownGracePeriod,
async: Boolean = false
): Unit = {
wrapped.destroy()
if (!async) {
val now = System.currentTimeMillis()
Expand Down
11 changes: 5 additions & 6 deletions os/test/src-jvm/SpawningSubprocessesNewTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ object SpawningSubprocessesNewTests extends TestSuite {
sha.stdout.trim() ==> s"${ExampleResourcess.RemoteReadme.gzip6ShaSum256} -"
}
}
test("spawn callback") - prep { wd =>
test("spawn callback") - prep { wd =>
if (TestUtil.isInstalled("echo") && Unix()) {
val output: mutable.Buffer[String] = mutable.Buffer()
val sub = os.spawn(
Expand All @@ -174,16 +174,16 @@ object SpawningSubprocessesNewTests extends TestSuite {
.open(p.toNIO, util.EnumSet.of(StandardOpenOption.READ, StandardOpenOption.WRITE))
.tryLock()
def waitForLockTaken(p: os.Path) = {
while({
while ({
val waitLock = tryLock(p)
if (waitLock != null) {
waitLock.release()
true
}else false
} else false
}) Thread.sleep(1)
}

test("destroy"){
test("destroy") {
val temp1 = os.temp()
val sub1 = os.spawn((sys.env("TEST_SPAWN_EXIT_HOOK_ASSEMBLY"), temp1))
waitForLockTaken(temp1)
Expand All @@ -197,8 +197,7 @@ object SpawningSubprocessesNewTests extends TestSuite {
assert(sub2.isAlive())
}

test("spawnExitHook"){

test("spawnExitHook") {

val temp = os.temp()
val lock0 = tryLock(temp)
Expand Down
32 changes: 16 additions & 16 deletions os/test/src-jvm/SpawningSubprocessesTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -147,23 +147,23 @@ object SpawningSubprocessesTests extends TestSuite {
}
}
test("spawn callback") {
test - prep { wd =>
if (TestUtil.isInstalled("echo") && Unix()) {
val output: mutable.Buffer[String] = mutable.Buffer()
val sub = os.proc("echo", "output")
.spawn(stdout =
ProcessOutput((bytes, count) => output += new String(bytes, 0, count))
)
val finished = sub.join(5000)
sub.wrapped.getOutputStream().flush()
assert(finished)
assert(sub.exitCode() == 0)
val expectedOutput = "output\n"
val actualOutput = output.mkString("")
assert(actualOutput == expectedOutput)
sub.destroy()
}
test - prep { wd =>
if (TestUtil.isInstalled("echo") && Unix()) {
val output: mutable.Buffer[String] = mutable.Buffer()
val sub = os.proc("echo", "output")
.spawn(stdout =
ProcessOutput((bytes, count) => output += new String(bytes, 0, count))
)
val finished = sub.join(5000)
sub.wrapped.getOutputStream().flush()
assert(finished)
assert(sub.exitCode() == 0)
val expectedOutput = "output\n"
val actualOutput = output.mkString("")
assert(actualOutput == expectedOutput)
sub.destroy()
}
}
}
}
}
2 changes: 1 addition & 1 deletion os/test/testSpawnExitHook/src/TestSpawnExitHook.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package test.os

object TestSpawnExitHook{
object TestSpawnExitHook {
def main(args: Array[String]): Unit = {
os.spawn((sys.env("TEST_SPAWN_EXIT_HOOK_ASSEMBLY2"), args(0)), shutdownHook = true)
Thread.sleep(99999)
Expand Down

0 comments on commit 269f73d

Please sign in to comment.