def dump_exported_symbols(args): """Print all symbols exported using include_defs in a build file.""" logging.debug("Dumping exported symbols for " + args.build_file) bf = build_file.from_path(args.build_file) repo = repository.Repository(args.repository, args.cell_roots) symbols = bf.get_exported_symbols_transitive_closure(repo) if args.json: print(json.dumps(symbols)) else: print(os.linesep.join(symbols))
def dump_exported_symbols(args): """Print all symbols exported using include_defs in a build file.""" logging.debug("Dumping exported symbols for " + args.build_file) bf = build_file.from_path(args.build_file) repo = repository.Repository(args.repository, args.cell_roots) symbols = bf.get_exported_symbols_transitive_closure(repo) if args.json: print(json.dumps(symbols)) else: print(os.linesep.join(symbols))
def dump_export_map(args): """ Prints export map that includes all included definitions and symbols they export. """ logging.debug("Dumping export map for " + args.build_file) bf = build_file.from_path(args.build_file) repo = repository.Repository(args.repository, args.cell_roots) export_map = bf.get_export_map(repo) def to_load_import_string(import_label: label): pkg = import_label.package # include_defs package includes a file name, so we have to split it # into file name file_name = pkg.split("/")[-1] # and it's prefix - which is the new package pkg = "/".join(pkg.split("/")[:-1]) load_fn_cell = args.cell_prefix + import_label.cell if import_label.cell else "" return load_fn_cell + "//" + pkg + ":" + file_name if args.use_load_function_import_string_format: new_export_map = {} for import_string, exported_symbols in export_map.items(): new_export_map[ to_load_import_string(label.from_string(import_string)) ] = exported_symbols export_map = new_export_map if args.print_as_load_functions: def to_load_function(import_label: label, symbols: List[str]): import_string = to_load_import_string(import_label) function_args = map(lambda s: '"%s"' % s, symbols) return 'load("%s", %s)' % (import_string, ",".join(function_args)) load_functions = [] for import_string, exported_symbols in export_map.items(): load_functions.append( to_load_function(label.from_string(import_string), exported_symbols) ) if args.json: print(json.dumps(load_functions)) else: print(os.linesep.join(load_functions)) elif args.json: print(json.dumps(export_map)) else: for import_string, exported_symbols in export_map.items(): print(import_string + ":") for exported_symbol in exported_symbols: print(" " * 2 + exported_symbol)
def dump_export_map(args): """ Prints export map that includes all included definitions and symbols they export. """ logging.debug("Dumping export map for " + args.build_file) bf = build_file.from_path(args.build_file) repo = repository.Repository(args.repository, args.cell_roots) export_map = bf.get_export_map(repo) def to_load_import_string(import_label: label): pkg = import_label.package # include_defs package includes a file name, so we have to split it # into file name file_name = pkg.split("/")[-1] # and it's prefix - which is the new package pkg = "/".join(pkg.split("/")[:-1]) load_fn_cell = args.cell_prefix + import_label.cell if import_label.cell else "" return load_fn_cell + "//" + pkg + ":" + file_name if args.use_load_function_import_string_format: new_export_map = {} for import_string, exported_symbols in export_map.items(): new_export_map[ to_load_import_string(label.from_string(import_string)) ] = exported_symbols export_map = new_export_map if args.print_as_load_functions: def to_load_function(import_label: label, symbols: List[str]): import_string = to_load_import_string(import_label) function_args = map(lambda s: '"%s"' % s, symbols) return 'load("%s", %s)' % (import_string, ",".join(function_args)) load_functions = [] for import_string, exported_symbols in export_map.items(): load_functions.append( to_load_function(label.from_string(import_string), exported_symbols) ) if args.json: print(json.dumps(load_functions)) else: print(os.linesep.join(load_functions)) elif args.json: print(json.dumps(export_map)) else: for import_string, exported_symbols in export_map.items(): print(import_string + ":") for exported_symbol in exported_symbols: print(" " * 2 + exported_symbol)
def test_find_export_transitive_closure(self): with tempfile.TemporaryDirectory() as tmp_dir: package_dir = os.path.join(tmp_dir, 'pkg') os.mkdir(package_dir) build_file_path = os.path.join(package_dir, 'BUCK') with open(build_file_path, 'w') as buck_file: buck_file.write('include_defs("cell//pkg/DEFS")') buck_file.write(os.linesep) buck_file.write('foo = "FOO"') with open(os.path.join(package_dir, 'DEFS'), 'w') as defs_file: defs_file.write('bar = "BAR"') repo = repository.Repository('/repo', {'cell': tmp_dir}) self.assertEqual(['foo', 'bar'], build_file.from_path(build_file_path). get_exported_symbols_transitive_closure(repo))
def test_find_export_transitive_closure(self): with tempfile.TemporaryDirectory() as tmp_dir: package_dir = os.path.join(tmp_dir, 'pkg') os.mkdir(package_dir) build_file_path = os.path.join(package_dir, 'BUCK') with open(build_file_path, 'w') as buck_file: buck_file.write('include_defs("cell//pkg/DEFS")') buck_file.write(os.linesep) buck_file.write('foo = "FOO"') with open(os.path.join(package_dir, 'DEFS'), 'w') as defs_file: defs_file.write('bar = "BAR"') repo = repository.Repository('/repo', {'cell': tmp_dir}) self.assertEqual(['foo', 'bar'], build_file.from_path(build_file_path) .get_exported_symbols_transitive_closure(repo))
def test_find_export_transitive_closure(self): with tempfile.TemporaryDirectory() as tmp_dir: package_dir = os.path.join(tmp_dir, "pkg") os.mkdir(package_dir) build_file_path = os.path.join(package_dir, "BUCK") with open(build_file_path, "w") as buck_file: buck_file.write('include_defs("cell//pkg/DEFS")') buck_file.write(os.linesep) buck_file.write('foo = "FOO"') with open(os.path.join(package_dir, "DEFS"), "w") as defs_file: defs_file.write('bar = "BAR"') repo = repository.Repository("/repo", {"cell": tmp_dir}) self.assertEqual( ["foo", "bar"], build_file.from_path(build_file_path). get_exported_symbols_transitive_closure(repo), )
def test_find_export_transitive_closure(self): with tempfile.TemporaryDirectory() as tmp_dir: package_dir = os.path.join(tmp_dir, "pkg") os.mkdir(package_dir) build_file_path = os.path.join(package_dir, "BUCK") with open(build_file_path, "w") as buck_file: buck_file.write('include_defs("cell//pkg/DEFS")') buck_file.write(os.linesep) buck_file.write('foo = "FOO"') with open(os.path.join(package_dir, "DEFS"), "w") as defs_file: defs_file.write('bar = "BAR"') repo = repository.Repository("/repo", {"cell": tmp_dir}) self.assertEqual( ["foo", "bar"], build_file.from_path( build_file_path ).get_exported_symbols_transitive_closure(repo), )
def test_get_export_map(self): with tempfile.TemporaryDirectory() as tmp_dir: package_dir = os.path.join(tmp_dir, "pkg") os.mkdir(package_dir) build_file_path = os.path.join(package_dir, "BUCK") with open(build_file_path, "w") as buck_file: buck_file.write('include_defs("cell//pkg/DEFS")') buck_file.write(os.linesep) buck_file.write('foo = "FOO"') with open(os.path.join(package_dir, "DEFS"), "w") as defs_file: defs_file.write('include_defs("cell//pkg/DEFS2")') defs_file.write(os.linesep) defs_file.write('bar = "BAR"') with open(os.path.join(package_dir, "DEFS2"), "w") as defs_file: defs_file.write('baz = "BAZ"') repo = repository.Repository("/repo", {"cell": tmp_dir}) self.assertEqual( {"cell//pkg/DEFS": ["bar"], "cell//pkg/DEFS2": ["baz"]}, build_file.from_path(build_file_path).get_export_map(repo), )
def test_get_export_map(self): with tempfile.TemporaryDirectory() as tmp_dir: package_dir = os.path.join(tmp_dir, "pkg") os.mkdir(package_dir) build_file_path = os.path.join(package_dir, "BUCK") with open(build_file_path, "w") as buck_file: buck_file.write('include_defs("cell//pkg/DEFS")') buck_file.write(os.linesep) buck_file.write('foo = "FOO"') with open(os.path.join(package_dir, "DEFS"), "w") as defs_file: defs_file.write('include_defs("cell//pkg/DEFS2")') defs_file.write(os.linesep) defs_file.write('bar = "BAR"') with open(os.path.join(package_dir, "DEFS2"), "w") as defs_file: defs_file.write('baz = "BAZ"') repo = repository.Repository("/repo", {"cell": tmp_dir}) self.assertEqual( {"cell//pkg/DEFS": ["bar"], "cell//pkg/DEFS2": ["baz"]}, build_file.from_path(build_file_path).get_export_map(repo), )
def test_get_export_map(self): with tempfile.TemporaryDirectory() as tmp_dir: package_dir = os.path.join(tmp_dir, 'pkg') os.mkdir(package_dir) build_file_path = os.path.join(package_dir, 'BUCK') with open(build_file_path, 'w') as buck_file: buck_file.write('include_defs("cell//pkg/DEFS")') buck_file.write(os.linesep) buck_file.write('foo = "FOO"') with open(os.path.join(package_dir, 'DEFS'), 'w') as defs_file: defs_file.write('include_defs("cell//pkg/DEFS2")') defs_file.write(os.linesep) defs_file.write('bar = "BAR"') with open(os.path.join(package_dir, 'DEFS2'), 'w') as defs_file: defs_file.write('baz = "BAZ"') repo = repository.Repository('/repo', {'cell': tmp_dir}) self.assertEqual({ 'cell//pkg/DEFS': ['bar'], 'cell//pkg/DEFS2': ['baz'], }, build_file.from_path(build_file_path).get_export_map(repo))