ENV.deparallelize: add block form for temporary change
Closes Homebrew/homebrew#39026.
This commit is contained in:
parent
789390f378
commit
f5d6d80d5b
@ -78,8 +78,22 @@ module Stdenv
|
||||
paths.select { |d| File.directory? d }.join(File::PATH_SEPARATOR)
|
||||
end
|
||||
|
||||
# Removes the MAKEFLAGS environment variable, causing make to use a single job.
|
||||
# This is useful for makefiles with race conditions.
|
||||
# When passed a block, MAKEFLAGS is removed only for the duration of the block and is restored after its completion.
|
||||
# Returns the value of MAKEFLAGS.
|
||||
def deparallelize
|
||||
old = self['MAKEFLAGS']
|
||||
remove 'MAKEFLAGS', /-j\d+/
|
||||
if block_given?
|
||||
begin
|
||||
yield
|
||||
ensure
|
||||
self['MAKEFLAGS'] = old
|
||||
end
|
||||
end
|
||||
|
||||
old
|
||||
end
|
||||
alias_method :j1, :deparallelize
|
||||
|
||||
|
@ -241,8 +241,21 @@ module Superenv
|
||||
|
||||
public
|
||||
|
||||
# Removes the MAKEFLAGS environment variable, causing make to use a single job.
|
||||
# This is useful for makefiles with race conditions.
|
||||
# When passed a block, MAKEFLAGS is removed only for the duration of the block and is restored after its completion.
|
||||
# Returns the value of MAKEFLAGS.
|
||||
def deparallelize
|
||||
delete('MAKEFLAGS')
|
||||
old = delete('MAKEFLAGS')
|
||||
if block_given?
|
||||
begin
|
||||
yield
|
||||
ensure
|
||||
self['MAKEFLAGS'] = old
|
||||
end
|
||||
end
|
||||
|
||||
old
|
||||
end
|
||||
alias_method :j1, :deparallelize
|
||||
|
||||
|
@ -114,6 +114,14 @@ module SharedEnvTests
|
||||
assert_equal compiler, @env.compiler
|
||||
end
|
||||
end
|
||||
|
||||
def test_deparallelize_block_form_restores_makeflags
|
||||
@env['MAKEFLAGS'] = '-j4'
|
||||
@env.deparallelize do
|
||||
assert_nil @env['MAKEFLAGS']
|
||||
end
|
||||
assert_equal '-j4', @env['MAKEFLAGS']
|
||||
end
|
||||
end
|
||||
|
||||
class StdenvTests < Homebrew::TestCase
|
||||
|
Loading…
x
Reference in New Issue
Block a user