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;}\n')
        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 distutils2.compiler.ccompiler import new_compiler, 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.assertTrue('libfoo.a' in os.listdir(build_temp))
Exemple #2
0
 def _check_compiler(self):
     """Check that 'self.compiler' really is a CCompiler object;
     if not, make it one.
     """
     # We do this late, and only on-demand, because this is an expensive
     # import.
     from distutils2.compiler.ccompiler import CCompiler, new_compiler
     if not isinstance(self.compiler, CCompiler):
         self.compiler = new_compiler(compiler=self.compiler,
                                      dry_run=self.dry_run, force=1)
         customize_compiler(self.compiler)
         if self.include_dirs:
             self.compiler.set_include_dirs(self.include_dirs)
         if self.libraries:
             self.compiler.set_libraries(self.libraries)
         if self.library_dirs:
             self.compiler.set_library_dirs(self.library_dirs)
    def test_customize_compiler(self):

        # not testing if default compiler is not unix
        if get_default_compiler() != 'unix':
            return

        os.environ['AR'] = 'my_ar'
        os.environ['ARFLAGS'] = '-arflags'

        # make sure AR gets caught
        class compiler:
            compiler_type = 'unix'

            def set_executables(self, **kw):
                self.exes = kw

        comp = compiler()
        customize_compiler(comp)
        self.assertEquals(comp.exes['archiver'], 'my_ar -arflags')
Exemple #4
0
    def run(self):
        if not self.libraries:
            return

        # Yech -- this is cut 'n pasted from build_ext.py!
        from distutils2.compiler.ccompiler import new_compiler
        self.compiler = new_compiler(compiler=self.compiler,
                                     dry_run=self.dry_run,
                                     force=self.force)
        customize_compiler(self.compiler)

        if self.include_dirs is not None:
            self.compiler.set_include_dirs(self.include_dirs)
        if self.define is not None:
            # 'define' option is a list of (name,value) tuples
            for (name,value) in self.define:
                self.compiler.define_macro(name, value)
        if self.undef is not None:
            for macro in self.undef:
                self.compiler.undefine_macro(macro)

        self.build_libraries(self.libraries)
Exemple #5
0
    def run(self):
        from distutils2.compiler.ccompiler import new_compiler

        # 'self.extensions', as supplied by setup.py, is a list of
        # Extension instances.  See the documentation for Extension (in
        # distutils.extension) for details.
        #
        # For backwards compatibility with Distutils 0.8.2 and earlier, we
        # also allow the 'extensions' list to be a list of tuples:
        #    (ext_name, build_info)
        # where build_info is a dictionary containing everything that
        # Extension instances do except the name, with a few things being
        # differently named.  We convert these 2-tuples to Extension
        # instances as needed.

        if not self.extensions:
            return

        # If we were asked to build any C/C++ libraries, make sure that the
        # directory where we put them is in the library search path for
        # linking extensions.
        if self.distribution.has_c_libraries():
            build_clib = self.get_finalized_command('build_clib')
            self.libraries.extend(build_clib.get_library_names() or [])
            self.library_dirs.append(build_clib.build_clib)

        # Setup the CCompiler object that we'll use to do all the
        # compiling and linking

        # used to prevent the usage of an existing compiler for the
        # compiler option when calling new_compiler()
        # this will be removed in 3.3 and 2.8
        if not isinstance(self._compiler, str):
            self._compiler = None

        self.compiler_obj = new_compiler(compiler=self._compiler,
                                         verbose=self.verbose,
                                         dry_run=self.dry_run,
                                         force=self.force)

        # used to keep the compiler object reachable with
        # "self.compiler". this will be removed in 3.3 and 2.8
        self._compiler = self.compiler_obj

        customize_compiler(self.compiler_obj)
        # If we are cross-compiling, init the compiler now (if we are not
        # cross-compiling, init would not hurt, but people may rely on
        # late initialization of compiler even if they shouldn't...)
        if os.name == 'nt' and self.plat_name != get_platform():
            self.compiler_obj.initialize(self.plat_name)

        # And make sure that any compile/link-related options (which might
        # come from the command-line or from the setup script) are set in
        # that CCompiler object -- that way, they automatically apply to
        # all compiling and linking done here.
        if self.include_dirs is not None:
            self.compiler_obj.set_include_dirs(self.include_dirs)
        if self.define is not None:
            # 'define' option is a list of (name,value) tuples
            for (name, value) in self.define:
                self.compiler_obj.define_macro(name, value)
        if self.undef is not None:
            for macro in self.undef:
                self.compiler_obj.undefine_macro(macro)
        if self.libraries is not None:
            self.compiler_obj.set_libraries(self.libraries)
        if self.library_dirs is not None:
            self.compiler_obj.set_library_dirs(self.library_dirs)
        if self.rpath is not None:
            self.compiler_obj.set_runtime_library_dirs(self.rpath)
        if self.link_objects is not None:
            self.compiler_obj.set_link_objects(self.link_objects)

        # Now actually compile and link everything.
        self.build_extensions()