1313# limitations under the License.
1414
1515def _http_archive_impl (ctx ):
16+ overlay = _resolve_overlay (ctx , ctx .attr .overlay )
1617 ctx .download_and_extract (
1718 url = ctx .attr .urls ,
1819 sha256 = ctx .attr .sha256 ,
1920 type = ctx .attr .type ,
2021 stripPrefix = ctx .attr .strip_prefix ,
2122 )
22-
23- _apply_overlay (ctx , ctx .attr .overlay )
23+ _apply_overlay (ctx , overlay )
2424
2525http_archive = repository_rule (
2626 implementation = _http_archive_impl ,
@@ -43,12 +43,14 @@ def _git_repository_impl(ctx):
4343 if ctx .attr .commit and ctx .attr .tag :
4444 fail ("'commit' and 'tag' may not both be specified" )
4545
46+ overlay = _resolve_overlay (ctx , ctx .attr .overlay )
47+
4648 # TODO(jayconrod): sanitize inputs passed to git.
4749 revision = ctx .attr .commit if ctx .attr .commit else ctx .attr .tag
4850 _check_execute (ctx , ["git" , "clone" , "-n" , ctx .attr .remote , "." ], "failed to clone %s" % ctx .attr .remote )
4951 _check_execute (ctx , ["git" , "checkout" , revision ], "failed to checkout revision %s in remote %s" % (revision , ctx .attr .remote ))
5052
51- _apply_overlay (ctx , ctx . attr . overlay )
53+ _apply_overlay (ctx , overlay )
5254
5355git_repository = repository_rule (
5456 implementation = _git_repository_impl ,
@@ -60,11 +62,23 @@ git_repository = repository_rule(
6062 },
6163)
6264
65+ def _resolve_overlay (ctx , overlay ):
66+ """Resolve overlay labels to paths.
67+
68+ This should be done before downloading the repository, since it may
69+ trigger restarts.
70+ """
71+ return [(ctx .path (src_label ), dst_rel ) for src_label , dst_rel in overlay .items ()]
72+
6373def _apply_overlay (ctx , overlay ):
74+ """Copies overlay files into the repository.
75+
76+ This should be done after downloading the repository, since it may replace
77+ downloaded files.
78+ """
6479 # TODO(jayconrod): sanitize destination paths.
65- for src_label , dst_rel in overlay .items ():
66- src_path = ctx .path (src_label )
67- _check_execute (ctx , ["cp" , src_path , dst_rel ], "failed to copy file from %s" % src_label )
80+ for src_path , dst_rel in overlay :
81+ _check_execute (ctx , ["cp" , src_path , dst_rel ], "failed to copy file from %s" % src_path )
6882
6983def _check_execute (ctx , arguments , message ):
7084 res = ctx .execute (arguments )
0 commit comments