diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-04-09 01:23:02 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-04-09 01:23:02 +0000 |
commit | 07cfb683a4c9ec3ecbe22fba6675cebd3fdf2ab2 (patch) | |
tree | a2ae586bb3aa4547427669106248620f8dba03b2 | |
parent | a2ab6d8f97983e44da5ac6b178d3721102b8ead6 (diff) | |
download | ruby-07cfb683a4c9ec3ecbe22fba6675cebd3fdf2ab2.tar.gz |
default.mspec: defer job tokens
* spec/default.mspec (MSpecScript::JobServer#cores): defer getting
job tokens until required. when running only one spec file,
`-j` option has no effect.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58282 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | spec/default.mspec | 53 |
1 files changed, 33 insertions, 20 deletions
diff --git a/spec/default.mspec b/spec/default.mspec index 082d432c7f..1c9bbf2db7 100644 --- a/spec/default.mspec +++ b/spec/default.mspec @@ -25,27 +25,40 @@ class MSpecScript ] end -class MSpecScript - if /(?:\A|\s)--jobserver-(?:auth|fds)=(\d+),(\d+)/ =~ ENV["MAKEFLAGS"] - begin - r = IO.for_fd($1.to_i(10), "rb", autoclose: false) - w = IO.for_fd($2.to_i(10), "wb", autoclose: false) - rescue - r.close if r - else - jobtokens = r.read_nonblock(1024) - cores = jobtokens.size - if cores > 0 - jobserver = w - at_exit { - jobserver.print(jobtokens) - jobserver.close - } - end - remove_method :cores - define_method(:cores) do - cores +module MSpecScript::JobServer + def cores + if /(?:\A|\s)--jobserver-(?:auth|fds)=(\d+),(\d+)/ =~ ENV["MAKEFLAGS"] + cores = 0 + begin + r = IO.for_fd($1.to_i(10), "rb", autoclose: false) + w = IO.for_fd($2.to_i(10), "wb", autoclose: false) + jobtokens = r.read_nonblock(1024) + else + cores = jobtokens.size + if cores > 0 + jobserver = w + w = nil + at_exit { + jobserver.print(jobtokens) + jobserver.close + } + MSpecScript::JobServer.module_eval do + remove_method :cores + define_method(:cores) do + cores + end + end + return cores + end + ensure + r&.close + w&.close end end + super end end + +class MSpecScript + prepend JobServer +end |