Beispiel #1
0
def gecode_version():
    global GECODE_VERSION
    if GECODE_VERSION is not None:
        return GECODE_VERSION
    from distutils.ccompiler import new_compiler
    try:
        from distutils.ccompiler import customize_compiler
    except:
        from distutils.sysconfig import customize_compiler
    import os
    cxx = new_compiler()
    customize_compiler(cxx)
    pid = os.getpid()
    file_hh = "_gecode_version_%d.hh" % pid
    file_txt = "_gecode_version_%d.txt" % pid
    f = file(file_hh,"w")
    f.write("""#include "gecode/support/config.hpp"
@@GECODE_VERSION""")
    f.close()
    cxx.preprocess(file_hh,output_file=file_txt)
    if True:
        f = open(file_txt)
        version = ""
        for line in f:
            if line.startswith("@@"):
                version = line[3:-2]
                break
        f.close()
        os.remove(file_hh)
        os.remove(file_txt)
    else:
        version = "4.4.0" 
    GECODE_VERSION = version
    return version
def gecode_version():
    global GECODE_VERSION
    if GECODE_VERSION is not None:
        return GECODE_VERSION
    from distutils.ccompiler import new_compiler
    try:
        from distutils.ccompiler import customize_compiler
    except:
        from distutils.sysconfig import customize_compiler
    import os
    cxx = new_compiler()
    customize_compiler(cxx)
    pid = os.getpid()
    file_hh = "_gecode_version_%d.hh" % pid
    file_txt = "_gecode_version_%d.txt" % pid
    f = file(file_hh, "w")
    f.write("""#include "gecode/support/config.hpp"
@@GECODE_VERSION""")
    f.close()
    cxx.preprocess(file_hh, output_file=file_txt)
    if True:
        f = open(file_txt)
        version = ""
        for line in f:
            if line.startswith("@@"):
                version = line[3:-2]
                break
        f.close()
        os.remove(file_hh)
        os.remove(file_txt)
    else:
        version = "4.4.0"
    GECODE_VERSION = version
    return version
    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 distutils.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))
    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 distutils.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))
Beispiel #5
0
 def _check_compiler(self):
     """Check that 'self.compiler' really is a CCompiler object;
     if not, make it one.
     """
     from distutils.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)
Beispiel #6
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 distutils.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 _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 distutils.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)
Beispiel #8
0
    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.assertEqual(comp.exes['archiver'], 'my_ar -arflags')
Beispiel #9
0
    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.assertEqual(comp.exes['archiver'], 'my_ar -arflags')
    def run(self):
        if not self.libraries:
            return

        # Yech -- this is cut 'n pasted from build_ext.py!
        from distutils.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)
Beispiel #11
0
    def run(self):
        if not self.libraries:
            return
        else:
            from distutils.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:
                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)
            return
Beispiel #12
0
    def run(self):
        if not self.libraries:
            return

        # Yech -- this is cut 'n pasted from build_ext.py!
        from distutils.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)
Beispiel #13
0
from distutils.ccompiler import new_compiler
try:
    from distutils.ccompiler import customize_compiler
except:
    from distutils.sysconfig import customize_compiler
import os
cxx = new_compiler()
customize_compiler(cxx)
pid = os.getpid()
file_hh = "_gecode_version_%d.hh" % pid
file_txt = "_gecode_version_%d.txt" % pid
f = open(file_hh, "w")
f.write("""#include "gecode/support/config.hpp"
@@GECODE_VERSION""")
f.close()
cxx.preprocess(file_hh, output_file=file_txt)
f = open(file_txt)
version = ""
for line in f:
    if line.startswith("@@"):
        version = line[3:-2]
        break
# for versions <4, the following is necessary
if version == "":
    version = f.readlines()[len(f.readlines()) + 1][2:-2]

print(version)
f.close()
os.remove(file_hh)
os.remove(file_txt)