Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move the Java tools deploy jars refrences to checked-in deploy jars #7114

Closed
wants to merge 8 commits into from

Conversation

iirina
Copy link
Contributor

@iirina iirina commented Jan 14, 2019

instead of embedding the deploy jars built at the same time with the bazel binary.

This comes in preparation for moving the Java tools to remote repositories (see #6316).

Moving the tools happens in two phases:

  1. Using checked-in deploy jars/binaries instead of those built when bazel was built
  2. Moving the checked-in jars/binaries to a remote repository and make bazel reference them from there. This step can only happen under an incompatible flag.

This PR addresses the first point. Doing the move incrementally this way is safer and allows finding bugs earlier. It also allows moving the Java tools code base out of the bazel repository.

We are making this change gradually for each java tool defined in JAVA_TOOLS (found in src/BUILD).

@iirina iirina added team-Rules-Java Issues for Java rules WIP labels Jan 14, 2019
@iirina
Copy link
Contributor Author

iirina commented Jan 14, 2019

@lberki PTAL. If/when this looks OK to you I'll do the same for the other deploy jars in JAVA_TOOLS.

@iirina iirina requested a review from lberki January 14, 2019 15:12
src/BUILD Outdated Show resolved Hide resolved
third_party/java/java_tools/README.md Outdated Show resolved Hide resolved
@iirina iirina requested a review from a team as a code owner January 15, 2019 11:39
@iirina iirina removed the WIP label Jan 15, 2019
@iirina iirina changed the title Move JavaBuilder refrence to a checked-in deploy jar Move the Java tools deploy jars refrences to checked-in deploy jars Jan 15, 2019
@iirina
Copy link
Contributor Author

iirina commented Jan 15, 2019

@lberki I updated all the deploy jars defined in src/BUILD in the embedded_tools filegroup (defined by JAVA_TOOLS). The remaining targets in JAVA_TOOLS require a bit more work and I'll do take care of them separately in new PRs.

@iirina
Copy link
Contributor Author

iirina commented Jan 15, 2019

@lberki This PR is ready for review now, PTAL! Thanks!

third_party/BUILD Outdated Show resolved Hide resolved
name = "java_tools",
srcs = glob(
["java/java_tools/*.jar"],
exclude = ["java/java_tools/SingleJar_deploy.jar"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change will need to be split (to a Git-on-Borg and a Google internal part). (But it's easier to review in one piece!)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does it need to be split?

third_party/java/java_tools/update_java_tools.sh Outdated Show resolved Hide resolved
@@ -0,0 +1,83 @@
#!/bin/bash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: how about adding -eu: -e makes the shell exit early if a command returns a non-zero exit code and -u makes using undeclared variables an error (one less opportunity for typos!)

If you want to be fancy, you can also add -x that makes bash print every command it executes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't add any of those because:

  • -e because I still want to update some of the tools even if the others didn't build. I find it easier to debug if we keep the errors and print them at the end

  • -u because I get an error of $1 not being declared when I check if it equals "help", even though I do this check only after checking that $1 is not empty

  • x because bazel already pollutes the output a lot, by looking at it is more than enough

Let me know if you think otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a second thought, I added -e. It can be more helpful to exit at the first error and not scroll through the whole log. 😆

third_party/java/java_tools/update_java_tools.sh Outdated Show resolved Hide resolved
local bazel_target="${1}"; shift
local binary=$(echo "bazel-bin/$bazel_target" | sed 's@:@/@')

bazel build "$bazel_target"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: how about issuing a single Bazel invocation that builds every tool? It's presumably faster.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each invocation is ~0.1s, do we need to speed it up? This script is meant to be run manually and anything under a few seconds is the same IMO. Having them separately allows printing more useful error messages and following all the logic for one build in the same place.

third_party/java/java_tools/update_java_tools.sh Outdated Show resolved Hide resolved

}

for tool in "${tools_to_update[@]}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opt: bash associative arrays are scary. How about simply

function process() {
  bazel build $2
  cp ... ...
}

process SingleJar src/java_tools/singlejar/java/com/google/devtools/build/singlejar:bazel-singlejar_deploy.jar
process GenClass rc/java_tools/buildjar/java/com/google/devtools/build/buildjar/genclass:GenClass_deploy.jar

More repetitive, but also more readable for mere mortals.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, this is exactly the way I started the script! However, it ended up having too much repetition especially because I wanted to be able to print the usage. Doing it this way requires repetition 3 times, and every time one of the targets or tool name changes we have to update the other 2 as well. I updated the documentation, does it make it more readable? I really want to avoid copying all these strings everywhere.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be OK with slightly worse usage text if it makes the script simpler.

@@ -115,43 +115,47 @@ py_binary(
deps = [":create_embedded_tools_lib"],
)

# The tools Bazel uses to compile Java.
# TODO(iirina): Gradually remove the targets here.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer TODO(<bug>)


}

for tool in "${tools_to_update[@]}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be OK with slightly worse usage text if it makes the script simpler.

To see how to update the tools run:

```
./third_party/java/java_tools/update_java_tools.sh help
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When do we expect this script to be run? i.e. as part of the release process, or on-demand, or something else?

@bazel-io bazel-io closed this in f4604ba Jan 16, 2019
weixiao-huang pushed a commit to weixiao-huang/bazel that referenced this pull request Jan 31, 2019
instead of embedding the deploy jars built at the same time with the bazel binary.

This comes in preparation for moving the Java tools to remote repositories (see bazelbuild#6316).

Moving the tools happens in two phases:
1. Using checked-in deploy jars/binaries instead of those built when bazel was built
2. Moving the checked-in jars/binaries to a remote repository and make bazel reference them from there. This step can only happen under an incompatible flag.

This PR addresses the first point. Doing the move incrementally this way is safer and allows finding bugs earlier. It also allows moving the Java tools code base out of the bazel repository.

We are making this change gradually for each java tool defined in JAVA_TOOLS (found in src/BUILD).

Closes bazelbuild#7114.

PiperOrigin-RevId: 229524951
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes team-Rules-Java Issues for Java rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants