def grab_lib(line): needs(line, ['(', ')']) needs(line, ['//%lib']) args = between(line, '(', ')') arg_tokens = splitstrip(args) Log.debug(' lib: {}'.format(arg_tokens)) return {'lib': {'target': arg_tokens[0], 'srcs': arg_tokens[1:]}}
def grab_codegen(line): needs(line, ['(', ')']) needs(line, ['# %codegen']) args = between(line, '(', ')') arg_tokens = splitstrip(args) Log.debug(' codegen: {}'.format(arg_tokens)) return {'codegen': {'type': arg_tokens[0], 'args': arg_tokens[1:]}}
def grab_bin(line): needs(line, ['(', ')']) needs(line, ['//%bin']) args = between(line, '(', ')') arg_tokens = splitstrip(args) Log.debug(' bin: {}'.format(arg_tokens)) assert len(arg_tokens) in (0, 1), "Wrong number of arguments" return {'bin': {'target': arg_tokens[0]}}
def grab_dependencies(line): '''Parse dependencies out of a line''' needs(line, ['(', ')']) needs(line, ['//%deps']) args = between(line, '(', ')') deps = splitstrip(args) Log.debug(' deps: {}'.format(deps)) return {'deps': deps}
def resolve_include(file_path, include_path, available_include_paths=[]): # return os.path.join('/home/jacob/repos/experiments', include_path) directory, _ = os.path.split(file_path) extended_available_incl_paths = available_include_paths + [directory] for path in extended_available_incl_paths: potential_path = os.path.join(path, include_path) if os.path.exists(potential_path): return potential_path else: # raise ValueError("Unknown include: {} in {}".format(include_path, file_path)) Log.warn("Unknown include: {} in {}".format(include_path, file_path))
def grab_include(line, incl_type='"'): needs(line, ['#include']) incl_path = "" for start, end in pairs.items(): if start in line: incl_path = between(line, start, end) break if (incl_type not in ("local", "system")): raise NotImplementedError("wtf?") Log.debug(" include: {} ({})".format(incl_path, incl_type)) return {'include': {'given_path': incl_path, 'type': incl_type}}
def build_bazel_build(to_build, base_directory): actions = { 'lib': create_lib, 'binary': create_bin } from graph import dependency_sort write_order = dependency_sort(to_build) Log.success('\n\nGenerating BUILDs....') cmake_text = "" for write in write_order: if write in to_build: build_item = to_build[write] if not should_create_target(build_item): continue action = actions[build_item['kind']] new_text = action(build_item, base_directory=base_directory) cmake_text += new_text + '\n' Log.info(new_text)
def should_create_target(build_item): if 'CMakeLists.txt' in os.listdir(build_item['location']): Log.debug("Ignoring: {}".format(build_item['target'])) return False else: return True
def flagger(line): Log.debug(' flag: {}'.format(flag_name)) return {'flags': [flag_name]}