Skip to content

Commit

Permalink
Refactor build for JDK 7
Browse files Browse the repository at this point in the history
Now the JDK 7 tuning happens all in Bazel, removing logic
from the CI script. It uses remote repositories to access
JDK 7 dependencies.

--
Change-Id: Iff590c6642ca5b2343aa15096f8fd837d1c80787
Reviewed-on: https://bazel-review.googlesource.com/#/c/3327
MOS_MIGRATED_REVID=119634530
  • Loading branch information
damienmg authored and lberki committed Apr 13, 2016
1 parent 75250e6 commit 6cb8d82
Show file tree
Hide file tree
Showing 9 changed files with 217 additions and 137 deletions.
16 changes: 16 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ bind(
actual = "//:dummy",
)

# For building for JDK 7
# This is a JDK 7 JavaBuilder from release 0.1.0.
# Do not use the skylark bootstrapped version of JavaBuilder
http_file(
name = "io_bazel_javabuilder_jdk7",
# This was built from Bazel 0.1.0 (after ./compile.sh) and JDK 7.
url = "https://storage.googleapis.com/bazel/0.1.0/JavaBuilder_deploy.jar",
sha256 = "374f07be2f73ec170ef6bdd8057530e6842cb0cbc7a240caccbd7b80be239366",
)

http_file(
name = "io_bazel_javac_jdk7",
url = "https://github.com/bazelbuild/bazel/blob/0.1.0/third_party/java/jdk/langtools/javac.jar?raw=true",
sha256 = "e063cf60cf9a1d24acd043f55dc605da559b913793c6a4e51c5ddbc4f5d494df",
)

# For tools/cpp/test/...
load("//tools/cpp/test:docker_repository.bzl", "docker_repository")
docker_repository()
Expand Down
5 changes: 2 additions & 3 deletions compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ if [ $DO_COMPILE ]; then
new_step 'Building Bazel with Bazel'
display "."
log "Building output/bazel"
bazel_build "src:bazel${EXE_EXT}"
cp -f "bazel-bin/src/bazel${EXE_EXT}" "output/bazel${EXE_EXT}"
bazel_build "src:bazel${BAZEL_FLAVOUR}${EXE_EXT}"
cp -f "bazel-bin/src/bazel${BAZEL_FLAVOUR}${EXE_EXT}" "output/bazel${EXE_EXT}"
chmod 0755 "output/bazel${EXE_EXT}"
BAZEL="$(pwd)/output/bazel${EXE_EXT}"
fi
Expand Down Expand Up @@ -155,7 +155,6 @@ if [ $DO_TESTS ]; then
$BAZEL --bazelrc=${BAZELRC} --nomaster_bazelrc test \
--test_tag_filters="${BAZEL_TEST_FILTERS-}" \
--build_tests_only \
--nolegacy_bazel_java_test \
${EXTRA_BAZEL_ARGS} \
--javacopt="-source ${JAVA_VERSION} -target ${JAVA_VERSION}" \
-k --test_output=errors //src/... //third_party/ijar/... //scripts/... \
Expand Down
32 changes: 21 additions & 11 deletions scripts/bootstrap/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,33 @@ if [ -n "${EMBED_LABEL}" ]; then
EMBED_LABEL_ARG=(--stamp --embed_label "${EMBED_LABEL}")
fi

: ${JAVA_VERSION:="1.8"}

: ${BAZEL_ARGS:=--singlejar_top=//src/java_tools/singlejar:bootstrap_deploy.jar \
--javabuilder_top=//src/java_tools/buildjar:bootstrap_deploy.jar \
--genclass_top=//src/java_tools/buildjar:bootstrap_genclass_deploy.jar \
--ijar_top=//third_party/ijar \
COMMON_BAZEL_ARGS="--singlejar_top=//src/java_tools/singlejar:bootstrap_deploy.jar \
--genclass_top=//src/java_tools/buildjar:bootstrap_genclass_deploy.jar \
--ijar_top=//third_party/ijar"
if [[ "${JAVA_VERSION-}" == 1.7 ]]; then
# Set the various arguments when JDK 7 is required (deprecated).
# This setting is here to continue to build binary release of Bazel
# for JDK 7. We will drop this method and JDK 7 support when our
# ci system turn red on this one.
: ${BAZEL_ARGS:=--java_toolchain=//tools/jdk:toolchain7 \
--javabuilder_top=@io_bazel_javabuilder_jdk7//file \
--java_langtools=@io_bazel_javac_jdk7//file \
${COMMON_BAZEL_ARGS} \
"${EXTRA_BAZEL_ARGS:-}"}
: ${BAZEL_FLAVOUR:="-jdk7"}
else
: ${BAZEL_ARGS:=--javabuilder_top=//src/java_tools/buildjar:bootstrap_deploy.jar \
--strategy=Javac=worker --worker_quit_after_build \
--genrule_strategy=standalone --spawn_strategy=standalone \
${COMMON_BAZEL_ARGS} \
"${EXTRA_BAZEL_ARGS:-}"}
: ${BAZEL_FLAVOUR:=""}
fi

if [ -z "${BAZEL-}" ]; then
function bazel_build() {
bootstrap_build ${BAZEL_ARGS-} \
--verbose_failures \
--javacopt="-source ${JAVA_VERSION} -target ${JAVA_VERSION}" \
"${EMBED_LABEL_ARG[@]}" \
"${@}"
}
Expand All @@ -51,7 +63,6 @@ else
${BAZEL} --bazelrc=${BAZELRC} build \
${BAZEL_ARGS-} \
--verbose_failures \
--javacopt="-source ${JAVA_VERSION} -target ${JAVA_VERSION}" \
"${EMBED_LABEL_ARG[@]}" \
"${@}"
}
Expand All @@ -77,23 +88,22 @@ function get_outputs_sum() {
function bootstrap_test() {
local BAZEL_BIN=$1
local BAZEL_SUM=$2
local BAZEL_TARGET=${3:-src:bazel}
local BAZEL_TARGET=${3:-src:bazel${BAZEL_FLAVOUR}}
[ -x "${BAZEL_BIN}" ] || fail "syntax: bootstrap bazel-binary"
run ${BAZEL_BIN} --nomaster_bazelrc --bazelrc=${BAZELRC} clean \
--expunge || return $?
run ${BAZEL_BIN} --nomaster_bazelrc --bazelrc=${BAZELRC} build \
${EXTRA_BAZEL_ARGS-} \
--strategy=Javac=worker --worker_quit_after_build \
--fetch --nostamp \
--javacopt="-source ${JAVA_VERSION} -target ${JAVA_VERSION}" \
${BAZEL_TARGET} || return $?
if [ -n "${BAZEL_SUM}" ]; then
cat bazel-genfiles/src/java.version >${BAZEL_SUM}
get_outputs_sum >> ${BAZEL_SUM} || return $?
fi
if [ -z "${BOOTSTRAP:-}" ]; then
tempdir
BOOTSTRAP=${NEW_TMPDIR}/bazel
BOOTSTRAP=${NEW_TMPDIR}/bazel${BAZEL_FLAVOUR}
local FILE=bazel-bin/${BAZEL_TARGET##//}
cp -f ${FILE/:/\/} $BOOTSTRAP
chmod +x $BOOTSTRAP
Expand Down
2 changes: 1 addition & 1 deletion scripts/bootstrap/compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# Script for building bazel from scratch without bazel

PROTO_FILES=$(ls src/main/protobuf/*.proto)
LIBRARY_JARS=$(find third_party -name '*.jar' | tr "\n" " ")
LIBRARY_JARS=$(find third_party -name '*.jar' | grep -v "javac.jar" | tr "\n" " ")
DIRS=$(echo src/{java_tools/singlejar/java/com/google/devtools/build/zip,main/java,tools/xcode-common/java/com/google/devtools/build/xcode/{common,util}} ${OUTPUT_DIR}/src)
EXCLUDE_FILES=src/main/java/com/google/devtools/build/lib/server/GrpcServer.java

Expand Down
49 changes: 6 additions & 43 deletions scripts/ci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,45 +98,6 @@ EOF
fi
}

# Set the various arguments when JDK 7 is required (deprecated).
# This method is here to continue to build binary release of Bazel
# for JDK 7. We will drop this method and JDK 7 support when our
# ci system turn red on this one.
function setup_jdk7() {
# This is a JDK 7 JavaBuilder from release 0.1.0.
local javabuilder_url="https://storage.googleapis.com/bazel/0.1.0/JavaBuilder_deploy.jar"
local javac_url="https://github.com/bazelbuild/bazel/blob/0.1.0/third_party/java/jdk/langtools/javac.jar?raw=true"
sed -i.bak 's/_version = "8"/_version = "7"/' tools/jdk/BUILD
rm -f tools/jdk/BUILD.bak
rm -f third_party/java/jdk/langtools/javac.jar
curl -Ls -o tools/jdk/JavaBuilder_deploy.jar "${javabuilder_url}"
curl -Ls -o third_party/java/jdk/langtools/javac.jar "${javac_url}"
# Do not use the skylark bootstrapped version of JavaBuilder
export BAZEL_ARGS="--singlejar_top=//src/java_tools/singlejar:bootstrap_deploy.jar \
--genclass_top=//src/java_tools/buildjar:bootstrap_genclass_deploy.jar \
--ijar_top=//third_party/ijar"
# Skip building JavaBuilder
export BAZEL_SKIP_TOOL_COMPILATION=tools/jdk/JavaBuilder_deploy.jar
# Ignore JDK8 tests
export BAZEL_TEST_FILTERS="-jdk8"
if ! grep -Fq 'RealJavaBuilder' src/java_tools/buildjar/BUILD; then
# And more ugly hack. Overwrite the BUILD file of JavaBuilder
# so we use the pre-built version in integration tests.
sed -i.bak 's/name = \"JavaBuilder\"/name = \"RealJavaBuilder\"/' \
src/java_tools/buildjar/BUILD
rm -f src/java_tools/buildjar/BUILD.bak
cat >>src/java_tools/buildjar/BUILD <<'EOF'
genrule(
name = "JavaBuilder",
outs = ["JavaBuilder_deploy.jar"],
srcs = ["//tools/jdk:JavaBuilder_deploy.jar"],
cmd = "cp $< $@",
visibility = ["//visibility:public"],
)
EOF
fi
}

# Main entry point for building bazel.
# It sets the embed label to the release name if any, calls the whole
# test suite, compile the various packages, then copy the artifacts
Expand All @@ -151,9 +112,10 @@ function bazel_build() {

if [[ "${JAVA_VERSION-}" =~ ^(1\.)?7$ ]]; then
JAVA_VERSION=1.7
setup_jdk7
FLAVOUR="-jdk7"
release_label="${release_label}-jdk7"
else
FLAVOUR=""
JAVA_VERSION=1.8
fi

Expand All @@ -177,15 +139,16 @@ function bazel_build() {
--workspace_status_command=scripts/ci/build_status_command.sh \
--define JAVA_VERSION=${JAVA_VERSION} \
${ARGS} \
//scripts/packages/... || exit $?
//scripts/packages:install${FLAVOUR}.sh \
//scripts/bazel-debian${FLAVOUR}.deb} || exit $?

if [ -n "${1-}" ]; then
# Copy the results to the output directory
mkdir -p $1/packages
cp output/bazel $1/bazel
cp bazel-bin/scripts/packages/install.sh $1/bazel-${release_label}-installer.sh
cp bazel-bin/scripts/packages/install${FLAVOUR}.sh $1/bazel-${release_label}-installer.sh
if [ "$PLATFORM" = "linux" ]; then
cp bazel-bin/scripts/packages/bazel-debian.deb $1/bazel_${release_label}.deb
cp bazel-bin/scripts/packages/bazel-debian${FLAVOUR}.deb $1/bazel_${release_label}.deb
fi
cp bazel-genfiles/scripts/packages/README.md $1/README.md
fi
Expand Down
Loading

0 comments on commit 6cb8d82

Please sign in to comment.