ruby-changes:72568
From: Nobuyoshi <ko1@a...>
Date: Sat, 16 Jul 2022 10:20:37 +0900 (JST)
Subject: [ruby-changes:72568] 78d2be69b5 (master): Move copying/linking extra files to Makefile so removed by `clean`
https://git.ruby-lang.org/ruby.git/commit/?id=78d2be69b5 From 78d2be69b500e4552e0e75fdefd26606a0506009 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Thu, 14 Jul 2022 11:59:46 +0900 Subject: 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 diff --git a/ext/extmk.rb b/ext/extmk.rb index ce8e9b88c5..6a9f9a7a70 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) @@ -521,7 +522,10 @@ cond = proc {|ext, *| https://github.com/ruby/ruby/blob/trunk/ext/extmk.rb#L522 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}" @@ -537,6 +541,9 @@ extend Module.new { https://github.com/ruby/ruby/blob/trunk/ext/extmk.rb#L541 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)" } @@ -545,37 +552,65 @@ extend Module.new { https://github.com/ruby/ruby/blob/trunk/ext/extmk.rb#L552 "#{$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) @@ -594,26 +629,6 @@ exts.each do |d| https://github.com/ruby/ruby/blob/trunk/ext/extmk.rb#L629 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 100755 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) -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/