Пример #1
0
    def get_binary_path(self, binary: Binary) -> Path:
        # Special case: allow the path to be specified in the binary object itself for testing purposes:
        if binary.path:
            return Path(binary.path)
        # Try resolved cache first.
        result = self._resolved_paths.get(binary.SerializePartialToString())
        if result:
            return result
        log(f"Finding path of binary:\n{binary}")

        # Try list (cache) of binary artifacts on disk.
        result = self._get_binary_path_from_binary_artifacts(binary)
        if result:
            return result

        # Try online.
        wrapped_recipe = get_github_release_recipe(binary)
        # Execute the recipe to download the binaries.
        artifact_util.artifact_execute_recipe_if_needed(
            wrapped_recipe.path, {wrapped_recipe.path: wrapped_recipe.recipe})
        # Add to binary artifacts list (cache).
        self._binary_artifacts.append((
            wrapped_recipe.recipe.download_and_extract_archive_set.archive_set,
            wrapped_recipe.path,
        ))
        # Now we should be able to find it in the binary artifacts list.
        result = self._get_binary_path_from_binary_artifacts(binary)
        check(
            bool(result),
            AssertionError(
                f"Could not find:\n{binary} even though we just added it:\n{wrapped_recipe}"
            ),
        )
        assert result  # noqa
        return result
Пример #2
0
 def _get_binary_path_from_binary_artifacts(
         self, binary: Binary) -> Optional[Path]:
     binary_tags = set(binary.tags)
     binary_tags.add(self._platform)
     for (archive_set, artifact_path) in self._binary_artifacts:
         for artifact_binary in archive_set.binaries:  # type: Binary
             if artifact_binary.name != binary.name:
                 continue
             if artifact_binary.version != binary.version:
                 continue
             recipe_binary_tags = set(artifact_binary.tags)
             if not binary_tags.issubset(recipe_binary_tags):
                 continue
             artifact_util.artifact_execute_recipe_if_needed(
                 artifact_path, self._built_in_binary_recipes)
             result = artifact_util.artifact_get_inner_file_path(
                 artifact_binary.path, artifact_path)
             self._resolved_paths[
                 binary.SerializePartialToString()] = result
             return result
     return None