Skip to content

Commit 414e11a

Browse files
author
Siddhartha Bagaria
committed
Fix default key logic in urls attribute
We were not using the strip_prefix attribute correctly when the default key was being used instead of the host OS key. This resulted in the archive being extracted without any strip_prefix value.
1 parent 2f6e6ad commit 414e11a

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

tests/WORKSPACE

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ llvm_toolchain(
3131
name = "llvm_toolchain",
3232
llvm_version = LLVM_VERSION,
3333
# To test (manually) if the URLs feature works to fetch an archive.
34-
#sha256 = {"ubuntu-20.04-x86_64": "a9ff205eb0b73ca7c86afc6432eed1c2d49133bd0d49e47b15be59bbf0dd292e"},
35-
#strip_prefix = {"ubuntu-20.04-x86_64": "clang+llvm-14.0.0-x86_64-linux-gnu-ubuntu-20.04"},
36-
#urls = {"ubuntu-20.04-x86_64": ["https://github.com/llvm/llvm-project/releases/download/llvmorg-14.0.0/clang+llvm-14.0.0-x86_64-linux-gnu-ubuntu-20.04.tar.xz"]},
34+
#sha256 = {"": "61582215dafafb7b576ea30cc136be92c877ba1f1c31ddbbd372d6d65622fef5"},
35+
#strip_prefix = {"": "clang+llvm-14.0.0-x86_64-linux-gnu-ubuntu-18.04"},
36+
#urls = {"": ["https://github.com/llvm/llvm-project/releases/download/llvmorg-14.0.0/clang+llvm-14.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz"]},
3737
)
3838

3939
# This is the last known LLVM version with zlib support in ld.lld. Without zlib

toolchain/internal/llvm_distributions.bzl

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,11 @@ def _get_auth(ctx, urls):
255255

256256
def download_llvm(rctx):
257257
urls = []
258+
update_sha256 = False
258259
if rctx.attr.urls:
259260
urls, sha256, strip_prefix, key = _urls(rctx)
261+
if not sha256:
262+
update_sha256 = True
260263
if not urls:
261264
urls, sha256, strip_prefix = _distribution_urls(rctx)
262265

@@ -268,21 +271,24 @@ def download_llvm(rctx):
268271
)
269272

270273
updated_attrs = _attr_dict(rctx.attr)
271-
if not sha256 and key:
272-
# Only using the urls attribute can result in no sha256.
273-
# Report back the sha256 if the URL came from a non-empty key.
274+
if update_sha256:
274275
updated_attrs["sha256"].update([(key, res.sha256)])
275-
276276
return updated_attrs
277277

278278
def _urls(rctx):
279279
key = _host_os_key(rctx)
280280

281-
urls = rctx.attr.urls.get(key, default = rctx.attr.urls.get("", default = []))
281+
key_orig = key
282+
if key not in rctx.attr.urls:
283+
print("LLVM archive URLs missing for host OS key '%s'; checking fallback with key ''" % (key))
284+
key = ""
285+
286+
urls = rctx.attr.urls.get(key, default = [])
282287
if not urls:
283-
print("llvm archive urls missing for host OS key '%s' and no default provided; will try 'distribution' attribute" % (key))
284-
sha256 = rctx.attr.sha256.get(key, "")
285-
strip_prefix = rctx.attr.strip_prefix.get(key, "")
288+
print("LLVM archive URLs missing for host OS key '%s' and no default fallback provided; will try 'distribution' attribute" % (key_orig))
289+
290+
sha256 = rctx.attr.sha256.get(key, default = "")
291+
strip_prefix = rctx.attr.strip_prefix.get(key, default = "")
286292

287293
return urls, sha256, strip_prefix, key
288294

0 commit comments

Comments
 (0)