def build(self, sources, env=None): sources = [self.ctx.src_root.find_resource(s) for s in sources] #task_gen = TaskGen("dummy", self.ctx, sources, name) env = yaku.tools._merge_env(self.env, env) copy_tf = task_factory("convert_copy") convert_tf = task_factory("convert_do") convert_tf.before.append(copy_tf.__name__) py3k_tmp = self.ctx.bld_root.declare("_py3k") tasks = [] for source in sources: target = py3k_tmp.declare(source.srcpath()) task = copy_tf([target], [source]) task.func = copy_func task.env_vars = {} tasks.append(task) source = target target = self.ctx.bld_root.declare(source.srcpath()) task = convert_tf([target], [source]) task.func = convert_func task.env_vars = {} tasks.append(task) for t in tasks: t.env = env self.ctx.tasks.extend(tasks) return []
def convert(self, name, sources, env=None): # Basic principle: we first copy the whole tree (defined by the sources # list) into a temporary directory, which is then used for the # convertion. Notes: # - the whole tree needs to be copied before any 2to3 execution as 2to3 # depends on the tree structure (e.g. for local vs absolute imports) # - because 2to3 can only modify files in place, we need to copy things # twice to avoid re-applying 2to3 several times (2to3 is not # idem-potent). # - the exclude process is particularly ugly... env = yaku.tools._merge_env(self.env, env) flter = self._process_exclude(env) self.env["__2TO3_FILTER"] = flter files = [self.ctx.src_root.find_resource(f) for f in sources] convert_tf = task_factory("2to3") copy_tf = task_factory("2to3_prepare") convert_tf.before.append(copy_tf.__name__) py3k_tmp = self.ctx.bld_root.declare("_py3k_tmp") py3k_top = self.ctx.bld_root.declare("py3k") tasks = [] for f in files: target = py3k_tmp.declare(f.srcpath()) task = copy_tf(inputs=[f], outputs=[target]) task.func = copy_func task.env_vars = {} task.env = env tasks.append(task) if f.name.endswith(".py") and not flter(f): source = target target = py3k_top.declare(source.path_from(py3k_tmp)) task = convert_tf(inputs=[source], outputs=[target]) task.func = convert_func task.env_vars = {} task.env = env tasks.append(task) else: source = f target = py3k_top.declare(source.srcpath()) task = copy_tf(inputs=[source], outputs=[target]) task.func = copy_func task.env_vars = {} task.env = env tasks.append(task) self.ctx.tasks.extend(tasks) outputs = [] for t in tasks: outputs.extend(t.outputs) return outputs
def template_task(task_gen, node): out = node.change_ext("") target = node.parent.declare(out.name) task = task_factory("subst")(inputs=[node], outputs=[target], func=render) task.env_vars = ["SUBST_DICT"] task.env = task_gen.env return [task]
def shared_ccompile_task(self, node): base = self.env["CC_OBJECT_FMT"] % node.name target = node.parent.declare(base) ensure_dir(target.abspath()) task = task_factory("shcc")(inputs=[node], outputs=[target], func=shccompile, env=self.env) task.gen = self task.env_vars = cc_vars return [task]
def pycxx_task(self, node): base = self.env["CXX_OBJECT_FMT"] % node.name target = node.parent.declare(base) ensure_dir(target.abspath()) task = task_factory("pycxx")(inputs=[node], outputs=[target]) task.gen = self task.env_vars = pycxx_vars task.env = self.env task.func = pycxx return [task]
def static_link_task(self, name): objects = [tsk.outputs[0] for tsk in self.object_tasks] folder, base = os.path.split(name) tmp = folder + os.path.sep + self.env["STATICLIB_FMT"] % base target = self.bld.path.declare(tmp) ensure_dir(target.abspath()) task = task_factory("cc_stlink")(inputs=objects, outputs=[target], func=clink, env=self.env) task.gen = self task.env_vars = clink_vars return [task]
def fcompile_task(self, node): base = self.env["F77_OBJECT_FMT"] % node.name target = node.parent.declare(base) ensure_dir(target.abspath()) task = task_factory("f77")(inputs=[node], outputs=[target]) task.gen = self task.env_vars = f77_vars task.env = self.env task.func = f77_compile self.object_tasks.append(task) return [task]
def ccprogram_task(self, name): objects = [tsk.outputs[0] for tsk in self.object_tasks] def declare_target(): folder, base = os.path.split(name) tmp = folder + os.path.sep + self.env["PROGRAM_FMT"] % base return self.bld.path.declare(tmp) target = declare_target() ensure_dir(target.abspath()) task = task_factory("cc_program")(inputs=objects, outputs=[target], func=ccprogram, env=self.env) task.gen = self task.env_vars = ccprogram_vars return [task]
def shlink_task(self, name): objects = [tsk.outputs[0] for tsk in self.object_tasks] folder, base = os.path.split(name) tmp = folder + os.path.sep + self.env["SHAREDLIB_FMT"] % base target = self.bld.bld_root.declare(tmp) ensure_dir(target.abspath()) task = task_factory("cc_shlink")(inputs=objects, outputs=[target]) task.gen = self task.env = self.env task.func = cshlink task.env_vars = cshlink_vars return [task]
def ccompile_task(self, node): base = self.env["CC_OBJECT_FMT"] % node.name target = node.parent.declare(base) ensure_dir(target.abspath()) task = task_factory("cc")(inputs=[node], outputs=[target]) task.gen = self task.env_vars = cc_vars #print find_deps("foo.c", ["."]) #task.scan = lambda : find_deps(node, ["."]) #task.deps.extend(task.scan()) task.env = self.env task.func = ccompile return [task]
def cxxcompile_task(self, node): base = self.env["CXX_OBJECT_FMT"] % node.name target = node.parent.declare(base) ensure_dir(target.abspath()) task = task_factory("cxx")(inputs=[node], outputs=[target]) task.gen = self task.env_vars = cxx_vars #print find_deps("foo.c", ["."]) #task.scan = lambda : find_deps(node, ["."]) #task.deps.extend(task.scan()) task.env = self.env task.func = cxxcompile return [task]
def swig_hook(self, name): # FIXME: only handle C extension (no C++) base = os.path.splitext(name)[0] target = os.path.join(self.env["BLDDIR"], base) targets = [target + "_wrap.c", target + ".py"] for t in targets: ensure_dir(t) task = task_factory("swig")(inputs=name, outputs=targets) task.func = swig_func task.env_vars = swig_vars task.env = self.env compile_task = get_extension_hook(".c") ctask = compile_task(self, targets[0]) return [task] + ctask
def cython_task(self, node): out = node.change_ext(".c") target = node.parent.declare(out.name) ensure_dir(target.name) task = task_factory("cython")(inputs=[node], outputs=[target]) task.gen = self task.env_vars = [] task.env = self.env self.env["CYTHON_INCPATH"] = ["-I%s" % p for p in self.env["CYTHON_CPPPATH"]] task.func = compile_fun("cython", "${CYTHON} ${SRC} -o ${TGT} ${CYTHON_INCPATH}", False)[0] return [task]
def cxxprogram_task(self, name): objects = [tsk.outputs[0] for tsk in self.object_tasks] def declare_target(): folder, base = os.path.split(name) tmp = folder + os.path.sep + self.env["PROGRAM_FMT"] % base return self.bld.path.declare(tmp) target = declare_target() ensure_dir(target.abspath()) task = task_factory("cxxprogram")(inputs=objects, outputs=[target]) task.gen = self task.env = self.env task.func = cxxprogram task.env_vars = cxxprogram_vars return [task]
def shlink_task(self, name): objects = [tsk.outputs[0] for tsk in self.object_tasks] folder, base = os.path.split(name) tmp = folder + os.path.sep + self.env["SHAREDLIB_FMT"] % base target = self.bld.path.declare(tmp) ensure_dir(target.abspath()) task = task_factory("cc_shlink")(inputs=objects, outputs=[target], func=cshlink, env=self.env) task.gen = self task.env_vars = cshlink_vars return [task]
def cython_task(self, node): out = node.change_ext(".c") target = node.parent.declare(out.name) ensure_dir(target.name) task = task_factory("cython")(inputs=[node], outputs=[target]) task.gen = self task.env_vars = [] task.env = self.env self.env["CYTHON_INCPATH"] = [ "-I%s" % p for p in self.env["CYTHON_CPPPATH"] ] task.func = compile_fun("cython", "${CYTHON} ${SRC} -o ${TGT} ${CYTHON_INCPATH}", False)[0] return [task]
def pylink_task(self, name): objects = [tsk.outputs[0] for tsk in self.object_tasks] if len(objects) < 1: warnings.warn("task %s has no inputs !" % name) def declare_target(): folder, base = os.path.split(name) tmp = folder + os.path.sep + self.env["PYEXT_FMT"] % base return self.bld.path.declare(tmp) target = declare_target() ensure_dir(target.abspath()) task = task_factory("pylink")(inputs=objects, outputs=[target]) task.gen = self task.func = pylink task.env_vars = pylink_vars self.link_task = task return [task]