Skip to content

Commit

Permalink
Stop downloading existing Bazel binaries (bazelbuild#438)
Browse files Browse the repository at this point in the history
Due to a bug Bazelisk never read any binaries from the cache, thus resulting in severe runtime penalties.
  • Loading branch information
fweikert authored Mar 22, 2023
1 parent ef81536 commit 204a69f
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func RunBazeliskWithArgsFunc(argsFunc ArgsFunc, repos *Repositories) (int, error
}

baseDirectory := filepath.Join(bazeliskHome, "downloads", bazelForkOrURL)
bazelPath, err = downloadBazel(resolvedBazelVersion, baseDirectory, repos, downloader)
bazelPath, err = downloadBazelIfNecessary(resolvedBazelVersion, baseDirectory, repos, downloader)
if err != nil {
return -1, fmt.Errorf("could not download Bazel: %v", err)
}
Expand Down Expand Up @@ -404,20 +404,25 @@ func parseBazelForkAndVersion(bazelForkAndVersion string) (string, string, error
return bazelFork, bazelVersion, nil
}

func downloadBazel(version string, baseDirectory string, repos *Repositories, downloader DownloadFunc) (string, error) {
func downloadBazelIfNecessary(version string, baseDirectory string, repos *Repositories, downloader DownloadFunc) (string, error) {
pathSegment, err := platforms.DetermineBazelFilename(version, false)
if err != nil {
return "", fmt.Errorf("could not determine path segment to use for Bazel binary: %v", err)
}

destDir := filepath.Join(baseDirectory, pathSegment, "bin")
destFile := "bazel" + platforms.DetermineExecutableFilenameSuffix()
destinationDir := filepath.Join(baseDirectory, pathSegment, "bin")

destPath := filepath.Join(destDir, destFile)
if _, err := os.Stat(destPath); err == nil {
return destPath, nil
}

if url := GetEnvOrConfig(BaseURLEnv); url != "" {
return repos.DownloadFromBaseURL(url, version, destinationDir, destFile)
return repos.DownloadFromBaseURL(url, version, destDir, destFile)
}

return downloader(destinationDir, destFile)
return downloader(destDir, destFile)
}

func copyFile(src, dst string, perm os.FileMode) error {
Expand Down

0 comments on commit 204a69f

Please sign in to comment.