Exemplo n.º 1
0
def c_link_list(obj_files, verbose_flag=0, cplus=0):
    #  Link the given object files into a dynamically
    #  loadable extension file. Returns the pathname
    #  of the resulting file.
    out_file = replace_suffix(obj_files[0], ".so")
    linker = linkers[bool(cplus)]
    args = [linker] + linker_options + obj_files + ["-o", out_file]
    if verbose_flag or verbose:
        print(" ".join(args))
    status = os.spawnvp(os.P_WAIT, linker, args)
    if status != 0:
        raise CCompilerError("Linker returned status %s" % status)
    return out_file
Exemplo n.º 2
0
def c_link_list(obj_files, verbose_flag = 0, cplus = 0):
    #  Link the given object files into a dynamically
    #  loadable extension file. Returns the pathname
    #  of the resulting file.
    out_file = replace_suffix(obj_files[0], ".so")
    linker = linkers[bool(cplus)]
    args = [linker] + linker_options + obj_files + ["-o", out_file]
    if verbose_flag or verbose:
        print(" ".join(args))
    status = os.spawnvp(os.P_WAIT, linker, args)
    if status != 0:
        raise CCompilerError("Linker returned status %s" % status)
    return out_file
Exemplo n.º 3
0
def c_link_list(obj_files):
    #  Link the given object files into a dynamically
    #  loadable extension file. Returns the pathname
    #  of the resulting file.
    out_file = replace_suffix(obj_files[0], shared_lib_suffix)
    command = "%s -xm s -export all %s %s %s -o %s" % (
        c_linker, 
        string.join(obj_files), 
        pythoncore,
        string.join(libraries),
        out_file)
    stat = do_toolserver_command(command)
    if stat:
        raise CCompilerError("Linker returned status %s" % stat)
    return out_file
Exemplo n.º 4
0
def c_compile(c_file, verbose_flag = 0, cplus = 0, obj_suffix = ".o"):
    #  Compile the given C source file to produce
    #  an object file. Returns the pathname of the
    #  resulting file.
    c_file = os.path.join(os.getcwd(), c_file)
    o_file = replace_suffix(c_file, obj_suffix)
    include_options = []
    for dir in py_include_dirs:
        include_options.append("-I%s" % dir)
    compiler = compilers[bool(cplus)]
    args = [compiler] + compiler_options + include_options + [c_file, "-o", o_file]
    if verbose_flag or verbose:
        print(" ".join(args))
    #print compiler, args ###
    status = os.spawnvp(os.P_WAIT, compiler, args)
    if status != 0:
        raise CCompilerError("C compiler returned status %s" % status)
    return o_file
Exemplo n.º 5
0
def c_compile(c_file):
    #  Compile the given C source file to produce
    #  an object file. Returns the pathname of the
    #  resulting file.
    c_file = os.path.join(os.getcwd(), c_file)
    #print "c_compile: c_file =", repr(c_file) ###
    c_file_dir = os.path.dirname(c_file)
    o_file = replace_suffix(c_file, ".o")
    include_options = ["-i %s" % c_file_dir]
    for dir in py_include_dirs:
        include_options.append("-i %s" % dir)
    command = "%s -opt %s -nomapcr -w off -r %s %s -o %s" % (
        c_compiler, 
        c_optimizations,
        string.join(include_options),
        c_file, 
        o_file, 
        #e_file
        )
    #print "...command =", repr(command) ###
    stat = do_toolserver_command(command)
    if stat:
        raise CCompilerError("C compiler returned status %s" % stat)
    return o_file
Exemplo n.º 6
0
    def compile(self, source, options = None, full_module_name = None):
        # Compile a Pyrex implementation file in this context
        # and return a CompilationResult.
        if not options:
            options = default_options
        result = CompilationResult()
        cwd = os.getcwd()

        if full_module_name is None:
            full_module_name, _ = os.path.splitext(source)
            full_module_name = re.sub(r'[\\/]', '.', full_module_name)
            full_module_name = re.sub(r'[^\w.]', '_', full_module_name)

        source = os.path.join(cwd, source)
        
        if options.use_listing_file:
            result.listing_file = replace_suffix(source, ".lis")
            Errors.open_listing_file(result.listing_file,
                echo_to_stderr = options.errors_to_stderr)
        else:
            Errors.open_listing_file(None)
        if options.output_file:
            result.c_file = os.path.join(cwd, options.output_file)
        else:
            if options.cplus:
                c_suffix = ".cpp"
            else:
                c_suffix = ".c"
            result.c_file = replace_suffix(source, c_suffix)
        c_stat = None
        if result.c_file:
            try:
                c_stat = os.stat(result.c_file)
            except EnvironmentError:
                pass
        module_name = full_module_name # self.extract_module_name(source, options)
        initial_pos = (source, 1, 0)
        scope = self.find_module(module_name, pos = initial_pos, need_pxd = 0)
        errors_occurred = False
        try:
            tree = self.parse(source, scope.type_names, pxd = 0, full_module_name = full_module_name)
            tree.process_implementation(scope, options, result)
        except CompileError:
            errors_occurred = True
        Errors.close_listing_file()
        result.num_errors = Errors.num_errors
        if result.num_errors > 0:
            errors_occurred = True
        if errors_occurred and result.c_file:
            try:
                #os.unlink(result.c_file)
                Utils.castrate_file(result.c_file, c_stat)
            except EnvironmentError:
                pass
            result.c_file = None
        if result.c_file and not options.c_only and c_compile:
            result.object_file = c_compile(result.c_file,
                verbose_flag = options.show_version,
                cplus = options.cplus)
            if not options.obj_only and c_link:
                result.extension_file = c_link(result.object_file,
                    extra_objects = options.objects,
                    verbose_flag = options.show_version,
                    cplus = options.cplus)
        return result