]> granicus.if.org Git - python/commitdiff
Fixed #5941: added ARFLAGS for the archiver command.
authorTarek Ziadé <ziade.tarek@gmail.com>
Thu, 7 May 2009 21:20:34 +0000 (21:20 +0000)
committerTarek Ziadé <ziade.tarek@gmail.com>
Thu, 7 May 2009 21:20:34 +0000 (21:20 +0000)
Lib/distutils/sysconfig.py
Lib/distutils/tests/test_build_clib.py
Lib/distutils/tests/test_sysconfig.py
Makefile.pre.in
Misc/ACKS
Misc/NEWS
configure.in

index 56cb861a6cbcca72683dceeaa0186eab9e1f4d45..099e0586fd7b9a2f10f566c0e9076687ae5df069 100644 (file)
@@ -165,9 +165,9 @@ def customize_compiler(compiler):
     varies across Unices and is stored in Python's Makefile.
     """
     if compiler.compiler_type == "unix":
-        (cc, cxx, opt, cflags, ccshared, ldshared, so_ext, ar) = \
+        (cc, cxx, opt, cflags, ccshared, ldshared, so_ext, ar, ar_flags) = \
             get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS',
-                            'CCSHARED', 'LDSHARED', 'SO', 'AR')
+                            'CCSHARED', 'LDSHARED', 'SO', 'AR', 'ARFLAGS')
 
         if 'CC' in os.environ:
             cc = os.environ['CC']
@@ -190,6 +190,10 @@ def customize_compiler(compiler):
             ldshared = ldshared + ' ' + os.environ['CPPFLAGS']
         if 'AR' in os.environ:
             ar = os.environ['AR']
+        if 'ARFLAGS' in os.environ:
+            archiver = ar + ' ' + os.environ['ARFLAGS']
+        else:
+            archiver = ar + ' ' + ar_flags
 
         cc_cmd = cc + ' ' + cflags
         compiler.set_executables(
@@ -199,7 +203,7 @@ def customize_compiler(compiler):
             compiler_cxx=cxx,
             linker_so=ldshared,
             linker_exe=cc,
-            archiver=ar)
+            archiver=archiver)
 
         compiler.shared_lib_extension = so_ext
 
index 7374c4956afefbc4f9fdf89da06cb3dd4b7084d1..3c6643f354d78b36a3a906d573f9ae14e0e00f34 100644 (file)
@@ -1,9 +1,12 @@
 """Tests for distutils.command.build_clib."""
 import unittest
+import os
+import sys
 
 from distutils.command.build_clib import build_clib
 from distutils.errors import DistutilsSetupError
 from distutils.tests import support
+from distutils.spawn import find_executable
 
 class BuildCLibTestCase(support.TempdirManager,
                         support.LoggingSilencer,
@@ -97,6 +100,43 @@ class BuildCLibTestCase(support.TempdirManager,
         cmd.distribution.libraries = 'WONTWORK'
         self.assertRaises(DistutilsSetupError, cmd.finalize_options)
 
+    def test_run(self):
+        # can't test on windows
+        if sys.platform == 'win32':
+            return
+
+        pkg_dir, dist = self.create_dist()
+        cmd = build_clib(dist)
+
+        foo_c = os.path.join(pkg_dir, 'foo.c')
+        self.write_file(foo_c, 'int main(void) { return 1;}')
+        cmd.libraries = [('foo', {'sources': [foo_c]})]
+
+        build_temp = os.path.join(pkg_dir, 'build')
+        os.mkdir(build_temp)
+        cmd.build_temp = build_temp
+        cmd.build_clib = build_temp
+
+        # before we run the command, we want to make sure
+        # all commands are present on the system
+        # by creating a compiler and checking its executables
+        from distutils.ccompiler import new_compiler
+        from distutils.sysconfig import customize_compiler
+
+        compiler = new_compiler()
+        customize_compiler(compiler)
+        for ccmd in compiler.executables.values():
+            if ccmd is None:
+                continue
+            if find_executable(ccmd[0]) is None:
+                return # can't test
+
+        # this should work
+        cmd.run()
+
+        # let's check the result
+        self.assert_('libfoo.a' in os.listdir(build_temp))
+
 def test_suite():
     return unittest.makeSuite(BuildCLibTestCase)
 
index dd17eb347fe452b2a154d10f3c6660e9f69ba21d..040dfcb6ad1828ecc5e0439c8b04fea600ebd932 100644 (file)
@@ -49,7 +49,8 @@ class SysconfigTestCase(unittest.TestCase):
         if get_default_compiler() != 'unix':
             return
 
-        os.environ['AR'] = 'xxx'
+        os.environ['AR'] = 'my_ar'
+        os.environ['ARFLAGS'] = '-arflags'
 
         # make sure AR gets caught
         class compiler:
@@ -60,7 +61,7 @@ class SysconfigTestCase(unittest.TestCase):
 
         comp = compiler()
         sysconfig.customize_compiler(comp)
-        self.assertEquals(comp.exes['archiver'], 'xxx')
+        self.assertEquals(comp.exes['archiver'], 'my_ar -arflags')
 
 
 def test_suite():
index 5b77d911d4398d7195536227fa5ff753e6aa729d..88512164215aeab3bef2af35ff781e46265412fd 100644 (file)
@@ -67,6 +67,7 @@ LDLAST=               @LDLAST@
 SGI_ABI=       @SGI_ABI@
 CCSHARED=      @CCSHARED@
 LINKFORSHARED= @LINKFORSHARED@
+ARFLAGS=       @ARFLAGS@
 # Extra C flags added for building the interpreter object files.
 CFLAGSFORSHARED=@CFLAGSFORSHARED@
 # C flags used for building the interpreter object files
@@ -403,12 +404,12 @@ sharedmods: $(BUILDPYTHON)
 # avoid long command lines, same as LIBRARY_OBJS
 $(LIBRARY): $(LIBRARY_OBJS)
        -rm -f $@
-       $(AR) cr $@ Modules/getbuildinfo.o
-       $(AR) cr $@ $(PARSER_OBJS)
-       $(AR) cr $@ $(OBJECT_OBJS)
-       $(AR) cr $@ $(PYTHON_OBJS)
-       $(AR) cr $@ $(MODULE_OBJS) $(SIGNAL_OBJS)
-       $(AR) cr $@ $(MODOBJS)
+       $(AR) $(ARFLAGS) $@ Modules/getbuildinfo.o
+       $(AR) $(ARFLAGS) $@ $(PARSER_OBJS)
+       $(AR) $(ARFLAGS) $@ $(OBJECT_OBJS)
+       $(AR) $(ARFLAGS) $@ $(PYTHON_OBJS)
+       $(AR) $(ARFLAGS) $@ $(MODULE_OBJS) $(SIGNAL_OBJS)
+       $(AR) $(ARFLAGS) $@ $(MODOBJS)
        $(RANLIB) $@
 
 libpython$(VERSION).so: $(LIBRARY_OBJS)
index 208bce3bd2e16272a7e20f2f0831a6399a2f3915..9db9f61b8e20a3c53a6ff782339d0271b2bb9832 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -145,6 +145,7 @@ Aldo Cortesi
 David Costanzo
 Scott Cotton
 Greg Couch
+David Cournapeau
 Steve Cousins
 Alex Coventry
 Matthew Dixon Cowles
index 6e4a71423cf787525b7b52580aafa30d96189e7f..e36c4a1aaaec4253a2992ff96b5530b5563a7cc3 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -285,6 +285,11 @@ Core and Builtins
 Library
 -------
 
+- Issue #5941: Distutils build_clib command was not working anymore because
+  of an incomplete costumization of the archiver command. Added ARFLAGS in the
+  Makefile besides AR and make Distutils use it. Original patch by David
+  Cournapeau.
+
 - Issue 5955: aifc's close method did not close the file it wrapped,
   now it does.  This also means getfp method now returns the real fp.
 
index bd13ef5785e9890bf6417c5e4edb0892b34357a7..1491417ea0191942df8189f22bb4ac0f9d0c2cfa 100644 (file)
@@ -770,6 +770,13 @@ AC_PROG_RANLIB
 AC_SUBST(AR)
 AC_CHECK_PROGS(AR, ar aal, ar)
 
+# tweak ARFLAGS only if the user didn't set it on the command line
+AC_SUBST(ARFLAGS)
+if test -z "$ARFLAGS"
+then
+        ARFLAGS="rc"
+fi
+
 AC_SUBST(SVNVERSION)
 AC_CHECK_PROG(SVNVERSION, svnversion, found, not-found)
 if test $SVNVERSION = found