def execute(self, targets): gentargets_by_dependee = self.context.dependents( on_predicate=is_gentarget, from_predicate=lambda t: not is_gentarget(t) ) dependees_by_gentarget = defaultdict(set) for dependee, tgts in gentargets_by_dependee.items(): for gentarget in tgts: dependees_by_gentarget[gentarget].add(dependee) # TODO(Robert Nielsen): Add optimization to only regenerate the files that have changed # initially we could just cache the generated file names and make subsequent invocations faster # but a feature like --dry-run will likely be added to scrooge to get these file names (without # actually doing the work of generating) # AWESOME-1563 PartialCmd = namedtuple('PartialCmd', ['classpath', 'main', 'opts']) partial_cmds = defaultdict(set) gentargets = filter(is_gentarget, targets) for target in gentargets: opts = [] language = target.language opts.append(('--language', language)) if target.rpc_style == 'ostrich': opts.append(('--finagle',)) opts.append(('--ostrich',)) elif target.rpc_style == 'finagle': opts.append(('--finagle',)) if target.namespace_map: for lhs, rhs in namespace_map([target]).items(): opts.append(('--namespace-map', '%s=%s' % (lhs, rhs))) outdir = self._outdir(target) opts.append(('--dest', '%s' % outdir)) safe_mkdir(outdir) if not self._strict(target): opts.append(('--disable-strict',)) if self._verbose(target): opts.append(('--verbose',)) classpath = self._classpth(target) main = INFO_FOR_COMPILER[target.compiler]['main'] partial_cmd = PartialCmd(tuple(classpath), main, tuple(opts)) partial_cmds[partial_cmd].add(target) for partial_cmd, targets in partial_cmds.items(): classpath = partial_cmd.classpath main = partial_cmd.main opts = list(partial_cmd.opts) compiler = list(targets)[0].compiler # any target will do (they all have the same compiler) calculate_compile_sources = INFO_FOR_COMPILER[compiler]['calculate_compile_sources'] import_paths, sources = calculate_compile_sources(targets, is_gentarget) for import_path in import_paths: opts.append(('--import-path', import_path)) gen_file_map_fd, gen_file_map_path = tempfile.mkstemp() os.close(gen_file_map_fd) opts.append(('--gen-file-map', gen_file_map_path)) cmdline = JvmCommandLine(classpath=classpath, main=main, opts=opts, args=sources) returncode = cmdline.call() if 0 == returncode: outdir = value_from_seq_of_seq(opts, '--dest') gen_files_for_source = self.parse_gen_file_map(gen_file_map_path, outdir) os.remove(gen_file_map_path) if 0 != returncode: raise TaskError("java %s ... exited non-zero (%i)" % (main, returncode)) langtarget_by_gentarget = {} for target in targets: dependees = dependees_by_gentarget.get(target, []) langtarget_by_gentarget[target] = self.createtarget(target, dependees, gen_files_for_source) genmap = self.context.products.get(language) # synmap is a reverse map # such as a map of java library target generated from java thrift target synmap = self.context.products.get(language + ':rev') for gentarget, langtarget in langtarget_by_gentarget.items(): synmap.add(langtarget, get_buildroot(), [gentarget]) genmap.add(gentarget, get_buildroot(), [langtarget]) for dep in gentarget.internal_dependencies: if is_gentarget(dep): langtarget.update_dependencies([langtarget_by_gentarget[dep]])
def calc_srcs(target): _, srcs = calculate_compile_sources([target], self.is_gentarget) return srcs
def execute(self, targets): gentargets_by_dependee = self.context.dependents( on_predicate=is_gentarget, from_predicate=lambda t: not is_gentarget(t)) dependees_by_gentarget = defaultdict(set) for dependee, tgts in gentargets_by_dependee.items(): for gentarget in tgts: dependees_by_gentarget[gentarget].add(dependee) # TODO(Robert Nielsen): Add optimization to only regenerate the files that have changed # initially we could just cache the generated file names and make subsequent invocations faster # but a feature like --dry-run will likely be added to scrooge to get these file names (without # actually doing the work of generating) # AWESOME-1563 PartialCmd = namedtuple('PartialCmd', ['classpath', 'main', 'opts']) partial_cmds = defaultdict(set) gentargets = filter(is_gentarget, targets) for target in gentargets: opts = [] language = target.language opts.append(('--language', language)) if target.rpc_style == 'ostrich': opts.append(('--finagle', )) opts.append(('--ostrich', )) elif target.rpc_style == 'finagle': opts.append(('--finagle', )) if target.namespace_map: for lhs, rhs in namespace_map([target]).items(): opts.append(('--namespace-map', '%s=%s' % (lhs, rhs))) outdir = self._outdir(target) opts.append(('--dest', '%s' % outdir)) safe_mkdir(outdir) if not self._strict(target): opts.append(('--disable-strict', )) if self._verbose(target): opts.append(('--verbose', )) classpath = self._classpth(target) main = INFO_FOR_COMPILER[target.compiler]['main'] partial_cmd = PartialCmd(tuple(classpath), main, tuple(opts)) partial_cmds[partial_cmd].add(target) for partial_cmd, targets in partial_cmds.items(): classpath = partial_cmd.classpath main = partial_cmd.main opts = list(partial_cmd.opts) compiler = list( targets )[0].compiler # any target will do (they all have the same compiler) calculate_compile_sources = INFO_FOR_COMPILER[compiler][ 'calculate_compile_sources'] import_paths, sources = calculate_compile_sources( targets, is_gentarget) for import_path in import_paths: opts.append(('--import-path', import_path)) gen_file_map_fd, gen_file_map_path = tempfile.mkstemp() os.close(gen_file_map_fd) opts.append(('--gen-file-map', gen_file_map_path)) cmdline = JvmCommandLine(classpath=classpath, main=main, opts=opts, args=sources) returncode = cmdline.call() if 0 == returncode: outdir = value_from_seq_of_seq(opts, '--dest') gen_files_for_source = self.parse_gen_file_map( gen_file_map_path, outdir) os.remove(gen_file_map_path) if 0 != returncode: raise TaskError("java %s ... exited non-zero (%i)" % (main, returncode)) langtarget_by_gentarget = {} for target in targets: dependees = dependees_by_gentarget.get(target, []) langtarget_by_gentarget[target] = self.createtarget( target, dependees, gen_files_for_source) genmap = self.context.products.get(language) # synmap is a reverse map # such as a map of java library target generated from java thrift target synmap = self.context.products.get(language + ':rev') for gentarget, langtarget in langtarget_by_gentarget.items(): synmap.add(langtarget, get_buildroot(), [gentarget]) genmap.add(gentarget, get_buildroot(), [langtarget]) for dep in gentarget.internal_dependencies: if is_gentarget(dep): langtarget.update_dependencies( [langtarget_by_gentarget[dep]])