How to integrate bazel-deps with bazel?

235 views
Skip to first unread message

tony....@rubrik.com

unread,
Dec 7, 2017, 10:13:03 PM12/7/17
to bazel-discuss
So I'm migrating a relatively sizable maven build over to bazel and we are using bazel-deps to manage our maven dependencies.
Currently, we need to run a script to generate all of the 3rdparty BUILD files and the workspace.bzl file before being able to run bazel.
However, the step is a little clunky in our developer workflow. Is it possible to have bazel to automatically run this script before initialization?
Perhaps as a pre-initialization step, or as a part of the build. I'm not sure it's kosher to have bazel generate BUILD files.

We thought about writing a wrapper script around bazel to run the bazel-deps script before running the actual bazel command, but we wanted to know if there was a better way to use this tool.

Thanks!
Tony

László Csomor

unread,
Dec 8, 2017, 4:40:35 AM12/8/17
to tony....@rubrik.com, bazel-discuss
Hi Tony,

I'd also recommend the wrapper script approach. In fact, if you're on Linux, you already are using a wrapper script.

Cheers,
Laszlo



--
László Csomor | Software Engineer | laszlo...@google.com

Google Germany GmbH | Erika-Mann-Str. 33 | 80636 München | Germany
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Geschäftsführer: Paul Manicle, Halimah DeLaine Prado

--
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-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/0c840fff-3d5c-4fd8-adcb-48993c0c1967%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

itt...@wix.com

unread,
Dec 16, 2017, 12:16:43 AM12/16/17
to bazel-discuss
Responding late but I'd just mention that it's worth checking the performance impacts of running bazel-deps in the wrapper (i.e. for every bazel command) since I'm not sure it's that cheap
On Friday, December 8, 2017 at 11:40:35 AM UTC+2, László Csomor wrote:
> Hi Tony,
>
>
> I'd also recommend the wrapper script approach. In fact, if you're on Linux, you already are using a wrapper script.
> See https://stackoverflow.com/questions/47678041/user-name-in-bazelrc/47692113#47692113
>
>
> Cheers,
> Laszlo
>
>
>
>
>
>
>
> --
> László Csomor | Software Engineer | laszlo...@google.com
>
> Google Germany GmbH | Erika-Mann-Str. 33 | 80636 München | Germany
> Registergericht und -nummer: Hamburg, HRB 86891
> Sitz der Gesellschaft: Hamburg
> Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
>
>
> On Fri, Dec 8, 2017 at 4:13 AM, <tony....@rubrik.com> wrote:
>
>
> So I'm migrating a relatively sizable maven build over to bazel and we are using bazel-deps to manage our maven dependencies.
> Currently, we need to run a script to generate all of the 3rdparty BUILD files and the workspace.bzl file before being able to run bazel.
> However, the step is a little clunky in our developer workflow. Is it possible to have bazel to automatically run this script before initialization?
>
> Perhaps as a pre-initialization step, or as a part of the build. I'm not sure it's kosher to have bazel generate BUILD files.
>
>
> We thought about writing a wrapper script around bazel to run the bazel-deps script before running the actual bazel command, but we wanted to know if there was a better way to use this tool.
>
>
> Thanks!
> Tony
>
>
>
>
>
> --
>
> 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.

tony....@rubrik.com

unread,
Dec 19, 2017, 2:43:17 PM12/19/17
to bazel-discuss
Thanks for the feedback!
The solution we went with was to write a wrapper at tools/bazel that would run the bazel-deps script.
The initial invocation of bazel-deps takes a few minutes.
Subsequent runs (with no changes to dependencies.yml) add about 5s to the build.
If the additional time becomes unbearable, we might check the hash of the dependencies.yml file.

Jingwen Chen

unread,
Dec 19, 2017, 2:50:03 PM12/19/17
to tony....@rubrik.com, bazel-discuss
That script sounds like it'll be useful to many. Is it possible to share that here?

Ittai Zeidman

unread,
Dec 19, 2017, 2:51:23 PM12/19/17
to Jingwen Chen, tony....@rubrik.com, bazel-discuss
How often do you change your dependencies.yml?

You received this message because you are subscribed to a topic in the Google Groups "bazel-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/bazel-discuss/SwCd5MVB6jY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/CAMpM06Drgwz6thB%3DATvvSOaeCFO%3DdwRQRxkaJ7ORKrwD-vtK8w%40mail.gmail.com.

tony....@rubrik.com

unread,
Dec 19, 2017, 3:26:37 PM12/19/17
to bazel-discuss
@Ittai right now, we're seeing approximately 1 change to the dependencies per week.
@Jingwen the script is pretty simple, we use the fact that the installed bazel binary looks for a wrapper in tools/bazel and calls exec

This is the general structure of our bazel wrapper that we have.
#!/bin/bash

set -eu

# Run whatever necessary setup functions you need here before bazel is executed.

if [[ ! -x "${BAZEL_REAL}" ]]; then
    echo "Failed to find underlying Bazel executable at ${BAZEL_REAL}" >&2
    exit 1
fi

exec -a "$0" "${BAZEL_REAL}" "$@"



Reply all
Reply to author
Forward
0 new messages