def dump(self, output_file_name): with open(output_file_name, 'w') as f: print( '# This config file was generated by `blade dump --config --to-file=<FILENAME>`\n', file=f) for name, value in sorted(iteritems(self.configs)): self._dump_section(name, value, f)
def get_canonical_architecture(arch): """Get the canonical architecture from the specified arch.""" canonical_arch = None for k, v in iteritems(BuildArchitecture._build_architecture): if arch == k or arch in v['alias']: canonical_arch = k break return canonical_arch
def _detect_maven_conflicted_deps(self, scope, dep_jars): """ Maven dependencies might have conflict: same group and artifact but different version. Select higher version by default unless a specific version of maven dependency is specified as a direct dependency of the target """ # pylint: disable=too-many-locals maven_jar_versions = {} # (group, artifact) -> versions maven_jars = {} # (group, artifact, version) -> jars maven_repo = '.m2/repository/' for jar in set(dep_jars): if maven_repo not in jar or not os.path.exists(jar): self.debug('%s not found in local maven repository' % jar) continue parts = jar[jar.find(maven_repo) + len(maven_repo):].split('/') if len(parts) < 4: continue version, artifact, group = parts[-2], parts[-3], '.'.join( parts[:-3]) key = group, artifact if key in maven_jar_versions: if version not in maven_jar_versions[key]: maven_jar_versions[key].append(version) else: maven_jar_versions[key] = [version] key = group, artifact, version if key in maven_jars: maven_jars[key].append(jar) else: maven_jars[key] = [jar] maven_dep_ids = self._get_maven_dep_ids() jars = [] for (group, artifact), versions in iteritems(maven_jar_versions): if len(versions) == 1: picked_version = versions[0] else: picked_version = None for v in versions: maven_id = ':'.join((group, artifact, v)) if maven_id in maven_dep_ids: picked_version = v break if picked_version is None or LooseVersion( v) > LooseVersion(picked_version): picked_version = v self.debug( 'Maven dependency version conflict %s:%s:{%s} during %s. Use %s' % (group, artifact, ', '.join(versions), scope, picked_version)) jars += maven_jars[group, artifact, picked_version] return sorted(jars)
def _get_target_files(self): """ Returns ----------- All the target files built by the target itself """ self.get_build_code() # Ensure rules were generated results = set() for _, v in iteritems(self.__targets): if isinstance(v, list): results.update(v) else: results.add(v) return sorted(results)
def generate_build(self, rule, outputs, inputs=None, implicit_deps=None, order_only_deps=None, variables=None, implicit_outputs=None, clean=None): """Generate a ninja build statement with specified parameters. Args: clean:list[str], files to be removed on clean, defaults to outputs + implicit_outputs, you can pass a empty list to prevent cleaning. (For example, if you want to remove the entire outer dir instead of single files) See ninja documents for description for other args. """ outputs = var_to_list(outputs) implicit_outputs = var_to_list(implicit_outputs) outs = outputs[:] if implicit_outputs: outs.append('|') outs += implicit_outputs ins = var_to_list(inputs) if implicit_deps: ins.append('|') ins += var_to_list(implicit_deps) if order_only_deps: ins.append('||') ins += var_to_list(order_only_deps) self._write_rule('build %s: %s %s' % (' '.join(outs), rule, ' '.join(ins))) clean = (outputs + implicit_outputs) if clean is None else var_to_list(clean) if clean: self._remove_on_clean(*clean) if variables: assert isinstance(variables, dict) for name, v in iteritems(variables): assert v is not None if v: self._write_rule(' %s = %s' % (name, v)) else: self._write_rule(' %s =' % name) self._write_rule('') # An empty line to improve readability
def __init__(self, name, path, code_generation): self.name = name self.path = path assert isinstance(code_generation, dict) self.code_generation = {} for language, v in iteritems(code_generation): if language not in self.__languages: console.error( '%s: Language %s is invalid. ' 'Protoc plugins in %s are supported by blade currently.' % (name, language, ', '.join(self.__languages))) continue self.code_generation[language] = {} # Note that each plugin dep should be in the global target format # since protoc plugin is defined in the global scope deps = [] for dep in var_to_list(v['deps']): if dep.startswith('//'): dep = dep[2:] if dep not in deps: deps.append(dep) self.code_generation[language]['deps'] = deps
def _set_protoc_plugins(self, plugins): """Handle protoc plugins and corresponding dependencies.""" plugins = var_to_list(plugins) self.attr['protoc_plugins'] = plugins protoc_plugin_config = config.get_section('protoc_plugin_config') protoc_plugins = [] protoc_plugin_deps, protoc_plugin_java_deps = set(), set() for plugin in plugins: if plugin not in protoc_plugin_config: self.error('Unknown plugin %s' % plugin) continue p = protoc_plugin_config[plugin] protoc_plugins.append(p) for language, v in iteritems(p.code_generation): for key in v['deps']: if key not in self.deps: self.deps.append(key) protoc_plugin_deps.add(key) if language == 'java': protoc_plugin_java_deps.add(key) self.attr['protoc_plugin_deps'] = list(protoc_plugin_deps) self.attr['exported_deps'] += list(protoc_plugin_java_deps) self.data['protoc_plugin_objects'] = protoc_plugins