2020-11-20 14:20:38 +01:00
|
|
|
# typed: strict
|
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-11-20 14:20:38 +01:00
|
|
|
module Kernel
|
|
|
|
extend T::Sig
|
|
|
|
|
|
|
|
sig { params(env: T.nilable(String)).returns(T::Boolean) }
|
|
|
|
def superenv?(env)
|
|
|
|
return false if env == "std"
|
|
|
|
|
|
|
|
!Superenv.bin.nil?
|
|
|
|
end
|
|
|
|
private :superenv?
|
2013-08-19 12:32:57 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
module EnvActivation
|
2020-11-20 14:20:38 +01:00
|
|
|
extend T::Sig
|
|
|
|
|
|
|
|
sig { params(env: T.nilable(String)).void }
|
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-11-20 14:20:38 +01:00
|
|
|
sig do
|
|
|
|
params(
|
|
|
|
env: T.nilable(String),
|
|
|
|
cc: T.nilable(String),
|
|
|
|
build_bottle: T.nilable(T::Boolean),
|
|
|
|
bottle_arch: T.nilable(String),
|
|
|
|
_block: T.proc.returns(T.untyped),
|
|
|
|
).returns(T.untyped)
|
|
|
|
end
|
|
|
|
def with_build_environment(env: nil, cc: nil, build_bottle: false, bottle_arch: nil, &_block)
|
2013-08-19 12:32:59 -05:00
|
|
|
old_env = to_hash.dup
|
|
|
|
tmp_env = to_hash.dup.extend(EnvActivation)
|
2020-11-20 14:20:38 +01:00
|
|
|
T.cast(tmp_env, EnvActivation).activate_extensions!(env: env)
|
|
|
|
T.cast(tmp_env, T.any(Superenv, Stdenv))
|
|
|
|
.setup_build_environment(cc: cc, build_bottle: build_bottle, bottle_arch: bottle_arch)
|
2013-08-19 12:32:59 -05:00
|
|
|
replace(tmp_env)
|
2020-11-20 14:20:38 +01:00
|
|
|
|
|
|
|
begin
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
replace(old_env)
|
|
|
|
end
|
2013-08-19 12:32:59 -05:00
|
|
|
end
|
2017-04-22 16:31:19 +01:00
|
|
|
|
2020-11-20 14:20:38 +01:00
|
|
|
sig { params(key: T.any(String, Symbol)).returns(T::Boolean) }
|
2019-07-13 22:48:22 +08:00
|
|
|
def sensitive?(key)
|
2020-11-20 14:20:38 +01:00
|
|
|
key.match?(/(cookie|key|token|password)/i)
|
2019-07-13 22:48:22 +08:00
|
|
|
end
|
2018-09-17 02:45:00 +02:00
|
|
|
|
2020-11-20 14:20:38 +01:00
|
|
|
sig { returns(T::Hash[String, String]) }
|
2019-07-13 22:48:22 +08:00
|
|
|
def sensitive_environment
|
|
|
|
select { |key, _| sensitive?(key) }
|
|
|
|
end
|
|
|
|
|
2020-11-20 14:20:38 +01:00
|
|
|
sig { void }
|
2019-07-13 22:48:22 +08:00
|
|
|
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)
|