diff options
author | Nobuyoshi Nakada <[email protected]> | 2020-05-10 14:58:55 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2020-05-12 15:57:47 +0900 |
commit | d1748484e8d919cbd7d13249d9e4f7af981c383e (patch) | |
tree | 06f19c11a40955c0fbdc4d838a41b8e4c39e0f25 /tool/extlibs.rb | |
parent | 1d2fc91237ac8639e762a3b36bd0ee066fb80c3e (diff) |
extlibs.rb: added variable references
Reduce duplicate parts such as package name and version numbers.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3102
Diffstat (limited to 'tool/extlibs.rb')
-rwxr-xr-x | tool/extlibs.rb | 27 |
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 |