def _using_and_products(self, env_local): sources = env_local.get('sources', []) objects = [self._compile_object(s, env_local) for s in sources] obj_files = list(chain(*[p['outputs'] for p in objects])) program_env = env_local.derive(cobble.env.make_prepending_delta( linksrcs = obj_files, )) program_path = self.package.outpath(program_env, self.name) program = cobble.product(program_env.subset(_link_keys), outputs = [ program_path ], rule = 'link_c_program', inputs = obj_files, ) symlink_path = self.package.leafpath(self.name) symlink = { 'outputs': [ symlink_path ], 'rule': 'symlink_leaf', 'order_only': [ program_path ], 'variables': { 'symlink_target': os.path.relpath(program_path, os.path.dirname(symlink_path)), }, } using = cobble.env.make_appending_delta( __implicit__ = [self.identifier], ) products = objects + [ program, symlink ] return (using, products)
def _using_and_products(self, env_local): sources = env_local.get('sources', []) if not sources: return (self._using_delta, []) objects = [self._compile_object(s, env_local) for s in sources] obj_files = list(chain(*[p['outputs'] for p in objects])) if env_local.get('c_library_archive_products', True): outs = [ self.package.outpath(env_local, 'lib' + self.name + '.a') ] out_delta = [ cobble.env.subset(_archive_keys), cobble.env.append('inputs', obj_files), ] library = [cobble.product(env_local.derive(out_delta), outputs = outs, rule = 'archive_c_library', inputs = obj_files, )] if env_local.get('whole_archive', False): link_srcs = ['-Wl,-whole-archive'] + outs + ['-Wl,-no-whole-archive'] else: link_srcs = outs else: outs = obj_files link_srcs = obj_files library = [] using = list(chain(self._using_delta, cobble.env.make_appending_delta( __implicit__ = outs, link_srcs = link_srcs, ))) products = objects + library return (using, products)
def _compile_object(self, source, env): ext = os.path.splitext(source)[1] rule, keys = self._file_type_map[ext] keys = _compile_keys | frozenset(keys) o_env = env.derive(chain(self._deps_delta(env), [ cobble.env.subset(keys) ])) return cobble.product(o_env, outputs = [ self.package.outpath(o_env, source + '.o') ], rule = rule, inputs = [ self.package.inpath(source) ], )