Exemplo n.º 1
0
    def test_is_library_package(self):
        root_path = tempfile.mkdtemp("monorepo")
        package_path = "projects/libs/pastry/abstractions"
        md_dir_name = "MVN-INF"
        mdfiles.MD_DIR_NAME = md_dir_name
        abs_package_path = os.path.join(root_path, package_path)

        self._write_file(root_path,
                         package_path,
                         md_dir_name,
                         "FOO",
                         content="")
        self.assertFalse(mdfiles.is_library_package(abs_package_path))
        self._write_file(root_path,
                         package_path,
                         md_dir_name,
                         "LIBRARY.root",
                         content="")
        if not mdfiles.is_library_package(abs_package_path):
            package_content = str(os.listdir(abs_package_path))
            md_dir_content = str(
                os.listdir(os.path.join(abs_package_path, md_dir_name)))
            self.fail(
                "Library marker file not found at path %s. Package has files: %s  md dir has files %s"
                % (abs_package_path, package_content, md_dir_content))
Exemplo n.º 2
0
def query_all_libraries(repository_root_path, packages):
    """
    Given a list of (BUILD.pom) packages, walks the paths up to find the root
    library directories, and returns those (without duplicates).
    """
    lib_roots = set()
    for package in packages:
        while len(package) > 0 and package != '/':
            abs_package_path = os.path.join(repository_root_path, package)
            if mdfiles.is_library_package(abs_package_path):
                lib_roots.add(package)
                break
            else:
                package = os.path.dirname(package)
    return sorted(lib_roots)
Exemplo n.º 3
0
def _get_library_path(repo_root_path, art_def):
    """
    Starts at the path the specified artifact lives at and "walks up" to find  
    the location (path) of the library owning the specified artifact.
    """
    abs_repo_path = os.path.abspath(repo_root_path)
    org_abs_path = os.path.abspath(
        os.path.join(repo_root_path, art_def.bazel_package))
    path = org_abs_path
    emergency_break = 0
    while True:
        if mdfiles.is_library_package(path):
            return os.path.relpath(path, repo_root_path)
        if path == abs_repo_path:
            raise Exception("Did not find %s at %s or any parent dir" %
                            (mdfiles.LIB_ROOT_FILE_NAME, org_abs_path))
        path = os.path.dirname(path)
        assert emergency_break < 50  # just in case
        emergency_break += 1
Exemplo n.º 4
0
def query_all_libraries(repository_root_path, packages):
    """
    Given a list of (BUILD.pom) packages, walks the paths up to find the root
    library directories, and returns those (without duplicates).
    """
    lib_roots = []
    for org_package in packages:
        for lib_root in lib_roots:
            if org_package.startswith(lib_root):
                break # we already have the path for this library
        else:
            package = org_package
            while len(package) > 0 and package != '/':
                abs_package_path = os.path.join(repository_root_path, package)
                if mdfiles.is_library_package(abs_package_path):
                    lib_roots.append(package)
                    break
                else:
                    package = os.path.dirname(package)

    return lib_roots