@@ -34,36 +34,22 @@ def _write_bazelisk_version(new, sha256):
34
34
f .write (new_content )
35
35
36
36
37
- def _get_current_bazel_version () -> str :
38
- """Parses ``.bazelversion`` for the old version of bazel."""
39
- with open (".bazelversion" , encoding = "utf-8" ) as f :
40
- lines = f .read ().splitlines ()
41
- (line ,) = lines
42
- return line .strip ()
43
-
44
-
45
- def _write_bazel_version (new ):
46
- """Overwrites ``.bazelversion`` with the new version of bazel."""
47
- with open (".bazelversion" , "w" , encoding = "utf-8" ) as f :
48
- f .write (f"{ new } \n " )
49
-
50
-
51
- def _get_current_workspace_versions ():
52
- """Parses ``workspace_versions.bzl`` for the old versions."""
53
- with open ("tools/workspace_versions.bzl" , encoding = "utf-8" ) as f :
37
+ def _get_current_buildifier_version ():
38
+ """Parses ``buildifier_version.bzl`` for the old version."""
39
+ with open ("tools/buildifier_version.bzl" , encoding = "utf-8" ) as f :
54
40
content = f .read ()
55
- prefix = "WORKSPACE_VERSIONS = "
41
+ prefix = "BUILDIFIER_VERSION = "
56
42
assert content .startswith (prefix )
57
43
return ast .literal_eval (content .removeprefix (prefix ))
58
44
59
45
60
- def _write_workspace_versions (new ):
61
- """Overwrites ``workspace_versions .bzl`` with the new versions .
46
+ def _write_buildifier_version (new ):
47
+ """Overwrites ``buildifier_version .bzl`` with the new version .
62
48
We assume that tools/update.sh will run buildifier formatting afterwards.
63
49
"""
64
- prefix = "WORKSPACE_VERSIONS = "
50
+ prefix = "BUILDIFIER_VERSION = "
65
51
content = prefix + pformat (new , width = 1 , sort_dicts = False )
66
- with open ("tools/workspace_versions .bzl" , "w" , encoding = "utf-8" ) as f :
52
+ with open ("tools/buildifier_version .bzl" , "w" , encoding = "utf-8" ) as f :
67
53
f .write (content )
68
54
69
55
@@ -111,39 +97,27 @@ def _upgrade_bazelisk():
111
97
_write_bazelisk_version (new , sha256 )
112
98
113
99
114
- def _upgrade_bazel ():
115
- """Upgrades bazel to its latest version (if necessary)."""
116
- old = _get_current_bazel_version ()
117
- new = _find_latest_github_release ("bazelbuild/bazel" )
118
- if new == old :
119
- print (f"bazel is already at the latest version { new } " )
120
- return
121
- print (f"bazel will be upgraded to version { new } " )
122
- _write_bazel_version (new )
123
-
124
-
125
100
def _upgrade_buildifier ():
126
101
"""Upgrades buildifier to its latest version (if necessary)."""
127
- workspace_versions = _get_current_workspace_versions ()
128
- old = workspace_versions [ "buildifier" ] ["version" ]
102
+ buildifier_version = _get_current_buildifier_version ()
103
+ old = buildifier_version ["version" ]
129
104
new = _find_latest_github_release ("bazelbuild/buildtools" )
130
105
if new == old :
131
106
print (f"buildifier is already at the latest version { new } " )
132
107
return
133
108
print (f"buildifier will be upgraded to version { new } " )
134
- workspace_versions [ "buildifier" ] ["version" ] = new
135
- names = list (workspace_versions [ "buildifier" ] ["binaries" ].keys ())
109
+ buildifier_version ["version" ] = new
110
+ names = list (buildifier_version ["binaries" ].keys ())
136
111
releases = "https://github.com/bazelbuild/buildtools/releases"
137
112
for name in names :
138
- workspace_versions [ "buildifier" ] ["binaries" ][name ] = _get_url_checksum (
113
+ buildifier_version ["binaries" ][name ] = _get_url_checksum (
139
114
f"{ releases } /download/v{ new } /{ name } "
140
115
)
141
- _write_workspace_versions ( workspace_versions )
116
+ _write_buildifier_version ( buildifier_version )
142
117
143
118
144
119
def _main ():
145
120
_upgrade_bazelisk ()
146
- _upgrade_bazel ()
147
121
_upgrade_buildifier ()
148
122
149
123
0 commit comments