Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Bazel version retrieval & downloads (bazelbuild#151)
------- Summary ------- This change introduces dedicated interfaces to handle how Bazel versions are retrieved and downloaded. ------- Details ------- The new `core` package introduces interfaces that represent four kinds of repositories that store Bazel versions: `ReleaseRepo`, `CandidateRepo`, `ForkRepo` and `LastGreenRepo`. Implementations of these interfaces must provide a list of available Bazel versions, as well as a function to download a desired version. The old main function was moved into `RunBazelisk()`, which expects implementations of these interfaces. As a result, the caller of this function can control which repositories are used. The previously existing repositories, GitHub and GCS, are still supported since they implement the new interfaces. GitHub is used for forks, whereas GCS is used for everything else. Moreover, the existing `BAZELISK_BASE_URL` environment variable is still supported, and overrides the repository interfaces (if set). Finally, this change moves some utility functions into new, dedicated packages such as `httputil` (for retrieving files via HTTP), `platforms` (for determining platform specific information) and `versions` (for sorting version numbers). ---------- Motivation ---------- The idea is to turn Bazelisk into a library that supports arbitrary repositories. For example, companies might want to ship their own version of Bazelisk that fetches all Bazel binaries from their internal servers. ---------- Next steps ---------- The next PR will move `RunBazelisk()` into the `core` package so that it can be used as a pure library. I didn’t want to move it in this PR to get better code diffs. ------------------ Functional changes ------------------ Even though this is a refactoring, a functional change has been made: The previous version used GitHub as a fallback when GCS was unavailable. This is no longer the case. As a result, the Python version now deviates from the Go version since the latter uses GCS, whereas the first uses GitHub. This forced me to rewrite the shell test, too, since the Go tests must be less strict wrt expected versions: Since the Go version uses GCS the fake json file written in the test is only used by the Python version. As a result, the shell test is effectively an integration test for the Go version and requires network access. Moreover, we can no longer check for specific Bazel version in the Go test since "latest" will point at different releases over time. We should split the test into proper Go and Python versions. * De-duplicate repo selection logic The first version of the PR determined which repo should be used (e.g. release vs candidate repo) in two places: Once in bazelisk.go when the version had to be resolved, and a second time in the core module when a binary had to be downloaded. This has now changed: core.Repositories got the new ResolveVersion() function that resolves a version label and also returns the appropriate download function. As a result, bazelisk.go is no longer in the business of caring about versions and can simply call the download function (unless BAZELISK_BASE_URL is set, of course). Positive side-effects: - All version parsing / analysis was moved into the versions module. - A lot of code from bazelisk.go could be removed. - LastGreenRepo was renamed to CommitRepo and now supports commit hashes, too.
- Loading branch information