summaryrefslogtreecommitdiff
path: root/tool/extlibs.rb
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2020-05-10 15:00:36 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-05-12 15:57:47 +0900
commit3150b97d3261025955561e40ec781723ddc716fb (patch)
tree038587f4efeba438c4c984c5d183984011824943 /tool/extlibs.rb
parentd1748484e8d919cbd7d13249d9e4f7af981c383e (diff)
downloadruby-3150b97d3261025955561e40ec781723ddc716fb.tar.gz
extlibs.rb: links in extracted directory
Allow to create symbolic links (if available) to share same or updated files.
Diffstat (limited to 'tool/extlibs.rb')
-rwxr-xr-xtool/extlibs.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/tool/extlibs.rb b/tool/extlibs.rb
index e7184b8fe3..e2605f5a1b 100755
--- a/tool/extlibs.rb
+++ b/tool/extlibs.rb
@@ -94,6 +94,36 @@ class ExtLibs
$?.success? or raise "failed to patch #{patch}"
end
+ def do_link(file, src, dest)
+ file = File.join(dest, file)
+ if (target = src).start_with?("/")
+ target = File.join([".."] * file.count("/"), src)
+ end
+ File.unlink(file) rescue nil
+ begin
+ File.symlink(target, file)
+ rescue
+ else
+ if $VERBOSE
+ $stdout.puts "linked #{target} to #{file}"
+ $stdout.flush
+ end
+ return
+ end
+ begin
+ src = src.sub(/\A\//, '')
+ File.copy_stream(src, file)
+ rescue
+ if $VERBOSE
+ $stdout.puts "failed to link #{src} to #{file}: #{$!.message}"
+ end
+ else
+ if $VERBOSE
+ $stdout.puts "copied #{src} to #{file}"
+ end
+ end
+ end
+
def do_command(mode, dest, url, cache_dir, chksums)
extracted = false
base = /.*(?=\.tar(?:\.\w+)?\z)/
@@ -175,6 +205,12 @@ class ExtLibs
do_patch(dest, patch, args)
end
next
+ elsif /->/ =~ line
+ if extracted and (mode == :all or mode == :patch)
+ link, file = $`.strip, $'.strip
+ do_link(vars.expand(link), vars.expand(file), dest)
+ end
+ next
else
url, *chksums = line.split(' ')
end