How to select external repo definition based on the build parameter?

36 views
Skip to first unread message

Konstantin

unread,
May 9, 2023, 6:11:36 PMMay 9
to bazel-discuss

In my workspace file I have external repository defined like this:

http_archive(
    name = "external_repo",
    urs = “…”,
)

Now I am looking for a way to pick one out of multiple definitions for "external_repo" bazed on some command line parameter or otherwise controllable by the build invoker.

Any ideas?

Thank you!

Konstantin

Konstantin

unread,
May 9, 2023, 8:37:29 PMMay 9
to bazel-discuss

To give a little more context what we really need is to replace http_archive with the local folder with pre-expanded data. –override-repository almost cuts it, but unfortunately it does not know to place BUILD and WORKSPACE files in that folder. So what we need is –override-repository with new_local_repository functionality.

David Turner

unread,
May 11, 2023, 5:54:38 AMMay 11
to Konstantin, bazel-discuss
There is no way to do that as far as I know.

What we do for our project (which has tons of conditional definitions like these) is to generate the WORKSPACE.bazel file from a template, and use a wrapper script for bazel, that can re-generate it when needed. This works because we do not rely on .bazelrc to store and manage our build configuration settings (that file is also auto-generated for us :-))

In your case, a simpler alternative would be to use --override-repository to point to a custom directory that contains a BUILD and WORKSPACE file, plus symlinks to the real external pre-expanded directory content.
 

--
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/cb0ddeb6-620e-4aa3-813b-b0a0330493bcn%40googlegroups.com.

Gregg Reynolds

unread,
May 11, 2023, 8:22:53 AMMay 11
to Konstantin, bazel-discuss
Sounds like a job for a custom repository rule.  I've done this before; it's not very hard. See `workspace_and_buildfile(ctx)` in https://github.com/bazelbuild/bazel/blob/master/tools/build_defs/repo/utils.bzl. Use a function to parameterize and call the repo rule. You could probably parameterize it by an env variable.




--
Reply all
Reply to author
Forward
0 new messages