ruby-changes:73935
From: nagachika <ko1@a...>
Date: Sun, 9 Oct 2022 12:15:55 +0900 (JST)
Subject: [ruby-changes:73935] bda0b8c093 (ruby_3_1): sync tool/rbinstall.rb to current master.
https://git.ruby-lang.org/ruby.git/commit/?id=bda0b8c093 From bda0b8c09331111f38af98291c201595ce3a2872 Mon Sep 17 00:00:00 2001 From: nagachika <nagachika@r...> Date: Sun, 9 Oct 2022 12:15:32 +0900 Subject: sync tool/rbinstall.rb to current master. --- tool/rbinstall.rb | 209 +++++++++++++++++++++--------------------------------- version.h | 4 +- 2 files changed, 83 insertions(+), 130 deletions(-) diff --git a/tool/rbinstall.rb b/tool/rbinstall.rb index 0b1195e360..e94445114b 100755 --- a/tool/rbinstall.rb +++ b/tool/rbinstall.rb @@ -376,6 +376,11 @@ install?(:local, :arch, :bin, :'bin-arch') do https://github.com/ruby/ruby/blob/trunk/tool/rbinstall.rb#L376 if rubyw_install_name and !rubyw_install_name.empty? install rubyw_install_name+exeext, bindir, :mode => $prog_mode, :strip => $strip end + # emcc produces ruby and ruby.wasm, the first is a JavaScript file of runtime support + # to load and execute the second .wasm file. Both are required to execute ruby + if RUBY_PLATFORM =~ /emscripten/ and File.exist? ruby_install_name+".wasm" + install ruby_install_name+".wasm", bindir, :mode => $prog_mode, :strip => $strip + end if File.exist? goruby_install_name+exeext install goruby_install_name+exeext, bindir, :mode => $prog_mode, :strip => $strip end @@ -681,7 +686,13 @@ install?(:dbg, :nodefault) do https://github.com/ruby/ruby/blob/trunk/tool/rbinstall.rb#L686 RbConfig.expand(File.read(src), conf) } end - install File.join(srcdir, "misc/lldb_cruby.py"), File.join(rubylibdir, "lldb_cruby.py") + Dir.glob(File.join(srcdir, "misc/lldb_*")) do |src| + if File.directory?(src) + install_recursive src, File.join(rubylibdir, File.basename(src)) + else + install src, rubylibdir + end + end install File.join(srcdir, ".gdbinit"), File.join(rubylibdir, "gdbinit") if $debug_symbols { @@ -724,86 +735,60 @@ module RbInstall https://github.com/ruby/ruby/blob/trunk/tool/rbinstall.rb#L735 module Specs class FileCollector - def initialize(gemspec) + def self.for(srcdir, type, gemspec) + relative_base = (File.dirname(gemspec) if gemspec.include?("/")) + const_get(type.capitalize).new(gemspec, srcdir, relative_base) + end + + attr_reader :gemspec, :srcdir, :relative_base + def initialize(gemspec, srcdir, relative_base) @gemspec = gemspec - @base_dir = File.dirname(gemspec) + @srcdir = srcdir + @relative_base = relative_base end def collect - (ruby_libraries + built_libraries).sort + ruby_libraries.sort end - def skip_install?(files) - case type - when "ext" + class Ext < self + def skip_install?(files) # install ext only when it's configured !File.exist?("#{$ext_build_dir}/#{relative_base}/Makefile") - when "lib" - files.empty? end - end - - private - def type - /\/(ext|lib)?\/.*?\z/ =~ @base_dir - $1 - end - def ruby_libraries - case type - when "ext" - prefix = "#{$extout}/common/" - base = "#{prefix}#{relative_base}" - when "lib" - base = @base_dir - prefix = base.sub(/lib\/.*?\z/, "") - # for lib/net/net-smtp.gemspec - if m = File.basename(@gemspec, ".gemspec").match(/.*\-(.*)\z/) - base = "#{@base_dir}/#{m[1]}" unless remove_prefix(prefix, @base_dir).include?(m[1]) - end + def ruby_libraries + Dir.glob("lib/**/*.rb", base: "#{srcdir}/ext/#{relative_base}") end + end - files = if base - Dir.glob("#{base}{.rb,/**/*.rb}").collect do |ruby_source| - remove_prefix(prefix, ruby_source) - end - else - [File.basename(@gemspec, '.gemspec') + '.rb'] - end - - case File.basename(@gemspec, ".gemspec") - when "net-http" - files << "lib/net/https.rb" - when "optparse" - files << "lib/optionparser.rb" + class Lib < self + def skip_install?(files) + files.empty? end - files - end - - def built_libraries - case type - when "ext" - prefix = "#{$extout}/#{CONFIG['arch']}/" - base = "#{prefix}#{relative_base}" - dlext = CONFIG['DLEXT'] - Dir.glob("#{base}{.#{dlext},/**/*.#{dlext}}").collect do |built_library| - remove_prefix(prefix, built_library) + def ruby_libraries + gemname = File.basename(gemspec, ".gemspec") + base = relative_base || gemname + # for lib/net/net-smtp.gemspec + if m = /.*(?=-(.*)\z)/.match(gemname) + base = File.join(base, *m.to_a.select {|n| !base.include?(n)}) + end + files = Dir.glob("lib/#{base}{.rb,/**/*.rb}", base: srcdir) + if !relative_base and files.empty? # no files at the toplevel + # pseudo gem like ruby2_keywords + files << "lib/#{gemname}.rb" end - when "lib" - [] - else - [] - end - end - def relative_base - /\/#{Regexp.escape(type)}\/(.*?)\z/ =~ @base_dir - $1 - end + case gemname + when "net-http" + files << "lib/net/https.rb" + when "optparse" + files << "lib/optionparser.rb" + end - def remove_prefix(prefix, string) - string.sub(/\A#{Regexp.escape(prefix)}/, "") + files + end end end end @@ -899,6 +884,10 @@ module RbInstall https://github.com/ruby/ruby/blob/trunk/tool/rbinstall.rb#L884 RbInstall.no_write(options) {super} end + # Now build-ext builds all extensions including bundled gems. + def build_extensions + end + def generate_bin_script(filename, bindir) name = formatted_program_filename(filename) unless $dryrun @@ -930,13 +919,12 @@ install?(:ext, :arch, :gem, :'default-gems', :'default-gems-arch') do https://github.com/ruby/ruby/blob/trunk/tool/rbinstall.rb#L919 install_default_gem('ext', srcdir, bindir) end -def load_gemspec(file, expanded = false) +def load_gemspec(file, base = nil) file = File.realpath(file) code = File.read(file, encoding: "utf-8:-") code.gsub!(/(?:`git[^\`]*`|%x\[git[^\]]*\])\.split\([^\)]*\)/m) do files = [] - if expanded - base = File.dirname(file) + if base Dir.glob("**/*", File::FNM_DOTMATCH, base: base) do |n| case File.basename(n); when ".", ".."; next; end next if File.directory?(File.join(base, n)) @@ -949,8 +937,9 @@ def load_gemspec(file, expanded = false) https://github.com/ruby/ruby/blob/trunk/tool/rbinstall.rb#L937 unless Gem::Specification === spec raise TypeError, "[#{file}] isn't a Gem::Specification (#{spec.class} instead)." end - spec.loaded_from = file + spec.loaded_from = base ? File.join(base, File.basename(file)) : file spec.files.reject! {|n| n.end_with?(".gemspec") or n.start_with?(".git")} + spec.date = RUBY_RELEASE_DATE spec end @@ -976,9 +965,10 @@ def install_default_gem(dir, srcdir, bindir) https://github.com/ruby/ruby/blob/trunk/tool/rbinstall.rb#L965 } default_spec_dir = Gem.default_specifications_dir - gems = Dir.glob("#{srcdir}/#{dir}/**/*.gemspec").map {|src| - spec = load_gemspec(src) - file_collector = RbInstall::Specs::FileCollector.new(src) + base = "#{srcdir}/#{dir}" + gems = Dir.glob("**/*.gemspec", base: base).map {|src| + spec = load_gemspec("#{base}/#{src}") + file_collector = RbInstall::Specs::FileCollector.for(srcdir, dir, src) files = file_collector.collect if file_collector.skip_install?(files) next @@ -1004,20 +994,6 @@ def install_default_gem(dir, srcdir, bindir) https://github.com/ruby/ruby/blob/trunk/tool/rbinstall.rb#L994 end install?(:ext, :comm, :gem, :'bundled-gems') do - if CONFIG['CROSS_COMPILING'] == 'yes' - # The following hacky steps set "$ruby = BASERUBY" in tool/fake.rb - $hdrdir = '' - $extmk = nil - $ruby = nil # ... - ruby_path = $ruby + " -I#{Dir.pwd}" # $baseruby + " -I#{Dir.pwd}" - else - # ruby_path = File.expand_path(with_destdir(File.join(bindir, ruby_install_name))) - ENV['RUBYLIB'] = nil - ENV['RUBYOPT'] = nil - ruby_path = File.expand_path(with_destdir(File.join(bindir, ruby_install_name))) + " --disable=gems -I#{with_destdir(archlibdir)}" - end - Gem.instance_variable_set(:@ruby, ruby_path) if Gem.ruby != ruby_path - gem_dir = Gem.default_dir install_dir = with_destdir(gem_dir) prepare "bundled gems", gem_dir @@ -1037,40 +1013,38 @@ install?(:ext, :comm, :gem, :'bundled-gems') do https://github.com/ruby/ruby/blob/trunk/tool/rbinstall.rb#L1013 :wrappers => true, :format_executable => true, } - gem_ext_dir = "#$extout/gems/#{CONFIG['arch']}" - extensions_dir = with_destdir(Gem::StubSpecification.gemspec_stub("", gem_dir, gem_dir).extensions_dir) + + extensions_dir = Gem::StubSpecification.gemspec_stub("", gem_dir, gem_dir).extensions_dir + specifications_dir = File.join(gem_dir, "specifications") + build_dir = Gem::StubSpecification.gemspec_stub("", ".bundle", ".bundle").extensions_dir + + # We are about to build extensions, and want to configure extensions with the + # newly installed ruby. + Gem.instance_variable_set(:@ruby, with_destdir(File.join(bindir, ruby_install_name))) + # Prevent fake.rb propagation. It conflicts with the natural mkmf configs of + # the newly installed ruby. + ENV.delete('RUBYOPT') File.foreach("#{srcdir}/gems/bundled_gems") do |name| next if /^\s*(?:#|$)/ =~ name next unless /^(\S+)\s+(\S+).*/ =~ name gem_name = "#$1-#$2" - path = "#{srcdir}/.bundle/gems/#{gem_name}/#{gem_name}.gemspec" - if File.exist?(path) - spec = load_gemspec(path) - else - path = "#{srcdir}/.bundle/gems/#{gem_n (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/