-
Notifications
You must be signed in to change notification settings - Fork 19
Bazel deps helper scripts #19
Bazel deps helper scripts #19
Conversation
…maven_deps.yaml. These scripts handle: - checking out and updating bazel-deps - running the buildifier on the generated BUILD files - making any manual edits to the generated files via buildozer rules - a check to ensure the generated files are in sync with the yaml
Can one of the admins verify this patch? |
@greggdonovan can you add a line checking if buildifier is installed (and installing it otherwise)? I ran into this issue when running |
@petroseskinder Good idea, thanks. I should do the same with I'll update the PR. |
ok to test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
I hope that we can one day drop these scripts and upstream all of its goodies :)
@@ -43,3 +43,5 @@ hs_err_pid* | |||
|
|||
# Ignore mac attributes files | |||
*.DS_STORE | |||
# Ignore bazel-deps resolverCache. See: https://github.com/johnynek/bazel-deps#options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you have experience with bazel_output_base
from that link?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use bazel_output_base
internally. @kevingessner added it here. I like it and I think it fits in with Bazel conventions nicely (e.g. removed with bazel clean --expunge
). I can switch it in the PR if you like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mmm... actually let's leave it like that, in case it turns out that it's useful to only have Bazel stuff in bazel-out
.
# shellcheck disable=SC1090 | ||
. "$SCRIPT_DIR/setup.sh" | ||
|
||
"${BAZEL_DEPS_DIR}/gen_maven_deps.sh" add-dep --deps "${ROOT_DIR}/maven_deps.yaml" --lang "$lang" "${coords[@]}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wat. It already supports consuming maven dependencies?
I gather the reason for using this script instead of calling bazel-deps directly is because it formats and handles AutoValue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Plus making sure you have a checked out version bazel-deps.
+1 to the goal of removing the scripts and using bazel-deps via a WORKSPACE
rule of some sort.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gen_maven_deps.sh
comes with bazel-deps and supports converting maven coords into dependencies.yaml. This wrapper script makes sure that bazel-deps is installed (setup.sh), updates dependencies.yaml, and then generates the new third_party code. It makes dep additions and updates a one-step process instead of 2 or 3. Switching to a workspace rule would take care of the first, but I still think it's a good workflow to have changing dependencies.yaml and regenerating the thrid_party files be a single command; maybe we could add that to bazel-deps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, sounds reasonable to ask bazel-deps to also regenerate the BUILD files.
then | ||
echo | ||
echo "* * *" | ||
echo "Generated dependency files are not up to date. Run \`dev-scripts/dependencies/generate.sh\` and commit the changes." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this something that you found useful in general with bazel-deps
?
If so, let's open an Issue in bazel-deps
and see what Oscar thinks.
If he's open to the idea, let's put a # TODO here to delete the file once the upstream issue is resolved?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, its occasionally useful. We have check-deps.sh
run in our CI so that someone doesn't update maven_deps.yaml
without running the generation step and checking in the thirdparty
BUILD files. It's saved us a couple of times so far.
Are you thinking something like "${BAZEL_DEPS_DIR}/gen_maven_deps.sh check -r ${SCRIPT_DIR} -s thirdparty/workspace.bzl -d maven_deps.yaml
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, something like that.
dev-scripts/dependencies/setup.sh
Outdated
buildozer 'add deps //external:jar/com/google/auto/value/auto_value' //thirdparty/jvm/com/google/auto/value:auto_value_plugin | ||
|
||
# The generated BUILD files are not well-formatted. Run the buildifier on them. | ||
find "${ROOT_DIR}/thirdparty/jvm" -name "BUILD" -exec "buildifier" -showlog -mode=fix {} + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a
# TODO(https://github.com/johnynek/bazel-deps/issues/73): Drop once issue is fixed.
dev-scripts/dependencies/setup.sh
Outdated
|
||
"$BAZEL_DEPS_DIR/gen_maven_deps.sh" generate --repo-root "$ROOT_DIR" --sha-file "thirdparty/workspace.bzl" --deps maven_deps.yaml | ||
|
||
# Manually add the AutoValue plugin. Otherwise, everything can be auto-generated from the YAML. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a
# TODO(https://github.com/johnynek/bazel-deps/issues/62): Drop once issue is fixed.
|
||
SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) | ||
ROOT_DIR=$(cd "${SCRIPT_DIR}/../.." && pwd) | ||
BAZEL_DEPS_DIR="$ROOT_DIR/../bazel-deps" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that'll land the new repo outside of the current tree?
feels awkward, though landing it inside the tree is also awkward. So I don't know :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Managing external repos outside of bazel feels really awkward. I don't have a great solution.
Do you or @kevingessner or @johnynek have a link to the issue or issues preventing us from using bazel-deps
as a repository rule? It'd be nice to track them. I see bazel #1673 but perhaps there's more to it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#1673 is the only one I know of. Even if it's in the workspace, it'll be a little bit of wrangling to get it running correctly -- IIRC bazel-deps comes with the gen_maven_deps.sh
wrapper script because it doesn't work with bazel run
. So we'll need to get the various paths right. Doable but may be a little tricky.
@@ -1,4 +1,16 @@ | |||
def maven_dependencies(callback): | |||
def declare_maven(hash): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you delete load.bzl and the reference to it in WORKSPACE, now that it's not needed anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Updated the PR.
Re: The Are we better off exiting with the proper instructions for installing them or better off doing something like: The |
I filed bazelbuild/bazel#3895 after chatting with @damienmg . There's a tentative agreement, but I'm told it's low priority. BFG uses Buildozer to create the BUILD files, so it's actually a prerequisite. I'll update So, I think it's ok to exit with instructions (pointing at README.md should be fine) |
We can drop our workaround when annotation processor support and buildifier formatting are integrated into bazel-deps.
…o is not installed. TODO: Remove this once bazelbuild/bazel#3895 is resolved and we can provide a better method for installing these tools.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's awesome, thanks!
Feel free to merge (you should have Write permissions). |
Ah, I ran into some trouble with |
@cgrushko That's a good point -- I'll update in a PR. I can also add in removals of the workaround to bazel-deps#73 and bazel-deps#85. I should be back to the meat of the Scala work this week, too. Sorry -- had to finish up some other work. |
I'm hoping to work on bazelbuild/bazel#1673 this week, which should make setup.sh unnecessary. I'll let you know if I can make progress! |
@cgrushko Cloning How about |
Add scripts to auto-generate the thirdparty/jvm BUILD files from the maven_deps.yaml.
These scripts handle:
The PR also runs these scripts to regenerate the thirdparty/jvm files that have been buildifier formatted.
This allows us to more easily add new dependencies to maven_deps.yaml. For example, for Scala support.