2020-10-10 14:16:11 +02:00
|
|
|
# typed: false
|
2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
require "hardware"
|
2020-09-11 12:05:22 +01:00
|
|
|
require "diagnostic"
|
2015-08-03 13:09:07 +01:00
|
|
|
require "extend/ENV/shared"
|
|
|
|
require "extend/ENV/std"
|
|
|
|
require "extend/ENV/super"
|
2013-08-19 12:32:57 -05:00
|
|
|
|
2020-07-28 02:04:50 +02:00
|
|
|
def superenv?(env)
|
|
|
|
env != "std" && Superenv.bin
|
2013-08-19 12:32:57 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
module EnvActivation
|
2020-07-28 02:04:50 +02:00
|
|
|
def activate_extensions!(env: nil)
|
|
|
|
if superenv?(env)
|
2013-08-19 12:32:57 -05:00
|
|
|
extend(Superenv)
|
|
|
|
else
|
2013-08-19 12:32:59 -05:00
|
|
|
extend(Stdenv)
|
2013-08-19 12:32:57 -05:00
|
|
|
end
|
|
|
|
end
|
2013-08-19 12:32:59 -05:00
|
|
|
|
2020-07-28 02:04:50 +02:00
|
|
|
def with_build_environment(env: nil, cc: nil, build_bottle: false, bottle_arch: nil)
|
2013-08-19 12:32:59 -05:00
|
|
|
old_env = to_hash.dup
|
|
|
|
tmp_env = to_hash.dup.extend(EnvActivation)
|
2020-07-28 02:04:50 +02:00
|
|
|
tmp_env.activate_extensions!(env: env)
|
|
|
|
tmp_env.setup_build_environment(cc: cc, build_bottle: build_bottle, bottle_arch: bottle_arch)
|
2013-08-19 12:32:59 -05:00
|
|
|
replace(tmp_env)
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
replace(old_env)
|
|
|
|
end
|
2017-04-22 16:31:19 +01:00
|
|
|
|
2019-07-13 22:48:22 +08:00
|
|
|
def sensitive?(key)
|
|
|
|
/(cookie|key|token|password)/i =~ key
|
|
|
|
end
|
2018-09-17 02:45:00 +02:00
|
|
|
|
2019-07-13 22:48:22 +08:00
|
|
|
def sensitive_environment
|
|
|
|
select { |key, _| sensitive?(key) }
|
|
|
|
end
|
|
|
|
|
|
|
|
def clear_sensitive_environment!
|
|
|
|
each_key { |key| delete key if sensitive?(key) }
|
2017-04-22 16:31:19 +01:00
|
|
|
end
|
2013-08-19 12:32:57 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
ENV.extend(EnvActivation)
|