def generate(BuildDir, source, SWIGFLAGS): mem.add_dep(mem.util.convert_to_file(source)) mem.add_deps([mem.nodes.File(f) for f in make_depends(source, SWIGFLAGS)]) # since we have no way to know all the files that swig will generate, # we have it generate into a temp directory, then we can see what # exact files were produced, and move them to their proper location. mem.util.ensure_file_dir(BuildDir) tmpdir = tempfile.mkdtemp(dir=BuildDir) if "-c++" in SWIGFLAGS: wrap_ext = ".cpp" else: wrap_ext = ".c" wrap = os.path.join(BuildDir, os.path.splitext(source)[0] + "_wrap" + wrap_ext) args = mem.util.convert_cmd(['swig', '-o', wrap, '-outdir', tmpdir] + SWIGFLAGS + [source]) if mem.util.run("SWIG", source, args) != 0: mem.fail() files = os.listdir(tmpdir) for file in files: shutil.move(os.path.join(tmpdir, file), os.path.join(BuildDir, file)) os.rmdir(tmpdir) return [mem.nodes.File(os.path.join(BuildDir, file)) for file in files] + \ [mem.nodes.File(wrap)]
def t_cpp_obj(target, source_list, CXXFLAGS, CPPPATH): inc_dirs = set() if len(source_list) > 1: combine_opt=['-combine'] else: combine_opt=[] for source in source_list: inc_dirs.add("-I" + os.path.dirname(source)) if not os.path.exists(str(source)): Mem.instance().fail("%s does not exist" % source) mem.add_dep(util.convert_to_file(source)) mem.add_deps([nodes.File(f) for f in make_depends(target, source_list, CFLAGS=CXXFLAGS, CPPPATH=CPPPATH, inc_dirs = list(inc_dirs))]) includes = ["-I" + path for path in CPPPATH] args = util.convert_cmd(["g++"] + CXXFLAGS + includes + target_inc_flag(target, source_list) + list(inc_dirs) + combine_opt + ["-c", "-o", target] + source_list) util.ensure_file_dir(target) if util.run("Compiling", source_list, args) != 0: Mem.instance().fail() return nodes.File(target)
def _build_python_obj(target, source, CC, CFLAGS, CPPPATH): includes = ["-I" + path for path in CPPPATH] if os.path.dirname(source) != '': includes.append("-I" + os.path.dirname(source)) includes.append("-I" + get_config_var("CONFINCLUDEPY")) # Check for header dependencies mem = Mem.instance() mem.add_deps([nodes.File(f) for f in gcc.make_depends(target, [source], CC=CC, CFLAGS=CFLAGS, CPPPATH=CPPPATH, inc_dirs=includes ) ]) cargs = get_config_var('BLDSHARED').split(' ') args = util.convert_cmd([cargs[0]] + cargs[1:] + CFLAGS + includes + gcc.target_inc_flag(target, [ source ]) + list(includes) + ["-c", "-o", target] + [ source ]) util.ensure_file_dir(target) if util.run("GCC (Python Extension)", source, args) != 0: Mem.instance().fail() return [ nodes.File(target) ]
def _link_python_ext(target, objs, CFLAGS, LINKFLAGS): mem = Mem.instance() mem.add_deps(objs) cargs = get_config_var('BLDSHARED').split() + get_config_var('BLDLIBRARY').split() args = util.convert_cmd(cargs[:1] + ["-o", target] + cargs[1:] + CFLAGS + objs + LINKFLAGS) (returncode, stdoutdata, stderrdata) = util.run_return_output("GCC Link (Python Extension)", objs, util._open_pipe_, args) if returncode != 0: Mem.instance().fail() return nodes.File(target)
def t_prog(target, objs, CFLAGS, LIBS, LIBPATH, LINKFLAGS): mem.add_deps(objs) npaths = map(lambda a: "-L" + str(a), LIBPATH) nlibs = map(lambda a: "-l" + str(a), LIBS) args = util.convert_cmd(["gcc", "-o", target] + CFLAGS + LINKFLAGS + npaths + objs + nlibs) util.ensure_file_dir(target) if util.run("Linking", target, args) != 0: Mem.instance().fail() return nodes.File(target)
def _compile(sources, JAVA_PACKAGE, JAVA_BUILD_DIR, JAVA_FLAGS): mem.add_deps([nodes.File(f) for f in sources]) args = (["javac", "-d", JAVA_BUILD_DIR, "-cp", JAVA_BUILD_DIR] + JAVA_FLAGS + sources) print " ".join(args) if subprocess.call(args) != 0: mem.fail() def src_path_to_dest_file(p): return os.path.splitext(os.path.basename(p))[0] + ".class" return [File(os.path.join(JAVA_BUILD_DIR, *(JAVA_PACKAGE.split(".") + [src_path_to_dest_file(source)]))) for source in sources]
def t_prog(target, objs, CC, CFLAGS, LIBS, LIBPATH, LINKFLAGS): mem.add_deps(objs) npaths = map(lambda a: "-L" + str(a), LIBPATH) nlibs = [] for l in LIBS: if type(l) is tuple: assert l[1] == 'static' nlibs.extend(["-Wl,-Bstatic", "-l" + l[0], "-Wl,-Bdynamic"]) else: nlibs.append("-l" + l) args = util.convert_cmd([CC, "-o", target] + CFLAGS + LINKFLAGS + npaths + objs + nlibs) util.ensure_file_dir(target) if util.run("Linking", target, args) != 0: Mem.instance().fail() return nodes.File(target)
def build(self, cfile, source): self.deps = set((source,)) # We might also depend on our definition file # if it exists pxd = os.path.splitext(source)[0] + '.pxd' if os.path.exists(pxd): self.deps.add(pxd) self._find_deps(open(pxd, "r").read()) self._find_deps(open(source,"r").read()) self.deps = [ d for d in self.deps if os.path.exists(d) ] mem = Mem.instance() mem.add_deps([ nodes.File(f) for f in self.deps ]) args = util.convert_cmd(["cython"] + ['-I' + path for path in self.include_paths ] + ["-o", cfile, source]) if util.run("Cython", source, args) != 0: Mem.instance().fail() return nodes.File(cfile)