Skip to content

Bazel: Add lfs_archives function - #22483

Open
jketema wants to merge 4 commits into
mainfrom
jketema/lfs-archives
Open

Bazel: Add lfs_archives function#22483
jketema wants to merge 4 commits into
mainfrom
jketema/lfs-archives

Conversation

@jketema

@jketema jketema commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

This pulls out some generic stuff from the Swift static runtime into a generic location.

Internal clean-up PR will follow once this is in.

This pulls out some generic stuff from the Swift static runtime into
a generic location.

Internal clean-up PR will follow once this is in.
Copilot AI balanced review requested due to automatic review settings September 1, 2026 14:10
@jketema
jketema requested a review from a team as a code owner September 1, 2026 14:10
Comment thread misc/bazel/lfs.bzl
Comment on lines -31 to +41
if remote:
infos = probe(remote)
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, executable = executable)
if extract:
for src in srcs:
repository_ctx.report_progress("extracting %s" % src.basename)
repository_ctx.extract(src.basename, stripPrefix = stripPrefix)
repository_ctx.delete(src.basename)
if remote:
infos = probe(remote)
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, executable = executable)
if extract:
for src in srcs:
repository_ctx.report_progress("extracting %s" % src.basename)
repository_ctx.extract(src.basename, stripPrefix = stripPrefix)
repository_ctx.delete(src.basename)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot changed the indentation here. The old indentation indeed looks somewhat fishy.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, indeed, seems like a latent bug being fixed 👍

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Duplicate archive basenames can collide in the shared staging location and cause incorrect extraction.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review tier: Balanced
Findings: 1 Medium severity

New issues introduced by this change (1)
Severity Finding
Medium severity misc/​bazel/​lfs.bzl — Different source labels can have the same basename, but lfs_smudge stages every input at…
What changed in this PR

Adds reusable support for overlaying multiple Git LFS archives in one Bazel repository.

Changes:

  • Fixes multi-source download/extraction sequencing.
  • Adds the public lfs_archives repository rule.
File Description
misc/​bazel/​lfs.bzl Adds ordered multi-archive LFS extraction support.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread misc/bazel/lfs.bzl Outdated
def _download_and_extract_lfs_archives(repository_ctx):
lfs_smudge(
repository_ctx,
[repository_ctx.path(src) for src in repository_ctx.attr.srcs],

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in c5f2bdb

@jketema
jketema requested a review from redsun82 September 2, 2026 09:57

@redsun82 redsun82 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks a lot, only a minor nit on my side

Comment thread misc/bazel/lfs.bzl
Comment on lines -31 to +41
if remote:
infos = probe(remote)
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, executable = executable)
if extract:
for src in srcs:
repository_ctx.report_progress("extracting %s" % src.basename)
repository_ctx.extract(src.basename, stripPrefix = stripPrefix)
repository_ctx.delete(src.basename)
if remote:
infos = probe(remote)
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, executable = executable)
if extract:
for src in srcs:
repository_ctx.report_progress("extracting %s" % src.basename)
repository_ctx.extract(src.basename, stripPrefix = stripPrefix)
repository_ctx.delete(src.basename)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, indeed, seems like a latent bug being fixed 👍

Comment thread misc/bazel/lfs.bzl Outdated
"build_file_content": attr.string(doc = "The content for the BUILD file for this repository. " +
"Either build_file or build_file_content can be specified, but not both."),
"srcs": attr.label_list(doc = "Local paths to the LFS archives to extract in order.", mandatory = True),
"strip_prefix": attr.string(default = "", doc = "A directory prefix to strip from the extracted files."),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we might want to have a per src strip prefix, but until we need that we can just keep this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then I'll keep this for now.

Comment thread misc/bazel/lfs.bzl
doc = "Overlay the contents from on-demand LFS archives. The corresponding paths should be added to be ignored " +
"in `.lfsconfig`.",
implementation = _download_and_extract_lfs_archives,
attrs = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should extract the common attributes to a _lfs_archive_attrs dictionary to avoid repeating, only leaving src/srcs out

attrs = {
    "src": ...,
    **_lfs_archive_attrs,
},

or

attrs = {
    "src": ...,
} | _lfs_archive_attrs,

(don't remember whether bazel supports the former, but it definitely supports the latter)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 7814be5

@jketema
jketema requested a review from redsun82 September 2, 2026 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants