ruby-changes:46169
From: nobu <ko1@a...>
Date: Sun, 9 Apr 2017 10:23:08 +0900 (JST)
Subject: [ruby-changes:46169] nobu:r58282 (trunk): default.mspec: defer job tokens
nobu 2017-04-09 10:23:02 +0900 (Sun, 09 Apr 2017) New Revision: 58282 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58282 Log: 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. Modified files: trunk/spec/default.mspec Index: spec/default.mspec =================================================================== --- spec/default.mspec (revision 58281) +++ spec/default.mspec (revision 58282) @@ -25,27 +25,40 @@ class MSpecScript https://github.com/ruby/ruby/blob/trunk/spec/default.mspec#L25 ] 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/