def _load_build_rules(): # pylint: disable=import-outside-toplevel,unused-import import blade.cc_targets import blade.cu_targets import blade.gen_rule_target import blade.go_targets import blade.java_targets import blade.scala_targets import blade.lex_yacc_target import blade.package_target import blade.proto_library_target import blade.py_targets import blade.resource_library_target import blade.sh_test_target import blade.swig_library_target import blade.thrift_library import blade.fbthrift_library build_rules.register_variable('build_target', build_attributes.attributes)
def load_targets(target_ids, blade_root_dir, blade): """load_targets. Parse and load targets, including those specified in command line and their direct and indirect dependencies, by loading related BUILD files. Returns a map which contains all these targets. """ _load_build_rules() # pylint: disable=too-many-locals build_rules.register_variable('build_target', build_attributes.attributes) target_database = blade.get_target_database() # targets specified in command line cited_targets = set() # cited_targets and all its dependencies related_targets = {} # source dirs mentioned in command line source_dirs = [] # to prevent duplicated loading of BUILD files processed_source_dirs = set() direct_targets = [] all_command_targets = [] # Parse command line target_ids. For those in the form of <path>:<target>, # record (<path>,<target>) in cited_targets; for the rest (with <path> # but without <target>), record <path> into paths. for target_id in target_ids: source_dir, target_name = target_id.rsplit(':', 1) if target_name != '*' and target_name != '...': cited_targets.add((source_dir, target_name)) elif target_name == '...': for root, dirs, files in os.walk(source_dir): # Note the dirs[:] = slice assignment; we are replacing the # elements in dirs (and not the list referred to by dirs) so # that os.walk() will not process deleted directories. dirs[:] = [d for d in dirs if not _is_load_excluded(root, d)] if 'BUILD' in files: source_dirs.append(root) else: source_dirs.append(source_dir) direct_targets = list(cited_targets) # Load BUILD files in paths, and add all loaded targets into # cited_targets. Together with above step, we can ensure that all # targets mentioned in the command line are now in cited_targets. for source_dir in source_dirs: _load_build_file(source_dir, processed_source_dirs, blade) for key in target_database: cited_targets.add(key) all_command_targets = list(cited_targets) # Starting from targets specified in command line, breath-first # propagate to load BUILD files containing directly and indirectly # dependent targets. All these targets form related_targets, # which is a subset of target_databased created by loading BUILD files. while cited_targets: source_dir, target_name = cited_targets.pop() target_id = (source_dir, target_name) if target_id in related_targets: continue _load_build_file(source_dir, processed_source_dirs, blade) if target_id not in target_database: console.error_exit('%s: target //%s:%s does not exist' % ( _find_depender(target_id, blade), source_dir, target_name)) related_targets[target_id] = target_database[target_id] for key in related_targets[target_id].expanded_deps: if key not in related_targets: cited_targets.add(key) # Iterating to get svn root dirs for path, name in related_targets: root_dir = path.split('/')[0].strip() if root_dir not in blade.svn_root_dirs and '#' not in root_dir: blade.svn_root_dirs.append(root_dir) return direct_targets, all_command_targets, related_targets
def load_targets(target_ids, blade_root_dir, blade): """load_targets. Parse and load targets, including those specified in command line and their direct and indirect dependencies, by loading related BUILD files. Returns a map which contains all these targets. """ _load_build_rules() # pylint: disable=too-many-locals build_rules.register_variable('build_target', build_attributes.attributes) target_database = blade.get_target_database() # targets specified in command line cited_targets = set() # cited_targets and all its dependencies related_targets = {} # source dirs mentioned in command line source_dirs = [] # to prevent duplicated loading of BUILD files processed_source_dirs = set() direct_targets = [] all_command_targets = [] # Parse command line target_ids. For those in the form of <path>:<target>, # record (<path>,<target>) in cited_targets; for the rest (with <path> # but without <target>), record <path> into paths. for target_id in target_ids: source_dir, target_name = target_id.rsplit(':', 1) if target_name != '*' and target_name != '...': cited_targets.add((source_dir, target_name)) elif target_name == '...': for root, dirs, files in os.walk(source_dir): # Note the dirs[:] = slice assignment; we are replacing the # elements in dirs (and not the list referred to by dirs) so # that os.walk() will not process deleted directories. dirs[:] = [d for d in dirs if not _is_load_excluded(d)] if 'BUILD' in files: source_dirs.append(root) else: source_dirs.append(source_dir) direct_targets = list(cited_targets) # Load BUILD files in paths, and add all loaded targets into # cited_targets. Together with above step, we can ensure that all # targets mentioned in the command line are now in cited_targets. for source_dir in source_dirs: _load_build_file(source_dir, processed_source_dirs, blade) for key in target_database: cited_targets.add(key) all_command_targets = list(cited_targets) # Starting from targets specified in command line, breath-first # propagate to load BUILD files containing directly and indirectly # dependent targets. All these targets form related_targets, # which is a subset of target_databased created by loading BUILD files. while cited_targets: source_dir, target_name = cited_targets.pop() target_id = (source_dir, target_name) if target_id in related_targets: continue _load_build_file(source_dir, processed_source_dirs, blade) if target_id not in target_database: console.error_exit('%s: target //%s:%s does not exist' % ( _find_depender(target_id, blade), source_dir, target_name)) related_targets[target_id] = target_database[target_id] for key in related_targets[target_id].expanded_deps: if key not in related_targets: cited_targets.add(key) # Iterating to get svn root dirs for path, name in related_targets: root_dir = path.split('/')[0].strip() if root_dir not in blade.svn_root_dirs and '#' not in root_dir: blade.svn_root_dirs.append(root_dir) return direct_targets, all_command_targets, related_targets