1
- def lfs_smudge (repository_ctx , srcs ):
1
+ def lfs_smudge (repository_ctx , srcs , extract = False , stripPrefix = None ):
2
2
for src in srcs :
3
3
repository_ctx .watch (src )
4
4
script = Label ("//misc/bazel/internal:git_lfs_probe.py" )
@@ -10,19 +10,28 @@ def lfs_smudge(repository_ctx, srcs):
10
10
fail ("git LFS probing failed while instantiating @%s:\n %s" % (repository_ctx .name , res .stderr ))
11
11
for src , loc in zip (srcs , res .stdout .splitlines ()):
12
12
if loc == "local" :
13
- repository_ctx .symlink (src , src .basename )
13
+ if extract :
14
+ repository_ctx .extract (src , stripPrefix = stripPrefix )
15
+ else :
16
+ repository_ctx .symlink (src , src .basename )
14
17
else :
15
18
sha256 , _ , url = loc .partition (" " )
16
- repository_ctx .download (url , src .basename , sha256 = sha256 )
19
+ if extract :
20
+ # we can't use skylib's `paths.split_extension`, as that only gets the last extension, so `.tar.gz`
21
+ # or similar wouldn't work
22
+ # it doesn't matter if file is something like some.name.zip and possible_extension == "name.zip",
23
+ # download_and_extract will just append ".name.zip" its internal temporary name, so extraction works
24
+ possible_extension = "." .join (src .basename .rsplit ("." , 2 )[- 2 :])
25
+ repository_ctx .download_and_extract (url , sha256 = sha256 , stripPrefix = stripPrefix , type = possible_extension )
26
+ else :
27
+ repository_ctx .download (url , src .basename , sha256 = sha256 )
17
28
18
29
def _download_and_extract_lfs (repository_ctx ):
19
30
attr = repository_ctx .attr
20
31
src = repository_ctx .path (attr .src )
21
32
if attr .build_file_content and attr .build_file :
22
33
fail ("You should specify only one among build_file_content and build_file for rule @%s" % repository_ctx .name )
23
- lfs_smudge (repository_ctx , [src ])
24
- repository_ctx .extract (src .basename , stripPrefix = attr .strip_prefix )
25
- repository_ctx .delete (src .basename )
34
+ lfs_smudge (repository_ctx , [src ], extract = True , stripPrefix = attr .strip_prefix )
26
35
if attr .build_file_content :
27
36
repository_ctx .file ("BUILD.bazel" , attr .build_file_content )
28
37
elif attr .build_file :
0 commit comments