Example #1
0
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)
Example #2
0
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)
Example #3
0
 def test_can_resolve_path_to_build_file(self):
     l = label.from_string('cell//pkg:name')
     cell_roots = {
         'cell': '/repo/cell',
     }
     self.assertEqual('/repo/cell/pkg/BUCK',
                      l.get_build_file_path(cell_roots, 'BUCK'))
Example #4
0
 def test_can_resolve_path_to_build_file(self):
     l = label.from_string('cell//pkg:name')
     cell_roots = {
         'cell': '/repo/cell',
     }
     self.assertEqual('/repo/cell/pkg/BUCK',
                      l.get_build_file_path(cell_roots, 'BUCK'))
def load_output(name):
  if not os.path.exists(output(name)):
    return None
  f = open(output(name), 'r')
  result = []
  for line in f.readlines():
    result.append(label.from_string(line))
  return result
Example #6
0
 def test_can_convert_to_import_string_without_name(self):
     self.assertEqual("cell//pkg", label.from_string("cell//pkg").to_import_string())
Example #7
0
 def test_can_parse_label_without_cell(self):
     l = label.from_string("//package:name")
     self.assertEqual(l.name, "name")
     self.assertEqual(l.package, "package")
     self.assertIsNone(l.cell)
Example #8
0
 def test_can_parse_full_label_from_string(self):
     l = label.from_string('cell//package:name')
     self.assertEqual(l.name, 'name')
     self.assertEqual(l.package, 'package')
     self.assertEqual(l.cell, 'cell')
Example #9
0
 def test_can_parse_label_with_multilevel_package(self):
     l = label.from_string('cell//pkg/subpkg:name')
     self.assertEqual(l.name, 'name')
     self.assertEqual(l.package, 'pkg/subpkg')
     self.assertEqual(l.cell, 'cell')
Example #10
0
 def test_can_convert_to_import_string(self):
     self.assertEqual(
         "cell//pkg:name",
         label.from_string("cell//pkg:name").to_import_string())
Example #11
0
 def test_can_convert_to_import_string_without_name(self):
     self.assertEqual("cell//pkg",
                      label.from_string("cell//pkg").to_import_string())
Example #12
0
 def test_can_parse_label_with_extension(self):
     l = label.from_string("//pkg/file.ext")
     self.assertIsNone(l.name)
     self.assertEqual(l.package, "pkg/file.ext")
     self.assertIsNone(l.cell)
Example #13
0
 def test_cannot_parse_invalid_label(self):
     with self.assertRaisesRegex(AssertionError,
                                 "Invalid label 'cell/pkg:name'"):
         label.from_string("cell/pkg:name")
Example #14
0
 def get_label(self) -> label.Label:
     """Returns a label identifying a build extension file."""
     return label.from_string(self.get_location())
Example #15
0
 def test_can_parse_label_with_dashes(self):
     l = label.from_string("//pkg-1:name")
     self.assertEqual(l.name, "name")
     self.assertEqual(l.package, "pkg-1")
     self.assertIsNone(l.cell)
Example #16
0
 def test_can_parse_full_label_from_string(self):
     l = label.from_string("cell//package:name")
     self.assertEqual(l.name, "name")
     self.assertEqual(l.package, "package")
     self.assertEqual(l.cell, "cell")
Example #17
0
 def test_can_parse_full_label_from_string(self):
     l = label.from_string('cell//package:name')
     self.assertEqual(l.name, 'name')
     self.assertEqual(l.package, 'package')
     self.assertEqual(l.cell, 'cell')
Example #18
0
 def test_can_convert_to_import_string_without_cell(self):
     self.assertEqual('//pkg:name',
                      label.from_string('//pkg:name').to_import_string())
Example #19
0
 def test_can_convert_to_import_string_without_cell(self):
     self.assertEqual('//pkg:name',
                      label.from_string('//pkg:name').to_import_string())
Example #20
0
 def test_can_parse_label_with_multilevel_package(self):
     l = label.from_string('cell//pkg/subpkg:name')
     self.assertEqual(l.name, 'name')
     self.assertEqual(l.package, 'pkg/subpkg')
     self.assertEqual(l.cell, 'cell')
Example #21
0
 def test_can_parse_label_without_cell(self):
     l = label.from_string("//package:name")
     self.assertEqual(l.name, "name")
     self.assertEqual(l.package, "package")
     self.assertIsNone(l.cell)
Example #22
0
 def test_can_parse_label_with_dashes(self):
     l = label.from_string("//pkg-1:name")
     self.assertEqual(l.name, "name")
     self.assertEqual(l.package, "pkg-1")
     self.assertIsNone(l.cell)
Example #23
0
 def test_can_parse_label_with_dashes_in_cell(self):
     l = label.from_string("my-cell//pkg-1:name")
     self.assertEqual(l.name, "name")
     self.assertEqual(l.package, "pkg-1")
     self.assertEqual(l.cell, "my-cell")
Example #24
0
 def test_can_parse_label_with_dashes_in_cell(self):
     l = label.from_string("my-cell//pkg-1:name")
     self.assertEqual(l.name, "name")
     self.assertEqual(l.package, "pkg-1")
     self.assertEqual(l.cell, "my-cell")
Example #25
0
 def test_can_parse_label_with_multilevel_package(self):
     l = label.from_string("cell//pkg/subpkg:name")
     self.assertEqual(l.name, "name")
     self.assertEqual(l.package, "pkg/subpkg")
     self.assertEqual(l.cell, "cell")
Example #26
0
 def test_can_parse_label_with_extension(self):
     l = label.from_string("//pkg/file.ext")
     self.assertIsNone(l.name)
     self.assertEqual(l.package, "pkg/file.ext")
     self.assertIsNone(l.cell)
Example #27
0
 def test_can_resolve_path_to_build_file(self):
     l = label.from_string("cell//pkg:name")
     cell_roots = {"cell": "/repo/cell"}
     self.assertEqual("/repo/cell/pkg/BUCK",
                      l.get_build_file_path(cell_roots, "BUCK"))
Example #28
0
 def test_can_parse_label_with_multilevel_package(self):
     l = label.from_string("cell//pkg/subpkg:name")
     self.assertEqual(l.name, "name")
     self.assertEqual(l.package, "pkg/subpkg")
     self.assertEqual(l.cell, "cell")
Example #29
0
 def test_can_parse_full_label_from_string(self):
     l = label.from_string("cell//package:name")
     self.assertEqual(l.name, "name")
     self.assertEqual(l.package, "package")
     self.assertEqual(l.cell, "cell")
Example #30
0
 def test_cannot_parse_invalid_label(self):
     with self.assertRaisesRegex(AssertionError, "Invalid label 'cell/pkg:name'"):
         label.from_string("cell/pkg:name")
Example #31
0
 def test_can_resolve_path_to_build_file(self):
     l = label.from_string("cell//pkg:name")
     cell_roots = {"cell": "/repo/cell"}
     self.assertEqual(
         "/repo/cell/pkg/BUCK", l.get_build_file_path(cell_roots, "BUCK")
     )
Example #32
0
 def test_can_convert_to_import_string(self):
     self.assertEqual(
         "cell//pkg:name", label.from_string("cell//pkg:name").to_import_string()
     )
Example #33
0
 def get_label(self) -> label.Label:
     """Returns a label identifying a build extension file."""
     return label.from_string(self.get_location())
Example #34
0
 def test_can_parse_label_with_dashes_in_cell(self):
     l = label.from_string('my-cell//pkg-1:name')
     self.assertEqual(l.name, 'name')
     self.assertEqual(l.package, 'pkg-1')
     self.assertEqual(l.cell, 'my-cell')