ruby-changes:45328
From: nobu <ko1@a...>
Date: Mon, 23 Jan 2017 11:50:30 +0900 (JST)
Subject: [ruby-changes:45328] nobu:r57401 (trunk): Parallel ext configuration
nobu 2017-01-23 11:50:23 +0900 (Mon, 23 Jan 2017) New Revision: 57401 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57401 Log: Parallel ext configuration * ext/configure-ext.mk: configure each directories underneath ext in parallel. * template/exts.mk.tmpl: then collect the results. Added files: trunk/template/configure-ext.mk.tmpl trunk/template/exts.mk.tmpl Modified directories: trunk/ext/ Modified files: trunk/.gitignore trunk/Makefile.in trunk/common.mk trunk/ext/extmk.rb trunk/win32/Makefile.sub Index: common.mk =================================================================== --- common.mk (revision 57400) +++ common.mk (revision 57401) @@ -210,9 +210,19 @@ showconfig: https://github.com/ruby/ruby/blob/trunk/common.mk#L210 exts: build-ext EXTS_MK = exts.mk -$(EXTS_MK): $(MKFILES) all-incs $(PREP) $(RBCONFIG) $(LIBRUBY) $(TIMESTAMPDIR)/.$(arch).time +$(EXTS_MK): ext/configure-ext.mk $(TIMESTAMPDIR)/.$(arch).time $(srcdir)/template/exts.mk.tmpl + $(MAKE) -f ext/configure-ext.mk V=$(V) MINIRUBY='$(MINIRUBY)' \ + SCRIPT_ARGS='$(SCRIPT_ARGS)' EXTSTATIC=$(EXTSTATIC) \ + gnumake=$(gnumake) EXTLDFLAGS="$(EXTLDFLAGS)" srcdir="$(srcdir)" $(ECHO) generating makefile $@ - $(Q)$(MINIRUBY) $(srcdir)/ext/extmk.rb --make="$(MAKE)" --command-output=$(EXTS_MK) $(EXTMK_ARGS) configure + $(Q)$(MINIRUBY) $(srcdir)/tool/generic_erb.rb -o $@ -c \ + $(srcdir)/template/exts.mk.tmpl + +ext/configure-ext.mk: $(PREP) all-incs $(MKFILES) $(RBCONFIG) $(LIBRUBY) + $(ECHO) generating makefiles $@ + $(Q)$(MAKEDIRS) ext + $(Q)$(MINIRUBY) $(srcdir)/tool/generic_erb.rb -o $@ -c \ + $(srcdir)/template/$(@F).tmpl --srcdir="$(srcdir)" configure-ext: $(EXTS_MK) Index: win32/Makefile.sub =================================================================== --- win32/Makefile.sub (revision 57400) +++ win32/Makefile.sub (revision 57401) @@ -1072,7 +1072,9 @@ clean-ext distclean-ext realclean-ext:: https://github.com/ruby/ruby/blob/trunk/win32/Makefile.sub#L1072 ) ) distclean-ext realclean-ext:: - -$(Q)$(RM) ext/extinit.c + -$(Q)$(RM) ext/extinit.c ext/configure-ext.mk + @cd ext && for /D $(EXTS) %I in (.) \ + do @if exist %I\exts.mk del %I\exts.mk -$(Q)rmdir ext 2> nul || @ clean-extout: Index: .gitignore =================================================================== --- .gitignore (revision 57400) +++ .gitignore (revision 57401) @@ -137,6 +137,8 @@ y.tab.c https://github.com/ruby/ruby/blob/trunk/.gitignore#L137 # /ext/ /ext/extinit.c +/ext/configure-ext.mk +/ext/*/exts.mk # /ext/-test-/win32/dln/ /ext/-test-/win32/dln/dlntest.exp Index: template/configure-ext.mk.tmpl =================================================================== --- template/configure-ext.mk.tmpl (revision 0) +++ template/configure-ext.mk.tmpl (revision 57401) @@ -0,0 +1,27 @@ https://github.com/ruby/ruby/blob/trunk/template/configure-ext.mk.tmpl#L1 +V = 0 +Q1 = $(V:1=) +Q = $(Q1:0=@) +ECHO1 = $(V:1=@:) +ECHO = $(ECHO1:0=@echo) + +<% +srcdir = miniruby = nil +opt = OptionParser.new do |o| + o.on('--srcdir=SRCDIR') {|v| srcdir = v} + o.on('--miniruby=MINIRUBY') {|v| miniruby = v} + o.order!(ARGV) +end +srcdir ||= File.dirname(File.dirname(__FILE__)) +exts = Dir.glob("#{srcdir}/ext/*/").map(&File.method(:basename)) +%> +all: +% exts.each do |dir| +all: ext/<%=dir%>/exts.mk +ext/<%=dir%>/exts.mk: FORCE + $(Q)$(MINIRUBY) $(srcdir)/ext/extmk.rb --make="$(MAKE)" --command-output=ext/<%=dir%>/exts.mk \ + $(SCRIPT_ARGS) --extension=<%=dir%> --extstatic $(EXTSTATIC) \ + --gnumake=$(gnumake) --extflags="$(EXTLDFLAGS)" \ + -- subconfigure +% end + +.PHONY: FORCE Property changes on: template/configure-ext.mk.tmpl ___________________________________________________________________ Added: svn:eol-style + LF Index: template/exts.mk.tmpl =================================================================== --- template/exts.mk.tmpl (revision 0) +++ template/exts.mk.tmpl (revision 57401) @@ -0,0 +1,98 @@ https://github.com/ruby/ruby/blob/trunk/template/exts.mk.tmpl#L1 +# -*- makefile -*- +V = 0 +Q1 = $(V:1=) +Q = $(Q1:0=@) +ECHO1 = $(V:1=@:) +ECHO = $(ECHO1:0=@echo) +<% +require './rbconfig' +macros = {} +deps = [] +note = [] +Dir.glob("ext/*/exts.mk") do |e| + s = File.read(e) + s.scan(/^(extensions|EXT[A-Z]+)[ \t]*=[ \t]*((?>(?>[^\\\n]|\\.)*\\\n)*(?>[^\\\n]|\\.)*)$/) do |n, v| + v.gsub!(/\\\n[ \t]*/, ' ') + next if v.empty? + v = v.split + m = macros[n] ||= [] + case n + when "LIBS" + m.concat(v) + else + macros[n] = m | v + end + end + s.scan(%r"^(ext/\S+)/[^/\s:]+:[ \t]*\1/static$|^(?:ruby|install(?:-(?:so|rb))?|static|(?:dist|real)?clean):.+$") do + deps << $& + end + s.scan(%r"^note:\n((?:\t.+\n)+)") do |(n)| + note |= n.split(/^/) + end +end +deps.uniq! +if objs = macros["EXTOBJS"] and objs.any? {|e|e.start_with?("ext/extinit.")} + objs.delete_if {|e|e.start_with?("dmyext.")} +end +macros.default = [].freeze +class Array + def fold(h, w = 70) + return "" if empty? + w -= h + ret = [s = String.new] + each do |e| + if s.size + e.size + 1 > w + ret << (s = String.new) + end + s << " " << e + end + ret.join(" \\\n" + "\t" * (h / 8) + " " * (h % 8)) + end +end +@erbout = _erbout +def self.column + w = 0 + @erbout[/^.*\z/].scan(/\t|([^\t]+)/) {|s,| w += (s ? s.size : 8 - w % 8)} + w +end +targets = %w[all static install install-so install-rb clean distclean realclean] +objext = RbConfig::CONFIG["OBJEXT"] +%> + +extensions =<%= macros["extensions"].fold(column) %> +gems = +EXTOBJS =<%= macros["EXTOBJS"].fold(column) %> +EXTLIBS =<%= macros["EXTLIBS"].fold(column) %> +EXTSO =<%= macros["EXTSO"].fold(column) %> +EXTLDFLAGS =<%= macros["EXTLDFLAGS"].fold(column) %> +EXTINITS =<%= macros["EXTINITS"].fold(column) %> +SUBMAKEOPTS = DLDOBJS="$(EXTOBJS) $(EXTENCS)" EXTOBJS= \ + EXTSOLIBS="$(EXTLIBS)" LIBRUBY_SO_UPDATE=$(LIBRUBY_EXTS) \ + EXTLDFLAGS="$(EXTLDFLAGS)" EXTINITS="$(EXTINITS)" \ + UPDATE_LIBRARIES="$(UPDATE_LIBRARIES)" SHOWFLAGS= + +all static: ruby + +clean: + -$(Q)$(RM) ext/extinit.<%= objext %> +distclean: + -$(Q)$(RM) ext/extinit.c + +<%= deps.join("\n") %> +ruby: + $(Q)$(MAKE) $(MFLAGS) $(SUBMAKEOPTS) $@ +libencs: + $(Q)$(MAKE) -f enc.mk V=$(V) $@ +ext/extinit.<%=objext%>: + $(Q)$(MAKE) $(MFLAGS) V=$(V) EXTINITS="$(EXTINITS)" $@ + +% targets.product(macros["extensions"].map {|e|e.chomp("/.")}) do |t, e| +<%=e%>/<%=t%>: + $(Q)$(MAKE) -C $(@D) $(MFLAGS) V=$(V) $(@F) +% end + +extso: + @echo EXTSO=$(EXTSO) + +note: +<%= note.join("") %> Property changes on: template/exts.mk.tmpl ___________________________________________________________________ Added: svn:eol-style + LF Index: Makefile.in =================================================================== --- Makefile.in (revision 57400) +++ Makefile.in (revision 57401) @@ -432,7 +432,7 @@ clean-ext distclean-ext realclean-ext:: https://github.com/ruby/ruby/blob/trunk/Makefile.in#L432 -$(Q)$(RM) ext/extinit.$(OBJEXT) distclean-ext realclean-ext:: - -$(Q)$(RM) ext/extinit.c + -$(Q)$(RM) ext/extinit.c ext/configure-ext.mk ext/*/exts.mk -$(Q)$(RMDIR) ext 2> /dev/null || true clean-extout: Index: ext/extmk.rb =================================================================== --- ext/extmk.rb (revision 57400) +++ ext/extmk.rb (revision 57401) @@ -421,7 +421,8 @@ if target = ARGV.shift and /^[a-z-]+$/ = https://github.com/ruby/ruby/blob/trunk/ext/extmk.rb#L421 "INSTALL_DATA=install -c -p -m 0644", "MAKEDIRS=mkdir -p") if $dryrun when /configure/ - $configure_only = true + target = target.sub(/^sub/, '') + $configure_only = $& || true end end unless $message @@ -674,7 +675,7 @@ unless $extlist.empty? https://github.com/ruby/ruby/blob/trunk/ext/extmk.rb#L675 ].map {|n, v| "#{n}=#{v}" if v &&= v[/\S(?:.*\S)?/] }.compact - puts(*conf) + puts(*conf) unless $configure_only == 'sub' $stdout.flush $mflags.concat(conf) $makeflags.concat(conf) @@ -701,6 +702,7 @@ ENV.delete("RUBYOPT") https://github.com/ruby/ruby/blob/trunk/ext/extmk.rb#L702 if $configure_only and $command_output exts.map! {|d| "ext/#{d}/."} gems.map! {|d| "gems/#{d}/."} + FileUtils.makedirs(File.dirname($command_output)) atomic_write_open($command_output) do |mf| mf.puts "V = 0" mf.puts "Q1 = $(V:1=)" @@ -760,7 +762,7 @@ if $configure_only and $command_output https://github.com/ruby/ruby/blob/trunk/ext/extmk.rb#L762 mf.puts mf.puts "#{rubies.join(' ')}: $(extensions:/.=/#{$force_static ? 'static' : 'all'}) $(gems:/.=/all)" submake = "$(Q)$(MAKE) $(MFLAGS) $(SUBMAKEOPTS)" - mf.puts "all static: #{rubies.join(' ')}\n" + mf.puts "all static: #{rubies.join(' ')}\n" unless $configure_only == 'sub' $extobjs.each do |tgt| mf.puts "#{tgt}: #{File.dirname(tgt)}/static" end Property changes on: ext ___________________________________________________________________ Modified: svn:ignore - *.log extinit.c tmpdir + *.log extinit.c tmpdir configure-ext.mk */exts.mk -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/