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

ruby-changes:27665

From: nobu <ko1@a...>
Date: Mon, 11 Mar 2013 11:54:44 +0900 (JST)
Subject: [ruby-changes:27665] nobu:r39717 (trunk): mkmf.rb: defer use of instance variable

nobu	2013-03-11 11:53:47 +0900 (Mon, 11 Mar 2013)

  New Revision: 39717

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=39717

  Log:
    mkmf.rb: defer use of instance variable
    
    * lib/mkmf.rb (MakeMakefile#dir_config, MakeMakefile#_libdir_basename):
      defer use of instance variable until needed.  [Bug #8074]

  Added files:
    trunk/test/mkmf/test_config.rb
  Modified files:
    trunk/ChangeLog
    trunk/lib/mkmf.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 39716)
+++ ChangeLog	(revision 39717)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Mar 11 11:53:35 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* lib/mkmf.rb (MakeMakefile#dir_config, MakeMakefile#_libdir_basename):
+	  defer use of instance variable until needed.  [Bug #8074]
+
 Thu Mar  7 10:42:28 2013  KOSAKI Motohiro  <kosaki.motohiro@g...>
 
 	* lib/thread.rb (Queue#clear): return self.
Index: lib/mkmf.rb
===================================================================
--- lib/mkmf.rb	(revision 39716)
+++ lib/mkmf.rb	(revision 39717)
@@ -45,6 +45,16 @@ end https://github.com/ruby/ruby/blob/trunk/lib/mkmf.rb#L45
 # correctly compile and link the C extension to ruby and a third-party
 # library.
 module MakeMakefile
+  #### defer until this module become global-state free.
+  # def self.extended(obj)
+  #   obj.init_mkmf
+  #   super
+  # end
+  #
+  # def initialize(*args, rbconfig: RbConfig, **rest)
+  #   init_mkmf(rbconfig::MAKEFILE_CONFIG, rbconfig::CONFIG)
+  #   super(*args, **rest)
+  # end
 
   ##
   # The makefile configuration using the defaults from when ruby was built.
@@ -1676,7 +1686,7 @@ SRC https://github.com/ruby/ruby/blob/trunk/lib/mkmf.rb#L1686
     idir = with_config(target + "-include", idefault)
     $arg_config.last[1] ||= "${#{target}-dir}/include"
     ldir = with_config(target + "-lib", ldefault)
-    $arg_config.last[1] ||= "${#{target}-dir}/#{@libdir_basename}"
+    $arg_config.last[1] ||= "${#{target}-dir}/#{_libdir_basename}"
 
     idirs = idir ? Array === idir ? idir.dup : idir.split(File::PATH_SEPARATOR) : []
     if defaults
@@ -1693,7 +1703,7 @@ SRC https://github.com/ruby/ruby/blob/trunk/lib/mkmf.rb#L1703
 
     ldirs = ldir ? Array === ldir ? ldir.dup : ldir.split(File::PATH_SEPARATOR) : []
     if defaults
-      ldirs.concat(defaults.collect {|d| "#{d}/#{@libdir_basename}"})
+      ldirs.concat(defaults.collect {|d| "#{d}/#{_libdir_basename}"})
       ldir = ([ldir] + ldirs).compact.join(File::PATH_SEPARATOR)
     end
     $LIBPATH = ldirs | $LIBPATH
@@ -2378,8 +2388,6 @@ site-install-rb: install-rb https://github.com/ruby/ruby/blob/trunk/lib/mkmf.rb#L2388
     $extout ||= nil
     $extout_prefix ||= nil
 
-    @libdir_basename = config["libdir"] && config["libdir"][/\A\$\(exec_prefix\)\/(.*)/, 1] or "lib"
-
     $arg_config.clear
     dir_config("opt")
   end
@@ -2404,6 +2412,12 @@ MESSAGE https://github.com/ruby/ruby/blob/trunk/lib/mkmf.rb#L2412
     end
   end
 
+  private
+
+  def _libdir_basename
+    @libdir_basename ||= config_string("libdir") {|name| name[/\A\$\(exec_prefix\)\/(.*)/, 1]} || "lib"
+  end
+
   extend self
   init_mkmf
 
Index: test/mkmf/test_config.rb
===================================================================
--- test/mkmf/test_config.rb	(revision 0)
+++ test/mkmf/test_config.rb	(revision 39717)
@@ -0,0 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/test/mkmf/test_config.rb#L1
+require 'test/unit'
+require 'mkmf'
+require_relative '../ruby/envutil'
+
+class TestMkmf
+  class TestConfig < Test::Unit::TestCase
+    def test_dir_config
+      bug8074 = '[Bug #8074]'
+      assert_separately %w[-rmkmf - -- --with-foo-dir=/test/foo], %{
+        assert_equal(%w[/test/foo/include /test/foo/lib], dir_config("foo"), #{bug8074.dump})
+      }
+    end
+  end
+end

Property changes on: test/mkmf/test_config.rb
___________________________________________________________________
Added: svn:eol-style
   + LF


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

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