[前][次][番号順一覧][スレッド一覧]

ruby-changes:67191

From: Nobuyoshi <ko1@a...>
Date: Thu, 19 Aug 2021 16:57:51 +0900 (JST)
Subject: [ruby-changes:67191] 00d66f7ec2 (master): Hard-link executable files to mae runnable

https://git.ruby-lang.org/ruby.git/commit/?id=00d66f7ec2

From 00d66f7ec215406b5977fb490b06dae71a4fede6 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Thu, 19 Aug 2021 16:10:14 +0900
Subject: Hard-link executable files to mae runnable

As `$ORIGIN` on Linux is refered from the real path of the
executable file, symbolic linked executable file cannot work.
---
 tool/mkrunnable.rb | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/tool/mkrunnable.rb b/tool/mkrunnable.rb
index cb211fd..62ace28 100755
--- a/tool/mkrunnable.rb
+++ b/tool/mkrunnable.rb
@@ -53,6 +53,15 @@ end https://github.com/ruby/ruby/blob/trunk/tool/mkrunnable.rb#L53
 
 alias ln_dir_safe ln_safe
 
+case RUBY_PLATFORM
+when /linux/
+  def ln_exe(src, dest)
+    ln(src, dest, force: true)
+  end
+else
+  alias ln_exe ln_safe
+end
+
 if !File.respond_to?(:symlink) && /mingw|mswin/ =~ (CROSS_COMPILING || RUBY_PLATFORM)
   extend Mswin
 end
@@ -80,10 +89,11 @@ def relative_path_from(path, base) https://github.com/ruby/ruby/blob/trunk/tool/mkrunnable.rb#L89
   end
 end
 
-def ln_relative(src, dest)
+def ln_relative(src, dest, executable = false)
   return if File.identical?(src, dest)
   parent = File.dirname(dest)
   File.directory?(parent) or mkdir_p(parent)
+  return ln_exe(src, dest) if executable
   clean_link(relative_path_from(src, parent), dest) {|s, d| ln_safe(s, d)}
 end
 
@@ -116,9 +126,9 @@ ruby_install_name = config["ruby_install_name"] https://github.com/ruby/ruby/blob/trunk/tool/mkrunnable.rb#L126
 rubyw_install_name = config["rubyw_install_name"]
 goruby_install_name = "go" + ruby_install_name
 [ruby_install_name, rubyw_install_name, goruby_install_name].map do |ruby|
-  ruby += exeext
-  if ruby and !ruby.empty? and !File.file?(target = "#{bindir}/#{ruby}")
-    ln_relative(ruby, target)
+  if ruby and !ruby.empty?
+    ruby += exeext
+    ln_relative(ruby, "#{bindir}/#{ruby}", true)
   end
 end
 so = config["LIBRUBY_SO"]
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]