Bazel: add executable attribute to `lfs_files`

This commit is contained in:
Paolo Tranquilli 2024-05-24 12:35:17 +02:00
Родитель 1529b58089
Коммит 8e132e90cc
1 изменённых файлов: 5 добавлений и 4 удалений

Просмотреть файл

@ -1,4 +1,4 @@
def lfs_smudge(repository_ctx, srcs, extract = False, stripPrefix = None):
def lfs_smudge(repository_ctx, srcs, *, extract = False, stripPrefix = None, executable = False):
python = repository_ctx.which("python3") or repository_ctx.which("python")
if not python:
fail("Neither python3 nor python executables found")
@ -25,7 +25,7 @@ def lfs_smudge(repository_ctx, srcs, extract = False, stripPrefix = None):
repository_ctx.symlink(src, src.basename)
else:
repository_ctx.report_progress("trying cache for remote %s" % src.basename)
res = repository_ctx.download([], src.basename, sha256 = info, allow_fail = True)
res = repository_ctx.download([], src.basename, sha256 = info, allow_fail = True, executable = executable)
if not res.success:
remote.append(src)
if remote:
@ -33,7 +33,7 @@ def lfs_smudge(repository_ctx, srcs, extract = False, stripPrefix = None):
for src, info in zip(remote, infos):
sha256, _, url = info.partition(" ")
repository_ctx.report_progress("downloading remote %s" % src.basename)
repository_ctx.download(url, src.basename, sha256 = sha256)
repository_ctx.download(url, src.basename, sha256 = sha256, executable = executable)
if extract:
for src in srcs:
repository_ctx.report_progress("extracting %s" % src.basename)
@ -62,7 +62,7 @@ def _download_lfs(repository_ctx):
if not dir.is_dir:
fail("`dir` not a directory in @%s" % repository_ctx.name)
srcs = [f for f in dir.readdir() if not f.is_dir]
lfs_smudge(repository_ctx, srcs)
lfs_smudge(repository_ctx, srcs, executable = repository_ctx.attr.executable)
# with bzlmod the name is qualified with `~` separators, and we want the base name here
name = repository_ctx.name.split("~")[-1]
@ -98,5 +98,6 @@ lfs_files = repository_rule(
"srcs": attr.label_list(doc = "Local paths to the LFS files to export."),
"dir": attr.label(doc = "Local path to a directory containing LFS files to export. Only the direct contents " +
"of the directory are exported"),
"executable": attr.bool(doc = "Whether files should be marked as executable"),
},
)