mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Move copying/linking extra files to Makefile so removed by clean
This commit is contained in:
parent
f375280d5a
commit
78d2be69b5
2 changed files with 161 additions and 33 deletions
81
ext/extmk.rb
81
ext/extmk.rb
|
@ -37,6 +37,7 @@ require 'rbconfig'
|
|||
|
||||
$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, *|
|
|||
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 {
|
|||
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 {
|
|||
"#{$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|
|
|||
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
|
||||
|
|
113
tool/ln_sr.rb
Executable file
113
tool/ln_sr.rb
Executable file
|
@ -0,0 +1,113 @@
|
|||
#!/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)
|
Loading…
Add table
Reference in a new issue