Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fd77f1a

Browse files
committed
Bazel: fix lfs to do checkout rather than smudging
On Windows `git lfs smudge` was not working as expected.
1 parent 38a7bc0 commit fd77f1a

3 files changed

Lines changed: 27 additions & 25 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python3
2+
3+
import sys
4+
import pathlib
5+
import subprocess
6+
import os
7+
8+
sources = [pathlib.Path(arg).resolve() for arg in sys.argv[1:]]
9+
source_dir = pathlib.Path(os.path.commonpath(src.parent for src in sources))
10+
source_dir = subprocess.check_output(["git", "rev-parse", "--show-toplevel"], cwd=source_dir, text=True).strip()
11+
12+
13+
def is_lfs_pointer(file):
14+
lfs_header = "version https://git-lfs.github.com/spec".encode()
15+
with open(file, 'rb') as fileobj:
16+
return fileobj.read(len(lfs_header)) == lfs_header
17+
18+
19+
for src in sources:
20+
if is_lfs_pointer(src):
21+
relative_src = src.relative_to(source_dir)
22+
subprocess.run(["git", "lfs", "fetch", f"--include={relative_src}"], stdout=subprocess.DEVNULL, check=True,
23+
cwd=source_dir)
24+
subprocess.run(["git", "lfs", "checkout", relative_src], check=True, cwd=source_dir)
25+
pathlib.Path(src.name).symlink_to(src)

misc/bazel/internal/git_lfs_smudge.py

Lines changed: 0 additions & 23 deletions
This file was deleted.

misc/bazel/lfs.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
def lfs_smudge(repository_ctx, srcs):
22
for src in srcs:
33
repository_ctx.watch(src)
4-
script = Label("//misc/bazel/internal:git_lfs_smudge.py")
4+
script = Label("//misc/bazel/internal:git_lfs_checkout.py")
55
python = repository_ctx.which("python3") or repository_ctx.which("python")
66
if not python:
77
fail("Neither python3 nor python executables found")
88
res = repository_ctx.execute([python, script] + srcs, quiet = False)
99
if res.return_code != 0:
10-
fail("git LFS smudging failed while instantiating @%s:\n%s" % (repository_ctx.name, res.stderr))
10+
fail("git LFS checkout failed while instantiating @%s:\n%s" % (repository_ctx.name, res.stderr))
1111

1212
def _download_and_extract_lfs(repository_ctx):
1313
attr = repository_ctx.attr

0 commit comments

Comments
 (0)