diff options
-rw-r--r-- | config.rb.example | 2 | ||||
-rw-r--r-- | nyabuild.rb | 19 |
2 files changed, 13 insertions, 8 deletions
diff --git a/config.rb.example b/config.rb.example index d218121..02bb38e 100644 --- a/config.rb.example +++ b/config.rb.example @@ -65,7 +65,7 @@ NyaConfig.configure( t.run "gem install --no-user-install -N rake-compiler test-unit" t.run "rake compile -- --with-openssl-dir=#{t.s openssl.prefix} --enable-debug" - t.run "rake test TESTOPTS=-v OSSL_MDEBUG=1" + t.run "rake test TESTOPTS=-v OSSL_MDEBUG=1", timeout: 300 } }, } diff --git a/nyabuild.rb b/nyabuild.rb index 37df4eb..cdadb23 100644 --- a/nyabuild.rb +++ b/nyabuild.rb @@ -58,14 +58,19 @@ class NyaBuildTarget @logger = logger end - private def run0(cmd, **opts) + private def run0(cmd, timeout: nil) @logger.log(cmd) - status = Open3.popen2e(cmd, **opts) { |stdin, mergedout, wait_thread| - stdin.close - FileUtils.copy_stream(mergedout, @logger.io) - wait_thread.value - } - unless status.success? + pid = spawn({}, *cmd, pgroup: true, [:out, :err] => @logger.io) + th = Thread.new { _, status = Process.waitpid2(-pid); status } + unless th.join(timeout) + th.kill; th.join + @logger.warn("Execution timed out (%p sec)", timeout) + Process.kill(:KILL, -pid) + _, status = Process.waitpid2(-pid) + raise status.inspect + end + + unless (status = th.value).success? @logger.warn(status.inspect) raise status.inspect end |