Skip to content

Commit 3a19bd3

Browse files
authored
Add progress display during binary downloads. (#511)
1 parent d7764e7 commit 3a19bd3

File tree

15 files changed

+283
-57
lines changed

15 files changed

+283
-57
lines changed

BUILD

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ go_test(
5858
embed = [":go_default_library"],
5959
importpath = "github.com/bazelbuild/bazelisk",
6060
deps = [
61+
"//config:go_default_library",
6162
"//core:go_default_library",
6263
"//httputil:go_default_library",
6364
"//repositories:go_default_library",
@@ -154,14 +155,14 @@ go_binary(
154155
pkg_npm(
155156
name = "npm_package",
156157
package_name = "@bazel/bazelisk",
157-
substitutions = {"0.0.0-PLACEHOLDER": "{BUILD_SCM_VERSION}"},
158158
srcs = [
159159
"LICENSE",
160160
"README.md",
161161
"bazelisk.d.ts",
162162
"bazelisk.js",
163163
"package.json",
164164
],
165+
substitutions = {"0.0.0-PLACEHOLDER": "{BUILD_SCM_VERSION}"},
165166
deps = [
166167
":bazelisk-darwin-amd64",
167168
":bazelisk-darwin-arm64",

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ The following variables can be set:
183183
- `BAZELISK_GITHUB_TOKEN`
184184
- `BAZELISK_HOME`
185185
- `BAZELISK_INCOMPATIBLE_FLAGS`
186+
- `BAZELISK_SHOW_PROGRESS`
186187
- `BAZELISK_SHUTDOWN`
187188
- `BAZELISK_SKIP_WRAPPER`
188189
- `BAZELISK_USER_AGENT`

WORKSPACE

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,20 @@ go_repository(
4949
version = "v0.0.0-20140422174119-9fd32a8b3d3d",
5050
)
5151

52+
go_repository(
53+
name = "org_golang_x_term",
54+
importpath = "golang.org/x/term",
55+
sum = "h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek=",
56+
version = "v0.13.0",
57+
)
58+
59+
go_repository(
60+
name = "org_golang_x_sys",
61+
importpath = "golang.org/x/sys",
62+
sum = "h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=",
63+
version = "v0.13.0",
64+
)
65+
5266
go_rules_dependencies()
5367

5468
go_register_toolchains(version = "1.19.4")

bazelisk_version_test.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strings"
1010
"testing"
1111

12+
"github.com/bazelbuild/bazelisk/config"
1213
"github.com/bazelbuild/bazelisk/core"
1314
"github.com/bazelbuild/bazelisk/httputil"
1415
"github.com/bazelbuild/bazelisk/repositories"
@@ -42,7 +43,7 @@ func TestResolveVersion(t *testing.T) {
4243

4344
gcs := &repositories.GCSRepo{}
4445
repos := core.CreateRepositories(nil, gcs, nil, nil, nil, false)
45-
version, _, err := repos.ResolveVersion(tmpDir, versions.BazelUpstream, "4.0.0")
46+
version, _, err := repos.ResolveVersion(tmpDir, versions.BazelUpstream, "4.0.0", config.Null())
4647

4748
if err != nil {
4849
t.Fatalf("Version resolution failed unexpectedly: %v", err)
@@ -60,7 +61,7 @@ func TestResolvePatchVersion(t *testing.T) {
6061

6162
gcs := &repositories.GCSRepo{}
6263
repos := core.CreateRepositories(nil, gcs, nil, nil, nil, false)
63-
version, _, err := repos.ResolveVersion(tmpDir, versions.BazelUpstream, "4.0.0-patch1")
64+
version, _, err := repos.ResolveVersion(tmpDir, versions.BazelUpstream, "4.0.0-patch1", config.Null())
6465

6566
if err != nil {
6667
t.Fatalf("Version resolution failed unexpectedly: %v", err)
@@ -82,7 +83,7 @@ func TestResolveLatestRcVersion(t *testing.T) {
8283

8384
gcs := &repositories.GCSRepo{}
8485
repos := core.CreateRepositories(nil, gcs, nil, nil, nil, false)
85-
version, _, err := repos.ResolveVersion(tmpDir, versions.BazelUpstream, "last_rc")
86+
version, _, err := repos.ResolveVersion(tmpDir, versions.BazelUpstream, "last_rc", config.Null())
8687

8788
if err != nil {
8889
t.Fatalf("Version resolution failed unexpectedly: %v", err)
@@ -100,7 +101,7 @@ func TestResolveLatestRcVersion_WithFullRelease(t *testing.T) {
100101

101102
gcs := &repositories.GCSRepo{}
102103
repos := core.CreateRepositories(nil, gcs, nil, nil, nil, false)
103-
version, _, err := repos.ResolveVersion(tmpDir, versions.BazelUpstream, "last_rc")
104+
version, _, err := repos.ResolveVersion(tmpDir, versions.BazelUpstream, "last_rc", config.Null())
104105

105106
if err != nil {
106107
t.Fatalf("Version resolution failed unexpectedly: %v", err)
@@ -120,7 +121,7 @@ func TestResolveLatestVersion_TwoLatestVersionsDoNotHaveAReleaseYet(t *testing.T
120121

121122
gcs := &repositories.GCSRepo{}
122123
repos := core.CreateRepositories(gcs, nil, nil, nil, nil, false)
123-
version, _, err := repos.ResolveVersion(tmpDir, versions.BazelUpstream, "latest")
124+
version, _, err := repos.ResolveVersion(tmpDir, versions.BazelUpstream, "latest", config.Null())
124125

125126
if err != nil {
126127
t.Fatalf("Version resolution failed unexpectedly: %v", err)
@@ -142,7 +143,7 @@ func TestResolveLatestVersion_ShouldOnlyReturnStableReleases(t *testing.T) {
142143

143144
gcs := &repositories.GCSRepo{}
144145
repos := core.CreateRepositories(gcs, nil, nil, nil, nil, false)
145-
version, _, err := repos.ResolveVersion(tmpDir, versions.BazelUpstream, "latest-1")
146+
version, _, err := repos.ResolveVersion(tmpDir, versions.BazelUpstream, "latest-1", config.Null())
146147

147148
if err != nil {
148149
t.Fatalf("Version resolution failed unexpectedly: %v", err)
@@ -161,7 +162,7 @@ func TestResolveLatestVersion_ShouldFailIfNotEnoughReleases(t *testing.T) {
161162

162163
gcs := &repositories.GCSRepo{}
163164
repos := core.CreateRepositories(gcs, nil, nil, nil, nil, false)
164-
_, _, err := repos.ResolveVersion(tmpDir, versions.BazelUpstream, "latest-1")
165+
_, _, err := repos.ResolveVersion(tmpDir, versions.BazelUpstream, "latest-1", config.Null())
165166

166167
if err == nil {
167168
t.Fatal("Expected ResolveVersion() to fail.")
@@ -178,7 +179,7 @@ func TestResolveLatestVersion_GCSIsDown(t *testing.T) {
178179

179180
gcs := &repositories.GCSRepo{}
180181
repos := core.CreateRepositories(gcs, nil, nil, nil, nil, false)
181-
_, _, err := repos.ResolveVersion(tmpDir, versions.BazelUpstream, "latest")
182+
_, _, err := repos.ResolveVersion(tmpDir, versions.BazelUpstream, "latest", config.Null())
182183

183184
if err == nil {
184185
t.Fatal("Expected resolveLatestVersion() to fail.")
@@ -196,7 +197,7 @@ func TestResolveLatestVersion_GitHubIsDown(t *testing.T) {
196197
gh := repositories.CreateGitHubRepo("test_token")
197198
repos := core.CreateRepositories(nil, nil, gh, nil, nil, false)
198199

199-
_, _, err := repos.ResolveVersion(tmpDir, "some_fork", "latest")
200+
_, _, err := repos.ResolveVersion(tmpDir, "some_fork", "latest", config.Null())
200201

201202
if err == nil {
202203
t.Fatal("Expected resolveLatestVersion() to fail.")
@@ -212,7 +213,7 @@ func TestAcceptRollingReleaseName(t *testing.T) {
212213
repos := core.CreateRepositories(nil, nil, nil, nil, gcs, false)
213214

214215
for _, version := range []string{"10.0.0-pre.20201103.4", "10.0.0-pre.20201103.4.2"} {
215-
resolvedVersion, _, err := repos.ResolveVersion(tmpDir, "", version)
216+
resolvedVersion, _, err := repos.ResolveVersion(tmpDir, "", version, config.Null())
216217

217218
if err != nil {
218219
t.Fatalf("ResolveVersion(%q, \"\", %q): expected no error, but got %v", tmpDir, version, err)
@@ -233,7 +234,7 @@ func TestResolveLatestRollingRelease(t *testing.T) {
233234
gcs := &repositories.GCSRepo{}
234235
repos := core.CreateRepositories(nil, nil, nil, nil, gcs, false)
235236

236-
version, _, err := repos.ResolveVersion(tmpDir, "", rollingReleaseIdentifier)
237+
version, _, err := repos.ResolveVersion(tmpDir, "", rollingReleaseIdentifier, config.Null())
237238

238239
if err != nil {
239240
t.Fatalf("ResolveVersion(%q, \"\", %q): expected no error, but got %v", tmpDir, rollingReleaseIdentifier, err)
@@ -257,7 +258,7 @@ func TestAcceptFloatingReleaseVersions(t *testing.T) {
257258

258259
gcs := &repositories.GCSRepo{}
259260
repos := core.CreateRepositories(gcs, nil, nil, nil, nil, false)
260-
version, _, err := repos.ResolveVersion(tmpDir, versions.BazelUpstream, "4.x")
261+
version, _, err := repos.ResolveVersion(tmpDir, versions.BazelUpstream, "4.x", config.Null())
261262

262263
if err != nil {
263264
t.Fatalf("Version resolution failed unexpectedly: %v", err)

core/core.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ func downloadBazel(bazelVersionString string, bazeliskHome string, repos *Reposi
322322
return "", fmt.Errorf("could not parse Bazel fork and version: %v", err)
323323
}
324324

325-
resolvedBazelVersion, downloader, err := repos.ResolveVersion(bazeliskHome, bazelFork, bazelVersion)
325+
resolvedBazelVersion, downloader, err := repos.ResolveVersion(bazeliskHome, bazelFork, bazelVersion, config)
326326
if err != nil {
327327
return "", fmt.Errorf("could not resolve the version '%s' to an actual version number: %v", bazelVersion, err)
328328
}
@@ -415,7 +415,7 @@ func downloadBazelToCAS(version string, bazeliskHome string, repos *Repositories
415415
} else if formatURL != "" {
416416
tmpDestPath, err = repos.DownloadFromFormatURL(config, formatURL, version, temporaryDownloadDir, tmpDestFile)
417417
} else if baseURL != "" {
418-
tmpDestPath, err = repos.DownloadFromBaseURL(baseURL, version, temporaryDownloadDir, tmpDestFile)
418+
tmpDestPath, err = repos.DownloadFromBaseURL(baseURL, version, temporaryDownloadDir, tmpDestFile, config)
419419
} else {
420420
tmpDestPath, err = downloader(temporaryDownloadDir, tmpDestFile)
421421
}

0 commit comments

Comments
 (0)