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

ruby-changes:46312

From: nobu <ko1@a...>
Date: Fri, 21 Apr 2017 12:01:17 +0900 (JST)
Subject: [ruby-changes:46312] nobu:r58426 (trunk): ext/extmk.rb: colorize notes [Feature #13302]

nobu	2017-04-21 12:01:12 +0900 (Fri, 21 Apr 2017)

  New Revision: 58426

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58426

  Log:
    ext/extmk.rb: colorize notes [Feature #13302]
    
    * common.mk (build-ext): pass variables to colorize.
    
    * ext/extmk.rb: colorize notes with tool/colorize.rb.
    
    * tool/colorize.rb: extract from tool/generic_erb.rb.

  Added files:
    trunk/tool/colorize.rb
  Modified files:
    trunk/common.mk
    trunk/ext/extmk.rb
    trunk/tool/generic_erb.rb
Index: tool/colorize.rb
===================================================================
--- tool/colorize.rb	(nonexistent)
+++ tool/colorize.rb	(revision 58426)
@@ -0,0 +1,41 @@ https://github.com/ruby/ruby/blob/trunk/tool/colorize.rb#L1
+class Colorize
+  def initialize(color = nil)
+    @colors = @reset = nil
+    if color or (color == nil && STDOUT.tty?)
+      if (/\A\e\[.*m\z/ =~ IO.popen("tput smso", "r", err: IO::NULL, &:read) rescue nil)
+        @beg = "\e["
+        @colors = (colors = ENV['TEST_COLORS']) ? Hash[colors.scan(/(\w+)=([^:\n]*)/)] : {}
+        @reset = "#{@beg}m"
+      end
+    end
+    self
+  end
+
+  DEFAULTS = {"pass"=>"32;1", "fail"=>"31;1", "skip"=>"33;1"}
+
+  def decorate(str, name)
+    if @colors and color = (@colors[name] || DEFAULTS[name])
+      "#{@beg}#{color}m#{str}#{@reset}"
+    else
+      str
+    end
+  end
+
+  def pass(str)
+    decorate(str, "pass")
+  end
+
+  def fail(str)
+    decorate(str, "fail")
+  end
+
+  def skip(str)
+    decorate(str, "skip")
+  end
+end
+
+if $0 == __FILE__
+  colorize = Colorize.new
+  col = ARGV.shift
+  ARGV.each {|str| puts colorize.decorate(str, col)}
+end

Property changes on: tool/colorize.rb
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+LF
\ No newline at end of property
Index: tool/generic_erb.rb
===================================================================
--- tool/generic_erb.rb	(revision 58425)
+++ tool/generic_erb.rb	(revision 58426)
@@ -8,6 +8,7 @@ require 'optparse' https://github.com/ruby/ruby/blob/trunk/tool/generic_erb.rb#L8
 require 'fileutils'
 $:.unshift(File.dirname(__FILE__))
 require 'vpath'
+require 'colorize'
 
 vpath = VPath.new
 timestamp = nil
@@ -25,17 +26,10 @@ opt = OptionParser.new do |o| https://github.com/ruby/ruby/blob/trunk/tool/generic_erb.rb#L26
   vpath.def_options(o)
   o.order!(ARGV)
 end
-unchanged = "unchanged"
-updated = "updated"
-if color or (color == nil && STDOUT.tty?)
-  if (/\A\e\[.*m\z/ =~ IO.popen("tput smso", "r", err: IO::NULL, &:read) rescue nil)
-    beg = "\e["
-    colors = (colors = ENV['TEST_COLORS']) ? Hash[colors.scan(/(\w+)=([^:\n]*)/)] : {}
-    reset = "#{beg}m"
-    unchanged = "#{beg}#{colors["pass"] || "32;1"}m#{unchanged}#{reset}"
-    updated = "#{beg}#{colors["fail"] || "31;1"}m#{updated}#{reset}"
-  end
-end
+color = Colorize.new(color)
+unchanged = color.pass("unchanged")
+updated = color.fail("updated")
+
 template = ARGV.shift or abort opt.to_s
 erb = ERB.new(File.read(template), nil, '%-')
 erb.filename = template
Index: common.mk
===================================================================
--- common.mk	(revision 58425)
+++ common.mk	(revision 58426)
@@ -235,7 +235,7 @@ configure-ext: $(EXTS_MK) https://github.com/ruby/ruby/blob/trunk/common.mk#L235
 build-ext: $(EXTS_MK)
 	$(Q)$(MAKE) -f $(EXTS_MK) $(mflags) libdir="$(libdir)" LIBRUBY_EXTS=$(LIBRUBY_EXTS) \
 	    EXTENCS="$(ENCOBJS)" UPDATE_LIBRARIES=no $(EXTSTATIC)
-	$(Q)$(MAKE) -f $(EXTS_MK) $(mflags) note
+	$(Q)$(MAKE) -f $(EXTS_MK) $(mflags) RUBY="$(MINIRUBY)" top_srcdir="$(srcdir)" note
 
 ext/extinit.c: $(srcdir)/template/extinit.c.tmpl
 	$(Q)$(MINIRUBY) $(srcdir)/tool/generic_erb.rb -o $@ -c \
Index: ext/extmk.rb
===================================================================
--- ext/extmk.rb	(revision 58425)
+++ ext/extmk.rb	(revision 58426)
@@ -411,12 +411,15 @@ elsif sep = config_string('BUILD_FILE_SE https://github.com/ruby/ruby/blob/trunk/ext/extmk.rb#L411
 else
   $ruby = '$(topdir)/miniruby' + EXEEXT
 end
-$ruby << " -I'$(topdir)'"
+$ruby = [$ruby]
+$ruby << "-I'$(topdir)'"
 unless CROSS_COMPILING
-  $ruby << " -I'$(top_srcdir)/lib'"
-  $ruby << " -I'$(extout)/$(arch)' -I'$(extout)/common'" if $extout
+  $ruby << "-I'$(top_srcdir)/lib'"
+  $ruby << "-I'$(extout)/$(arch)'" << "-I'$(extout)/common'" if $extout
   ENV["RUBYLIB"] = "-"
 end
+topruby = $ruby
+$ruby = topruby.join(' ')
 $mflags << "ruby=#$ruby"
 
 MTIMES = [__FILE__, 'rbconfig.rb', srcdir+'/lib/mkmf.rb'].collect {|f| File.mtime(f)}
@@ -658,6 +661,8 @@ begin https://github.com/ruby/ruby/blob/trunk/ext/extmk.rb#L661
       puts
     end
 
+    mf.macro "ruby", topruby
+    mf.macro "RUBY", ["$(ruby)"]
     mf.macro "extensions", exts
     mf.macro "EXTOBJS", $extlist.empty? ? ["dmyext.#{$OBJEXT}"] : ["ext/extinit.#{$OBJEXT}", *$extobjs]
     mf.macro "EXTLIBS", $extlibs
@@ -679,8 +684,8 @@ begin https://github.com/ruby/ruby/blob/trunk/ext/extmk.rb#L684
     submakeopts << 'UPDATE_LIBRARIES="$(UPDATE_LIBRARIES)"'
     submakeopts << 'SHOWFLAGS='
     mf.macro "SUBMAKEOPTS", submakeopts
-    mf.macro "NOTE_MESG", %w[echo]
-    mf.macro "NOTE_NAME", %w[echo]
+    mf.macro "NOTE_MESG", %w[$(RUBY) $(top_srcdir)/tool/colorize.rb skip]
+    mf.macro "NOTE_NAME", %w[$(RUBY) $(top_srcdir)/tool/colorize.rb fail]
     mf.puts
     targets = %w[all install static install-so install-rb clean distclean realclean]
     targets.each do |tgt|

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

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