-
-
Notifications
You must be signed in to change notification settings - Fork 938
Expand file tree
/
Copy pathrbconfig.rb
More file actions
77 lines (74 loc) · 2.35 KB
/
rbconfig.rb
File metadata and controls
77 lines (74 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Load built-in rbconfig library
JRuby::Util.load_ext("org.jruby.ext.rbconfig.RbConfigLibrary")
module RbConfig
# call-seq:
#
# RbConfig.expand(val) -> string
# RbConfig.expand(val, config) -> string
#
# expands variable with given +val+ value.
#
# RbConfig.expand("$(bindir)") # => /home/foobar/all-ruby/ruby19x/bin
def RbConfig::expand(val, config = CONFIG)
newval = val.gsub(/\$\$|\$\(([^()]+)\)|\$\{([^{}]+)\}/) {
var = $&
if !(v = $1 || $2)
'$'
elsif key = config[v = v[/\A[^:]+(?=(?::(.*?)=(.*))?\z)/]]
pat, sub = $1, $2
config[v] = false
config[v] = RbConfig::expand(key, config)
key = key.gsub(/#{Regexp.quote(pat)}(?=\s|\z)/n) {sub} if pat
key
else
var
end
}
val.replace(newval) unless newval == val
val
end
CONFIG.each_value do |val|
RbConfig::expand(val)
end
# call-seq:
#
# RbConfig.fire_update!(key, val) -> array
# RbConfig.fire_update!(key, val, mkconf, conf) -> array
#
# updates +key+ in +mkconf+ with +val+, and all values depending on
# the +key+ in +mkconf+.
#
# RbConfig::MAKEFILE_CONFIG.values_at("CC", "LDSHARED") # => ["gcc", "$(CC) -shared"]
# RbConfig::CONFIG.values_at("CC", "LDSHARED") # => ["gcc", "gcc -shared"]
# RbConfig.fire_update!("CC", "gcc-8") # => ["CC", "LDSHARED"]
# RbConfig::MAKEFILE_CONFIG.values_at("CC", "LDSHARED") # => ["gcc-8", "$(CC) -shared"]
# RbConfig::CONFIG.values_at("CC", "LDSHARED") # => ["gcc-8", "gcc-8 -shared"]
#
# returns updated keys list, or +nil+ if nothing changed.
def RbConfig.fire_update!(key, val, mkconf = MAKEFILE_CONFIG, conf = CONFIG) # :nodoc:
return if mkconf[key] == val
mkconf[key] = val
keys = [key]
deps = []
begin
re = Regexp.new("\\$\\((?:%1$s)\\)|\\$\\{(?:%1$s)\\}" % keys.join('|'))
deps |= keys
keys.clear
mkconf.each {|k,v| keys << k if re =~ v}
end until keys.empty?
deps.each {|k| conf[k] = mkconf[k].dup}
deps.each {|k| expand(conf[k])}
deps
end
# call-seq:
#
# RbConfig.ruby -> path
#
# returns the absolute pathname of the ruby command.
def RbConfig.ruby
File.join(
RbConfig::CONFIG["bindir"],
RbConfig::CONFIG["ruby_install_name"] + RbConfig::CONFIG["EXEEXT"]
)
end
end