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

ruby-changes:74168

From: nagachika <ko1@a...>
Date: Fri, 21 Oct 2022 15:02:31 +0900 (JST)
Subject: [ruby-changes:74168] d8c232935e (ruby_3_1): merge revision(s) 78d2be69b500e4552e0e75fdefd26606a0506009:

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

From d8c232935ea5920fd8d023db02b9443488da7252 Mon Sep 17 00:00:00 2001
From: nagachika <nagachika@r...>
Date: Fri, 21 Oct 2022 14:54:55 +0900
Subject: merge revision(s) 78d2be69b500e4552e0e75fdefd26606a0506009:

	Move copying/linking extra files to Makefile so removed by `clean`

	---
	 ext/extmk.rb  |  81 ++++++++++++++++++++++++-----------------
	 tool/ln_sr.rb | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	 2 files changed, 161 insertions(+), 33 deletions(-)
	 create mode 100755 tool/ln_sr.rb
---
 ext/extmk.rb  |  81 ++++++++++++++++++++++++-----------------
 tool/ln_sr.rb | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 version.h     |   2 +-
 3 files changed, 162 insertions(+), 34 deletions(-)
 create mode 100644 tool/ln_sr.rb

diff --git a/ext/extmk.rb b/ext/extmk.rb
index e2196ebfb5..57c874fa6f 100755
--- a/ext/extmk.rb
+++ b/ext/extmk.rb
@@ -37,6 +37,7 @@ require 'rbconfig' https://github.com/ruby/ruby/blob/trunk/ext/extmk.rb#L37
 
 $topdir = "."
 $top_srcdir = srcdir
+inplace = File.identical?($top_srcdir, $topdir)
 
 $" << "mkmf.rb"
 load File.expand_path("lib/mkmf.rb", srcdir)
@@ -524,7 +525,10 @@ cond = proc {|ext, *| https://github.com/ruby/ruby/blob/trunk/ext/extmk.rb#L525
 end
 ext_prefix = ext_prefix[$top_srcdir.size+1..-2]
 
+@ext_prefix = ext_prefix
+@inplace = inplace
 extend Module.new {
+
   def timestamp_file(name, target_prefix = nil)
     if @gemname and name == '$(TARGET_SO_DIR)'
       name = "$(arch)/gems/#{@gemname}#{target_prefix}"
@@ -540,6 +544,9 @@ extend Module.new { https://github.com/ruby/ruby/blob/trunk/ext/extmk.rb#L544
     return super unless @gemname
     super(*args) do |conf|
       conf.find do |s|
+        s.sub!(%r(^(srcdir *= *)\$\(top_srcdir\)/\.bundle/gems/[^/]+(?=/))) {
+          "gem_#{$&}\n" "#{$1}$(gem_srcdir)"
+        }
         s.sub!(/^(TIMESTAMP_DIR *= *)\$\(extout\)/) {
           "TARGET_TOPDIR = $(topdir)/.bundle\n" "#{$1}$(TARGET_TOPDIR)"
         }
@@ -548,37 +555,65 @@ extend Module.new { https://github.com/ruby/ruby/blob/trunk/ext/extmk.rb#L555
           "#{$1}$(TARGET_GEM_DIR)$(target_prefix)"
         }
       end
-      conf.any? {|s| /^TARGET *= *\S/ =~ s} and conf << %{
+
+      gemlib = File.directory?("#{$top_srcdir}/#{@ext_prefix}/#{@gemname}/lib")
+      if conf.any? {|s| /^TARGET *= *\S/ =~ s}
+        conf << %{
 gem_platform = #{Gem::Platform.local}
 
 # default target
 all:
 
+gem = #{@gemname}
+
 build_complete = $(TARGET_GEM_DIR)/gem.build_complete
 install-so: build_complete
+clean-so:: clean-build_complete
+
 build_complete: $(build_complete)
 $(build_complete): $(TARGET_SO)
 	$(Q) $(TOUCH) $@
 
-clean-so::
+clean-build_complete:
 	-$(Q)$(RM) $(build_complete)
+
+install: gemspec
+clean: clean-gemspec
+
+gemspec = $(TARGET_TOPDIR)/specifications/$(gem).gemspec
+$(gemspec): $(gem_srcdir)/.bundled.$(gem).gemspec
+	$(Q) $(MAKEDIRS) $(@D)
+	$(Q) $(COPY) $(gem_srcdir)/.bundled.$(gem).gemspec $@
+
+gemspec: $(gemspec)
+
+clean-gemspec:
+	-$(Q)$(RM) $(gemspec)
+}
+
+        if gemlib
+          conf << %{
+install-rb: gemlib
+clean-rb:: clean-gemlib
+
+LN_S = #{config_string('LN_S')}
+CP_R = #{config_string('CP')} -r
+
+gemlib = $(TARGET_TOPDIR)/gems/$(gem)/lib
+gemlib:#{%{ $(gemlib)\n$(gemlib): $(gem_srcdir)/lib} if $nmake}
+	$(Q) $(RUBY) $(top_srcdir)/tool/ln_sr.rb -f $(gem_srcdir)/lib $(gemlib)
+
+clean-gemlib:
+	$(Q) $(#{@inplace ? 'NULLCMD' : 'RM_RF'}) $(gemlib)
 }
+        end
+      end
+
       conf
     end
   end
 }
 
-if @gemname
-  gemdir = File.join($top_srcdir, ext_prefix, @gemname)
-  if File.exist?(spec_file = File.join(gemdir, ".bundled.#{@gemname}.gemspec")) or
-    File.exist?(spec_file = File.join(gemdir, "#{@gemname}.gemspec"))
-    dest = "#{File.dirname(ext_prefix)}/specifications"
-    FileUtils.mkdir_p(dest)
-    File.copy_stream(spec_file, "#{dest}/#{@gemname}.gemspec")
-    puts "copied #{@gemname}.gemspec"
-  end
-end
-
 dir = Dir.pwd
 FileUtils::makedirs(ext_prefix)
 Dir::chdir(ext_prefix)
@@ -597,26 +632,6 @@ exts.each do |d| https://github.com/ruby/ruby/blob/trunk/ext/extmk.rb#L632
   end
 end
 
-if @gemname
-  src_gemlib = File.join($top_srcdir, ext_prefix, @gemname, "lib")
-  src_gemlib = relative_from(src_gemlib, ([".."]*ext_prefix.count("/")).join("/"))
-  gemlib = "#{@gemname}/lib"
-  if File.directory?(src_gemlib)
-    if File.exist?(gemlib)
-      puts "using #{gemlib}"
-    else
-      begin
-        FileUtils.mkdir_p(File.dirname(gemlib))
-        File.symlink(relative_from(src_gemlib, ".."), gemlib)
-        puts "linked #{gemlib}"
-      rescue NotImplementedError, Errno::EPERM
-        FileUtils.cp_r(src_gemlib, gemlib)
-        puts "copied #{gemlib}"
-      end
-    end
-  end
-end
-
 $top_srcdir = srcdir
 $topdir = "."
 $hdrdir = hdrdir
diff --git a/tool/ln_sr.rb b/tool/ln_sr.rb
new file mode 100644
index 0000000000..1199263e85
--- /dev/null
+++ b/tool/ln_sr.rb
@@ -0,0 +1,113 @@ https://github.com/ruby/ruby/blob/trunk/tool/ln_sr.rb#L1
+#!/usr/bin/ruby
+
+until ARGV.empty?
+  case ARGV[0]
+  when '-n'
+    noop = true
+  when '-f'
+    force = true
+  else
+    break
+  end
+  ARGV.shift
+end
+
+unless ARGV.size == 2
+  abort "usage: #{$0} src destdir"
+end
+src, dest = ARGV
+
+require 'fileutils'
+
+include FileUtils
+unless respond_to?(:ln_sr)
+  def ln_sr(src, dest, force: nil, noop: nil, verbose: nil)
+    dest = File.path(dest)
+    srcs = Array.try_convert(src) || [src]
+    link = proc do |s, target_directory = true|
+      s = File.path(s)
+      if fu_starting_path?(s)
+        srcdirs = fu_split_path((File.realdirpath(s) rescue File.expand_path(s)))
+      else
+        srcdirs = fu_clean_components(*fu_split_path(s))
+      end
+      destdirs = fu_split_path(File.realdirpath(dest))
+      destdirs.pop unless target_directory
+      base = fu_relative_components_from(fu_split_path(Dir.pwd), destdirs)
+      while srcdirs.first&. == ".." and base.last and !fu_starting_path?(base.last)
+        srcdirs.shift
+        base.pop
+      end
+      s = File.join(*base, *srcdirs)
+      d = target_directory ? File.join(dest, File.basename(s)) : dest
+      fu_output_message "ln -s#{force ? 'f' : ''} #{s} #{d}" if verbose
+      next if noop
+      remove_file d, true if force
+      File.symlink s, d
+    end
+    case srcs.size
+    when 0
+    when 1
+      link[srcs[0], File.directory?(dest)]
+    else
+      srcs.each(&link)
+    end
+  end
+
+  def fu_split_path(path)
+    path = File.path(path)
+    list = []
+    until (parent, base = File.split(path); parent == path or parent == ".")
+      list << base
+      path = parent
+    end
+    list << path
+    list.reverse!
+  end
+
+  def fu_relative_components_from(target, base) #:nodoc:
+    i = 0
+    while target[i]&.== base[i]
+      i += 1
+    end
+    Array.new(base.size-i, '..').concat(target[i..-1])
+  end
+
+  def fu_clean_components(*comp)
+    comp.shift while comp.first == "."
+    return comp if comp.empty?
+    clean = [comp.shift]
+    path = File.join(*clean, "") # ending with File::SEPARATOR
+    while c = comp.shift
+      if c == ".." and clean.last != ".." and !(fu_have_symlink? && File.symlink?(path))
+        clean.pop
+        path.chomp!(%r((?<=\A|/)[^/]+/\z), "")
+      else
+        clean << c
+        path << c << "/"
+      end
+    end
+    clean
+  end
+
+  if fu_windows?
+    def fu_starting_path?(path)
+      path&.start_with?(%r(\w:|/))
+    end
+  else
+    def fu_starting_path?(path)
+      path&.start_with?("/")
+    end
+  end
+end
+
+if File.respond_to?(:symlink)
+  begin
+    ln_sr(src, dest, verbose: true, force: force, noop: noop)
+  rescue NotImplementedError, Errno::EPERM
+  else
+    exit
+  end
+end
+
+cp_r(src, dest)
diff --git a/version.h b/version.h
index 564e086eaf..854ce51883 100644
--- a/version.h
+++ b/version.h
@@ -11,7 +11,7 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L11
 # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
 #define RUBY_VERSION_TEENY 3
 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 135
+#define RUBY_PATCHLEVEL 136
 
 #define RUBY_RELEASE_YEAR 2022
 #define RUBY_RELEASE_MONTH 10
-- 
cgit v1.2.3


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

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