1- def lfs_smudge (repository_ctx , srcs ):
1+ def lfs_smudge (repository_ctx , srcs , extract = False , stripPrefix = None ):
22 for src in srcs :
33 repository_ctx .watch (src )
44 script = Label ("//misc/bazel/internal:git_lfs_probe.py" )
@@ -10,19 +10,28 @@ def lfs_smudge(repository_ctx, srcs):
1010 fail ("git LFS probing failed while instantiating @%s:\n %s" % (repository_ctx .name , res .stderr ))
1111 for src , loc in zip (srcs , res .stdout .splitlines ()):
1212 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 )
1417 else :
1518 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 )
1728
1829def _download_and_extract_lfs (repository_ctx ):
1930 attr = repository_ctx .attr
2031 src = repository_ctx .path (attr .src )
2132 if attr .build_file_content and attr .build_file :
2233 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 )
2635 if attr .build_file_content :
2736 repository_ctx .file ("BUILD.bazel" , attr .build_file_content )
2837 elif attr .build_file :
0 commit comments