How to handle re-mapping part of an http_archive repo?

326 views
Skip to first unread message

Tom Rybka

unread,
Jan 27, 2020, 1:43:16 PM1/27/20
to bazel-discuss
What would be the "canonical" way to re-map part (or all) of an http_archive?

Let's say I have some set of tools that is needed by one of my other deps.
However that dep expects the tool to have a particular directory structure that does not quite match the canonical distribution zipfile structure.

How can I "re-map" part (or all) of one of those archives to match the expected structure?

In some sense, this is an inverse of strip_prefix.

I can think of multiple ways I *could* handle this:
  • Fileset
  • cp
  • symlink
But I'm curious if there is consensus on how it *should* be done.

Jingwen Chen

unread,
Jan 28, 2020, 1:40:06 AM1/28/20
to Tom Rybka, bazel-discuss
Have you considered repackaging the http_archive files (e.g. a total filegroup) with rules_pkg? remap_paths for pkg_tar and package_dir for pkg_zip may be sufficient for your needs. 


--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/a8a53eae-60f4-4ea0-8051-c33172802dc0%40googlegroups.com.

Thomas Rybka

unread,
Jan 28, 2020, 2:38:13 PM1/28/20
to Jingwen Chen, bazel-discuss
What is the advantage of that vs. a genrule that copies things into place? 
Thomas Rybka | Software Engineer | try...@google.com | Portable C++ Tools

Brian Silverman

unread,
Jan 29, 2020, 1:40:01 PM1/29/20
to Thomas Rybka, Jingwen Chen, bazel-discuss
I've done this before with a custom repository rule. In my case, I could do that I needed with just repository_ctx.delete('somewhere') and repository_ctx.extract(stripPrefix='foo', output='somewhere').

I also needed to extract files from multiple archives in different patterns depending on the architecture, so it had to be a repository rule independent of remapping files. A two-step approach (like Jingwen suggested) making a remapped archive while adding the dependency, and then using the result of that for builds would be my preference in most other situations.

Reply all
Reply to author
Forward
0 new messages