summaryrefslogtreecommitdiff
path: root/tool/extlibs.rb
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2020-05-10 14:58:55 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-05-12 15:57:47 +0900
commitd1748484e8d919cbd7d13249d9e4f7af981c383e (patch)
tree06f19c11a40955c0fbdc4d838a41b8e4c39e0f25 /tool/extlibs.rb
parent1d2fc91237ac8639e762a3b36bd0ee066fb80c3e (diff)
downloadruby-d1748484e8d919cbd7d13249d9e4f7af981c383e.tar.gz
extlibs.rb: added variable references
Reduce duplicate parts such as package name and version numbers.
Diffstat (limited to 'tool/extlibs.rb')
-rwxr-xr-xtool/extlibs.rb27
1 files changed, 25 insertions, 2 deletions
diff --git a/tool/extlibs.rb b/tool/extlibs.rb
index f021a2bf01..e7184b8fe3 100755
--- a/tool/extlibs.rb
+++ b/tool/extlibs.rb
@@ -7,6 +7,20 @@ require 'digest'
require_relative 'downloader'
require_relative 'lib/colorize'
+class Vars < Hash
+ def pattern
+ /\$\((#{Regexp.union(keys)})\)/
+ end
+
+ def expand(str)
+ if empty?
+ str
+ else
+ str.gsub(pattern) {self[$1]}
+ end
+ end
+end
+
class ExtLibs
def initialize
@colorize = Colorize.new
@@ -143,16 +157,21 @@ class ExtLibs
$stdout.puts "downloading for #{list}"
$stdout.flush
end
+ vars = Vars.new
extracted = false
dest = File.dirname(list)
url = chksums = nil
IO.foreach(list) do |line|
line.sub!(/\s*#.*/, '')
+ if /^(\w+)\s*=\s*(.*)/ =~ line
+ vars[$1] = vars.expand($2)
+ next
+ end
if chksums
chksums.concat(line.split)
elsif /^\t/ =~ line
if extracted and (mode == :all or mode == :patch)
- patch, *args = line.split
+ patch, *args = line.split.map {|s| vars.expand(s)}
do_patch(dest, patch, args)
end
next
@@ -163,7 +182,11 @@ class ExtLibs
chksums.pop
next
end
- next unless url
+ unless url
+ chksums = nil
+ next
+ end
+ url = vars.expand(url)
begin
extracted = do_command(mode, dest, url, cache_dir, chksums)
rescue => e