Reorganized compile.sh Now the blessed Bazel binary is self-hosted and correctly labeled. All tools are also built using Bazel and labeled with the release. At the end of the compilation, the output folder only host the Bazel binary now. We use temporary folders to store the intermediate artifacts. Also integrated ./bootstrap_test.sh in compile.sh so there is only one script for everything regarding bootstraping Bazel. -- Change-Id: Idadbd075e7b8ecb6e306b919b7a73c647c5cfbae Reviewed-on: https://bazel-review.googlesource.com/#/c/1460/ MOS_MIGRATED_REVID=95625880
diff --git a/.travis/build.sh b/.travis/build.sh index a3f2173..9a650ae 100755 --- a/.travis/build.sh +++ b/.travis/build.sh
@@ -29,5 +29,5 @@ sudo update-alternatives --set nc /bin/nc.traditional export JAVA_HOME=/usr/lib/jvm/java-8-oracle export JAVA_OPTS="-Xmx3000m" - ./bootstrap_test.sh all + ./compile.sh all fi
diff --git a/.travis/prepare-for-deploy.sh b/.travis/prepare-for-deploy.sh index 15b259a..104b257 100755 --- a/.travis/prepare-for-deploy.sh +++ b/.travis/prepare-for-deploy.sh
@@ -26,7 +26,7 @@ local bazel_dir bazel_dir=bazel-$git_hash mkdir $bazel_dir - cp bazel-bin/src/bazel $bazel_dir + cp output/bazel $bazel_dir sha256sum $bazel_dir/bazel > $bazel_dir/sha256.txt cat > $bazel_dir/README.md <<EOF Bazel binary built by Travis CI
diff --git a/bootstrap_test.sh b/bootstrap_test.sh deleted file mode 100755 index 9688652..0000000 --- a/bootstrap_test.sh +++ /dev/null
@@ -1,146 +0,0 @@ -#! /bin/bash - -# Copyright 2014 Google Inc. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -set -eu - -BAZELRC=${BAZELRC:-/dev/null} - -function usage() { - [ -n "${1:-}" ] && echo "Invalid command(s): $1" >&2 - echo "syntax: $0 command[,command]* [BAZEL_BIN [BAZEL_SUM]]" >&2 - echo " Available commands: bootstrap, determinism, test, all" >&2 - exit 1 -} - -function parse_options() { - local keywords="(bootstrap|test|determinism|all)" - [[ "${1:-}" =~ ^$keywords(,$keywords)*$ ]] || usage "$@" - DO_BOOTSTRAP= - DO_CHECKSUM= - DO_TESTS= - [[ "$1" =~ (bootstrap|all) ]] && DO_BOOTSTRAP=1 - [[ "$1" =~ (determinism|all) ]] && DO_CHECKSUM=1 - [[ "$1" =~ (test|all) ]] && DO_TESTS=1 - - BAZEL_BIN=${2:-"bazel-bin/src/bazel"} - BAZEL_SUM=${3:-"bazel-out/bazel_checksum"} -} - -PLATFORM="$(uname -s | tr 'A-Z' 'a-z')" -if [[ ${PLATFORM} == "darwin" ]]; then - function md5_file() { - echo $(cat $1 | md5) $1 - } -else - function md5_file() { - md5sum $1 - } -fi - -function md5_outputs() { - [ -n "${BAZEL_TEST_XTRACE:-}" ] && set +x # Avoid garbage in the output - # runfiles/MANIFEST & runfiles_manifest contain absolute path, ignore. - # ar on OS-X is non-deterministic, ignore .a files. - for i in $(find bazel-bin/ -type f -a \! -name MANIFEST -a \! -name '*.runfiles_manifest' -a \! -name '*.a'); do - md5_file $i - done - for i in $(find bazel-genfiles/ -type f); do - md5_file $i - done - [ -n "${BAZEL_TEST_XTRACE:-}" ] && set -x -} - -function get_outputs_sum() { - md5_outputs | sort -k 2 -} - -function fail() { - echo $1 >&2 - exit 1 -} - -function bootstrap() { - local BAZEL_BIN=$1 - local BAZEL_SUM=$2 - [ -x "${BAZEL_BIN}" ] || fail "syntax: bootstrap bazel-binary" - ${BAZEL_BIN} --blazerc=${BAZELRC} clean || return $? - ${BAZEL_BIN} --blazerc=${BAZELRC} fetch //... || return $? - ${BAZEL_BIN} --blazerc=${BAZELRC} build --nostamp //src:bazel //src:tools || return $? - - if [ -n "${BAZEL_SUM}" ]; then - cat bazel-genfiles/src/java.version >${BAZEL_SUM} - get_outputs_sum >> ${BAZEL_SUM} || return $? - fi -} - -function copy_bootstrap() { - if [ -z "${BOOTSTRAP:-}" ]; then - BOOTSTRAP=$(mktemp /tmp/bootstrap.XXXXXXXXXX) - trap '{ rm -f $BOOTSTRAP; }' EXIT - cp -f $BAZEL_BIN $BOOTSTRAP - chmod +x $BOOTSTRAP - fi -} - -function start_test() { - echo "****${1//?/*}****" - echo "*** $1 ***" - echo "****${1//?/*}****" -} - -function end_test() { - echo " ==> $1 passed" - echo - echo -} - -parse_options "$@" - -if [ -n "${DO_BOOTSTRAP}" -o ! -x ${BAZEL_BIN} ]; then - start_test bootstrap - [ -x "output/bazel" ] || ./compile.sh || fail "Compilation failed" - bootstrap output/bazel ${BAZEL_SUM} || fail "Bootstrap failed" - end_test bootstrap -fi - -# check that bootstrapped binary actually runs correctly -copy_bootstrap -$BOOTSTRAP >/dev/null || fail "Bootstrapped binary is non-functional" - -if [ $DO_CHECKSUM ]; then - start_test checksum - - SUM1=$(mktemp /tmp/bootstrap-sum.XXXXXXXXXX) - SUM2=$(mktemp /tmp/bootstrap-sum.XXXXXXXXXX) - - trap '{ rm -f $BOOTSTRAP $SUM1 $SUM2; }' EXIT - cat $BAZEL_SUM > $SUM1 - - # Second run - bootstrap $BOOTSTRAP $SUM2 || fail "Bootstrap failed" - (diff -U 0 $SUM1 $SUM2 >&2) || fail "Differences detected in outputs!" - - end_test checksum -fi - -if [ $DO_TESTS ]; then - start_test "test" - - $BOOTSTRAP --blazerc=${BAZELRC} test -k --test_output=errors //src/... || fail "Tests failed" - end_test "test" -fi - -echo "Bootstrap tests succeeded (tested: $1)"
diff --git a/compile.sh b/compile.sh index 48a498f..c2b467e 100755 --- a/compile.sh +++ b/compile.sh
@@ -14,428 +14,160 @@ # See the License for the specific language governing permissions and # limitations under the License. -# This script bootstraps building a Bazel binary without Bazel. -# It should only be used to bootstrap Bazel itself. The resulting -# binary can be found at output/bazel +# This script bootstraps building a Bazel binary without Bazel then +# use this compiled Bazel to bootstrap Bazel itself. It can also +# be provided with a previous version of Bazel to bootstrap Bazel +# itself. +# The resulting binary can be found at output/bazel. set -o errexit cd "$(dirname "$0")" -mkdir -p output/classes -mkdir -p output/test_classes -mkdir -p output/src -mkdir -p output/objs -mkdir -p output/native +source scripts/bootstrap/buildenv.sh -# May be passed in from outside. -CXXFLAGS="$CXXFLAGS" -LDFLAGS="$LDFLAGS" -ZIPOPTS="$ZIPOPTS" -# TODO: CC target architecture needs to match JAVA_HOME. -CC=${CC:-gcc} -CXX=${CXX:-g++} -CXXSTD="c++0x" - -unset JAVA_TOOL_OPTIONS -unset _JAVA_OPTIONS - -JAVA_VERSION=${JAVA_VERSION:-"1.8"} -PLATFORM="$(uname -s | tr 'A-Z' 'a-z')" -ARCHIVE_CFLAGS=${ARCHIVE_CFLAGS:-""} -LDFLAGS=${LDFLAGS:-""} - -# Extension for executables (.exe on Windows). -EXE_EXT="" - -PROTO_FILES=$(ls src/main/protobuf/*.proto) -LIBRARY_JARS=$(find third_party -name *.jar | tr "\n" " ") -DIRS=$(echo src/{main/java,tools/xcode-common/java/com/google/devtools/build/xcode/{common,util}} output/src) - -MSYS_DLLS="" -PATHSEP=":" - -function fail() { - echo "$1" >&2 +function usage() { + [ -n "${1:-build}" ] && echo "Invalid command(s): $1" >&2 + echo "syntax: $0 [command[,command]* [BAZEL_BIN [BAZEL_SUM]]]" >&2 + echo " General purpose commands:" >&2 + echo " build = compile,tools,init (default)" >&2 + echo " compile = compile a Bazel binary for usage" >&2 + echo " tools = compile and install tooling for Bazel" >&2 + echo " init = initialize the base workspace" >&2 + echo " Commands for developers:" >&2 + echo " all = build,determinism,test" >&2 + echo " determinism = test for stability of Bazel builds" >&2 + echo " test = run the full test suite of Bazel" >&2 exit 1 } -function log() { - if [[ -z "${QUIETMODE}" ]]; then - echo -e "$1" >&2 - fi +function parse_options() { + local keywords="(build|compile|tools|init|all|determinism|bootstrap|test)" + COMMANDS="${1:-build}" + [[ "${COMMANDS}" =~ ^$keywords(,$keywords)*$ ]] || usage "$@" + DO_COMPILE= + DO_TOOLS_COMPILATION= + DO_CHECKSUM= + DO_FULL_CHECKSUM=1 + DO_TESTS= + DO_BASE_WORKSPACE_INIT= + [[ "${COMMANDS}" =~ (compile|build|all) ]] && DO_COMPILE=1 + [[ "${COMMANDS}" =~ (tools|build|all) ]] && DO_TOOLS_COMPILATION=1 + [[ "${COMMANDS}" =~ (init|build|all) ]] && DO_BASE_WORKSPACE_INIT=1 + [[ "${COMMANDS}" =~ (bootstrap|determinism|all) ]] && DO_CHECKSUM=1 + [[ "${COMMANDS}" =~ (bootstrap) ]] && DO_FULL_CHECKSUM= + [[ "${COMMANDS}" =~ (test|all) ]] && DO_TESTS=1 + + BAZEL_BIN=${2:-"bazel-bin/src/bazel"} + BAZEL_SUM=${3:-"bazel-out/bazel_checksum"} } -# Create symlinks so we can use tools and examples from the base_workspace. -base_workspace=$(pwd)/base_workspace -mkdir -p "$base_workspace" -rm -f "${base_workspace}/tools" && ln -s "$(pwd)/tools" "${base_workspace}/tools" -rm -f "${base_workspace}/third_party" && ln -s "$(pwd)/third_party" "${base_workspace}/third_party" -rm -f "${base_workspace}/examples" && ln -s "$(pwd)/examples" "${base_workspace}/examples" +parse_options "${@}" -case "${PLATFORM}" in -linux) - # Sorry, no static linking on linux for now. - LDFLAGS="-lz -lrt $LDFLAGS" - JNILIB="libunix.so" - MD5SUM="md5sum" - # JAVA_HOME must point to a Java 8 installation. - JAVA_HOME="${JAVA_HOME:-$(readlink -f $(which javac) | sed 's_/bin/javac__')}" - PROTOC=${PROTOC:-third_party/protobuf/protoc.linux-i686} - ;; +mkdir -p output +: ${BAZEL:=${2-}} -darwin) - JNILIB="libunix.dylib" - MD5SUM="md5" - LDFLAGS="-lz $LDFLAGS" - if [[ -z "$JAVA_HOME" ]]; then - JAVA_HOME="$(/usr/libexec/java_home -v 1.8+ 2> /dev/null)" \ - || fail "Could not find JAVA_HOME, please ensure a JDK (version 1.8+) is installed." - fi - PROTOC=${PROTOC:-third_party/protobuf/protoc.darwin} - - ;; - -msys*|mingw*) - # Use a simplified platform string. - PLATFORM="mingw" - # Workaround for msys issue which causes omission of std::to_string. - CXXFLAGS="$CXXFLAGS -D_GLIBCXX_USE_C99 -D_GLIBCXX_USE_C99_DYNAMIC" - LDFLAGS="-lz $LDFLAGS" - MD5SUM="md5sum" - EXE_EXT=".exe" - PATHSEP=";" - # Find the latest available version of the SDK. - JAVA_HOME="${JAVA_HOME:-$(ls -d /c/Program\ Files/Java/jdk* | sort | tail -n 1)}" - # We do not use the JNI library on Windows. - JNILIB="" - PROTOC=${PROTOC:-protoc} - - # The newer version of GCC on msys is stricter and removes some important function - # declarations from the environment if using c++0x / c++11. - CXXSTD="gnu++11" - - # Ensure that we are using the cygwin gcc, not the mingw64 gcc. - ${CC} -v 2>&1 | grep "Target: .*mingw.*" > /dev/null && - fail "mingw gcc detected. Please set CC to point to the msys/Cygwin gcc." - ${CXX} -v 2>&1 | grep "Target: .*mingw.*" > /dev/null && - fail "mingw g++ detected. Please set CXX to point to the msys/Cygwin g++." - - MSYS_DLLS="msys-2.0.dll msys-gcc_s-seh-1.dll msys-stdc++-6.dll" - for dll in $MSYS_DLLS ; do - cp "/usr/bin/$dll" "output/$dll" - done -esac - -[[ -x "${PROTOC-}" ]] \ - || fail "Protobuf compiler not found in ${PROTOC-}" - -test -z "$JAVA_HOME" && fail "JDK not found, please set \$JAVA_HOME." -rm -f tools/jdk/jdk && ln -s "${JAVA_HOME}" tools/jdk/jdk - -JAVAC="${JAVA_HOME}/bin/javac" - -[[ -x "${JAVAC}" ]] \ - || fail "JAVA_HOME ($JAVA_HOME) is not a path to a working JDK." - -JAVAC_VERSION=$("${JAVAC}" -version 2>&1) -[[ "$JAVAC_VERSION" =~ ^"javac 1"\.([89]|[1-9][0-9]).*$ ]] \ - || fail "JDK version is lower than 1.8, please set \$JAVA_HOME." - -JAR="${JAVA_HOME}/bin/jar" - -BLAZE_CC_FILES=( -src/main/cpp/blaze_startup_options.cc -src/main/cpp/blaze_startup_options_common.cc -src/main/cpp/blaze_util.cc -src/main/cpp/blaze_util_${PLATFORM}.cc -src/main/cpp/blaze.cc -src/main/cpp/option_processor.cc -src/main/cpp/util/errors.cc -src/main/cpp/util/file.cc -src/main/cpp/util/md5.cc -src/main/cpp/util/numbers.cc -src/main/cpp/util/port.cc -src/main/cpp/util/strings.cc -third_party/ijar/zip.cc -) - -NATIVE_CC_FILES=( -src/main/cpp/util/md5.cc -src/main/native/localsocket.cc -src/main/native/process.cc -src/main/native/unix_jni.cc -src/main/native/unix_jni_${PLATFORM}.cc -) - -IJAR_CC_FILES=( -third_party/ijar/ijar.cc -third_party/ijar/zip.cc -third_party/ijar/classfile.cc -) - -# Compiles java classes. -function java_compilation() { - name=$1 - directories=$2 - library_jars=$3 - output=$4 - - classpath=${library_jars// /$PATHSEP}:$5 - sourcepath=${directories// /$PATHSEP} - - tmp="$(mktemp -d ${TMPDIR:-/tmp}/bazel.XXXXXXXX)" - paramfile="${tmp}/param" - errfile="${tmp}/err" - - mkdir -p "${output}/classes" - - trap "cat \"$errfile\"; rm -f \"$paramfile\" \"$errfile\"; rmdir \"$tmp\"" EXIT - - # Compile .java files (incl. generated ones) using javac - log "Compiling $name code..." - find ${directories} -name "*.java" > "$paramfile" - - if [ ! -z "$BAZEL_DEBUG_JAVA_COMPILATION" ]; then - echo "directories=${directories}" >&2 - echo "classpath=${classpath}" >&2 - echo "sourcepath=${sourcepath}" >&2 - echo "libraries=${library_jars}" >&2 - echo "output=${output}/classes" >&2 - echo "List of compiled files:" >&2 - cat "$paramfile" >&2 - fi - - "${JAVAC}" -classpath "${classpath}" -sourcepath "${sourcepath}" \ - -d "${output}/classes" -source "$JAVA_VERSION" -target "$JAVA_VERSION" \ - "@${paramfile}" &> "$errfile" || - exit $? - trap - EXIT - rm "$paramfile" "$errfile" - rmdir "$tmp" - - log "Extracting helper classes for $name..." - for f in ${library_jars} ; do - unzip -qn ${f} -d "${output}/classes" - done -} - -# Create the deploy JAR -function create_deploy_jar() { - name=$1 - mainClass=$2 - output=$3 - shift 3 - packages="" - for i in $output/classes/*; do - package=$(basename $i) - if [[ "$package" != "META-INF" ]]; then - packages="$packages -C $output/classes $package" - fi - done - - log "Creating $name.jar..." - echo "Main-Class: $mainClass" > $output/MANIFEST.MF - "$JAR" cmf $output/MANIFEST.MF $output/$name.jar $packages "$@" -} - -function cc_compile() { - local OBJDIR=$1 - shift - mkdir -p "output/${OBJDIR}" - for FILE in "$@"; do - if [[ ! "${FILE}" =~ ^-.*$ ]]; then - local OBJ=$(basename "${FILE}").o - "${CXX}" \ - -I. \ - ${ARCHIVE_CFLAGS} \ - ${CFLAGS} \ - -std=$CXXSTD \ - -c \ - -DBLAZE_JAVA_CPU=\"k8\" \ - -DBLAZE_OPENSOURCE=1 \ - -o "output/${OBJDIR}/${OBJ}" \ - "${FILE}" - fi - done -} - -function cc_link() { - local OBJDIR=$1 - local OUTPUT=$2 - shift 2 - local FILES=() - for FILE in "$@"; do - local OBJ=$(basename "${FILE}").o - FILES+=("output/${OBJDIR}/${OBJ}") - done - "${CXX}" -o ${OUTPUT} "${FILES[@]}" -lstdc++ ${LDFLAGS} -} - -function cc_build() { - local NAME=$1 - local OBJDIR=$2 - local OUTPUT=$3 - shift 3 - log "Compiling ${NAME} .cc files..." - cc_compile "${OBJDIR}" "$@" - log "Linking ${NAME}..." - cc_link "${OBJDIR}" "${OUTPUT}" "$@" -} - -if [ -z "${BAZEL_SKIP_JAVA_COMPILATION}" ]; then - log "Compiling Java stubs for protocol buffers..." - for f in $PROTO_FILES ; do - "${PROTOC}" -Isrc/main/protobuf/ --java_out=output/src "$f" - done - - java_compilation "Bazel Java" "$DIRS" "$LIBRARY_JARS" "output" - - # help files: all non java and BUILD files in src/main/java. - for i in $(find src/main/java -type f -a \! -name '*.java' -a \! -name 'BUILD' | sed 's|src/main/java/||'); do - mkdir -p $(dirname output/classes/$i) - cp src/main/java/$i output/classes/$i - done - - # build-data.properties - git_version="non-git" - if [ -x "$(which git || true)" ] && [ -d .git ]; then - git_version=$(git log -1 --oneline | cut -d " " -f 1 2>/dev/null || \ - echo "non-git") - fi - cat >output/classes/build-data.properties <<EOF -build.time=$(date) -build.label=bazel-compile.sh-${git_version} -EOF - create_deploy_jar "libblaze" "com.google.devtools.build.lib.bazel.BazelMain" \ - output third_party/javascript +# +# Create an initial binary so we can host ourself +# +if [ ! -x "${BAZEL}" ]; then + display "$INFO You can skip this first step by providing a path to the bazel binary as second argument:" + display "$INFO $0 ${COMMANDS} /path/to/bazel" + new_step 'Building Bazel from scratch' + source scripts/bootstrap/compile.sh + cp ${OUTPUT_DIR}/bazel output/bazel + BAZEL=$(pwd)/output/bazel fi -cc_build "client" "objs" "output/client" ${BLAZE_CC_FILES[@]} - -if [ ! -z "$JNILIB" ] ; then - log "Compiling JNI libraries..." - for FILE in "${NATIVE_CC_FILES[@]}"; do - OUT=$(basename "${FILE}").o - "${CXX}" \ - -I . \ - -I "${JAVA_HOME}/include/" \ - -I "${JAVA_HOME}/include/${PLATFORM}" \ - -std=$CXXSTD \ - -fPIC \ - -c \ - -D_JNI_IMPLEMENTATION_ \ - -DBLAZE_JAVA_CPU=\"k8\" \ - -DBLAZE_OPENSOURCE=1 \ - -o "output/native/${OUT}" \ - "${FILE}" - done - - log "Linking ${JNILIB}..." - "${CXX}" -o output/${JNILIB} $JNI_LD_ARGS -shared output/native/*.o -l stdc++ +# +# Bootstrap bazel using the previous bazel binary = release binary +# +if [ -z "${EMBED_LABEL-}" ]; then + # Add a default label when unspecified + git_sha1=$(git_sha1) + EMBED_LABEL="head (@${git_sha1:-non-git})" fi -log "Compiling build-runfiles..." -# Clang on Linux requires libstdc++ -"${CXX}" -o output/build-runfiles -std=c++0x -l stdc++ src/main/tools/build-runfiles.cc - -log "Compiling process-wrapper..." -"${CC}" -o output/process-wrapper -std=c99 src/main/tools/process-wrapper.c -if [[ $PLATFORM == "linux" ]]; then - log "Compiling sandbox..." - "${CC}" -o output/namespace-sandbox -std=c99 src/main/tools/namespace-sandbox.c +source scripts/bootstrap/bootstrap.sh +if [ $DO_COMPILE ]; then + new_step 'Building Bazel with Bazel' + display "." + bazel_bootstrap //src:bazel output/bazel 0755 1 + BAZEL=$(pwd)/output/bazel fi -cp src/main/tools/build_interface_so output/build_interface_so -cp src/main/tools/jdk.* output - -touch output/client_info -chmod 755 output/client_info - -log "Creating Bazel self-extracting archive..." -TO_ZIP="libblaze.jar ${JNILIB} build-runfiles${EXE_EXT} process-wrapper${EXE_EXT} client_info build_interface_so ${MSYS_DLLS} jdk.WORKSPACE jdk.BUILD" -if [[ $PLATFORM == "linux" ]]; then - TO_ZIP="$TO_ZIP namespace-sandbox${EXE_EXT}" +# +# Bootstrap tools using the release binary +# +if [ $DO_TOOLS_COMPILATION ]; then + new_step 'Building Bazel tools' + bazel_bootstrap //third_party/ijar:ijar tools/jdk/ijar 755 + bazel_bootstrap //src/java_tools/singlejar:SingleJar_deploy.jar \ + tools/jdk/SingleJar_deploy.jar + bazel_bootstrap //src/java_tools/buildjar:JavaBuilder_deploy.jar \ + tools/jdk/JavaBuilder_deploy.jar + if [[ $PLATFORM == "darwin" ]]; then + bazel_bootstrap //src/tools/xcode-common/java/com/google/devtools/build/xcode/actoolzip:actoolzip_deploy.jar \ + tools/objc/precomp_actoolzip_deploy.jar + bazel_bootstrap //src/tools/xcode-common/java/com/google/devtools/build/xcode/ibtoolzip:ibtoolzip_deploy.jar \ + tools/objc/precomp_ibtoolzip_deploy.jar + bazel_bootstrap //src/objc_tools/momczip:momczip_deploy.jar \ + tools/objc/precomp_momczip_deploy.jar + bazel_bootstrap //src/objc_tools/bundlemerge:bundlemerge_deploy.jar \ + tools/objc/precomp_bundlemerge_deploy.jar + bazel_bootstrap //src/objc_tools/plmerge:plmerge_deploy.jar \ + tools/objc/precomp_plmerge_deploy.jar + bazel_bootstrap //src/objc_tools/xcodegen:xcodegen_deploy.jar \ + tools/objc/precomp_xcodegen_deploy.jar + fi fi -(cd output/ ; cat client ${TO_ZIP} | ${MD5SUM} | awk '{ print $1; }' > install_base_key) -(cd output/ ; echo "${JAVA_VERSION}" > java.version) -(cd output/ ; find . -type f | xargs -P 10 touch -t 198001010000) -(cd output/ ; zip $ZIPOPTS -q package.zip ${TO_ZIP} install_base_key java.version) -cat output/client output/package.zip > output/bazel -zip -qA output/bazel \ - || echo "(Non-critical error, ignore.)" +# +# Output is deterministic between two bootstrapped bazel binary using the actual tools and the +# released binary. +# +if [ $DO_CHECKSUM ]; then + new_step "Determinism test" + BAZEL_SUM=${BAZEL_SUM:-bazel-out/bazel_checksum} + if [ ! -f ${BAZEL_SUM} ]; then + log "First build" + bootstrap_test ${BAZEL} ${BAZEL_SUM} + else + BOOTSTRAP=${BAZEL} + fi + if [ "${BAZEL_SUM}" != "${OUTPUT_DIR}/bazel_checksum" ]; then + cp ${BAZEL_SUM} ${OUTPUT_DIR}/bazel_checksum + fi + if [ $DO_FULL_CHECKSUM ]; then + log "Second build" + bootstrap_test ${BOOTSTRAP} bazel-out/bazel_checksum + log "Comparing output" + (diff -U 0 ${OUTPUT_DIR}/bazel_checksum bazel-out/bazel_checksum >&2) \ + || fail "Differences detected in outputs!" + fi +fi -chmod 755 output/bazel - -function bootstrap_tool() { - output/bazel --blazerc=/dev/null build \ - --singlejar_top=//src/java_tools/singlejar:bootstrap_deploy.jar \ - --javabuilder_top=//src/java_tools/buildjar:bootstrap_deploy.jar \ +# +# Tests +# +if [ $DO_TESTS ]; then + new_step "Running tests" + display "." + $BAZEL --blazerc=${BAZELRC} test \ --javacopt="-source ${JAVA_VERSION} -target ${JAVA_VERSION}" \ - "${@}" -} - -# Compile ijar -bootstrap_tool //third_party/ijar -mkdir -p tools/jdk -cp -f bazel-bin/third_party/ijar/ijar tools/jdk -chmod 755 tools/jdk/ijar - -if [ -z "${BAZEL_SKIP_SINGLEJAR_COMPILATION}" ]; then - # Compile singlejar, a jar suitable for deployment. - bootstrap_tool //src/java_tools/singlejar:SingleJar_deploy.jar - mkdir -p tools/jdk - cp -f bazel-bin/src/java_tools/singlejar/SingleJar_deploy.jar tools/jdk - chmod 644 tools/jdk/SingleJar_deploy.jar + -k --test_output=errors //src/... //third_party/ijar/... //scripts/... \ + || fail "Tests failed" fi -if [ -z "${BAZEL_SKIP_BUILDJAR_COMPILATION}" ]; then - bootstrap_tool //src/java_tools/buildjar:JavaBuilder_deploy.jar - mkdir -p tools/jdk - cp -f bazel-bin/src/java_tools/buildjar/JavaBuilder_deploy.jar tools/jdk - chmod 644 tools/jdk/JavaBuilder_deploy.jar +# +# Setup the base workspace +# +if [ $DO_BASE_WORKSPACE_INIT ]; then + new_step 'Setting up base workspace' + display "." + source scripts/bootstrap/init_workspace.sh fi -if [[ $PLATFORM == "darwin" ]] && [ -z "${BAZEL_SKIP_OBJCTOOLS_COMPILATION}" ]; then - log "Creating objc helper tools..." - - OBJC_TOOLS="src/tools/xcode-common/java/com/google/devtools/build/xcode/actoolzip:actoolzip_deploy.jar \ - src/tools/xcode-common/java/com/google/devtools/build/xcode/ibtoolzip:ibtoolzip_deploy.jar \ - src/objc_tools/momczip:momczip_deploy.jar \ - src/objc_tools/bundlemerge:bundlemerge_deploy.jar \ - src/objc_tools/plmerge:plmerge_deploy.jar \ - src/objc_tools/xcodegen:xcodegen_deploy.jar" - bootstrap_tool ${OBJC_TOOLS} - - for i in ${OBJC_TOOLS}; do - p=bazel-bin/$(echo $i | sed "s|:|/|") - cp $p tools/objc/precomp_$(basename $p) - chmod 0644 tools/objc/precomp_$(basename $p) - done -fi - -# Create a bazelrc file with the base_workspace directory in the package path. -bazelrc='build --package_path %workspace%:'${base_workspace} -bazelrc="${bazelrc}"$'\nfetch --package_path %workspace%:'${base_workspace} -bazelrc="${bazelrc}"$'\nquery --package_path %workspace%:'${base_workspace} -if [ -z "${HOME-}" ]; then - warning="No \$HOME variable set, cannot write .bazelrc file." - warning="$warning Consider adding $base_workspace to your package path" - log $warning -elif [ ! -f $HOME/.bazelrc ]; then - log "Creating a .bazelrc pointing to $base_workspace" - echo "$bazelrc" > $HOME/.bazelrc -else - while read rcline; do - if ! grep -q "$rcline" $HOME/.bazelrc; then - warning="You already have a .bazelrc. Make sure it contains the " - warning="$warning following package paths:\n$bazelrc" - log "$warning" - break - fi - done <<< "$bazelrc" -fi - -log "Build successful! Binary is here: ${PWD}/output/bazel" +clear_log +display "Build successful! Binary is here: ${BAZEL}"
diff --git a/scripts/bootstrap/bootstrap.sh b/scripts/bootstrap/bootstrap.sh new file mode 100755 index 0000000..9d346b7 --- /dev/null +++ b/scripts/bootstrap/bootstrap.sh
@@ -0,0 +1,91 @@ +#!/bin/bash + +# Copyright 2015 Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Use bazel to bootstrap various tools +# Configuration: +# BAZEL: path to the bazel binary +# EMBED_LABEL: the label to embed in tools using --embed_label (optional) +# BAZEL_ARGS: list of other arguments to pass to bazel (optional) +# BAZELRC: the rc file to use + +: ${BAZELRC:="/dev/null"} +: ${EMBED_LABEL:=""} + +EMBED_LABEL_ARG=() +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 \ + --ijar_top=//third_party/ijar"} + +function bazel_bootstrap() { + local mode=${3:-"0644"} + if [[ ! ${BAZEL_SKIP_TOOL_COMPILATION-} =~ "$2" ]]; then + log "Building $2" + if [ -n "${4-}" ]; then + ${BAZEL} --blazerc=${BAZELRC} build ${BAZEL_ARGS} \ + --javacopt="-source ${JAVA_VERSION} -target ${JAVA_VERSION}" \ + "${EMBED_LABEL_ARG[@]}" $1 + else + run_silent ${BAZEL} --blazerc=${BAZELRC} build ${BAZEL_ARGS} \ + --javacopt="-source ${JAVA_VERSION} -target ${JAVA_VERSION}" \ + "${EMBED_LABEL_ARG[@]}" $1 + fi + local file=bazel-bin/${1##//} + cp -f ${file/:/\/} $2 + chmod ${mode} $2 + fi +} + +function md5_outputs() { + [ -n "${BAZEL_TEST_XTRACE:-}" ] && set +x # Avoid garbage in the output + # runfiles/MANIFEST & runfiles_manifest contain absolute path, ignore. + # ar on OS-X is non-deterministic, ignore .a files. + for i in $(find bazel-bin/ -type f -a \! -name MANIFEST -a \! -name '*.runfiles_manifest' -a \! -name '*.a'); do + md5_file $i + done + for i in $(find bazel-genfiles/ -type f); do + md5_file $i + done + [ -n "${BAZEL_TEST_XTRACE:-}" ] && set -x +} + +function get_outputs_sum() { + md5_outputs | sort -k 2 +} + +function bootstrap_test() { + local BAZEL_BIN=$1 + local BAZEL_SUM=$2 + [ -x "${BAZEL_BIN}" ] || fail "syntax: bootstrap bazel-binary" + run_silent ${BAZEL_BIN} --blazerc=${BAZELRC} clean || return $? + run_silent ${BAZEL_BIN} --blazerc=${BAZELRC} build --fetch --nostamp \ + --javacopt="-source ${JAVA_VERSION} -target ${JAVA_VERSION}" \ + //src:bazel //src:tools || 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 + cp -f bazel-bin/src/bazel $BOOTSTRAP + chmod +x $BOOTSTRAP + fi +}
diff --git a/scripts/bootstrap/buildenv.sh b/scripts/bootstrap/buildenv.sh new file mode 100755 index 0000000..20192ed --- /dev/null +++ b/scripts/bootstrap/buildenv.sh
@@ -0,0 +1,103 @@ +# Copyright 2015 Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# General purpose method and values for bootstrapping bazel. + +set -o errexit + +DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +WORKSPACE_DIR="$(dirname $(dirname ${DIR}))" + +JAVA_VERSION=${JAVA_VERSION:-1.8} +BAZELRC=${BAZELRC:-"/dev/null"} +PLATFORM="$(uname -s | tr 'A-Z' 'a-z')" + +ATEXIT_="" +function atexit() { + ATEXIT_="$1; ${ATEXIT_}" + trap "{ ${ATEXIT_} }" EXIT +} + +function tempdir() { + local tmp=${TMPDIR:-/tmp} + local DIR="$(mktemp -d ${tmp%%/}/bazel.XXXXXXXX)" + mkdir -p "${DIR}" + atexit "rm -fr ${DIR}" + NEW_TMPDIR="${DIR}" +} +tempdir +OUTPUT_DIR=${NEW_TMPDIR} +errfile=${OUTPUT_DIR}/errors +atexit "if [ -f ${errfile} ]; then cat ${errfile} >&2; fi" +phasefile=${OUTPUT_DIR}/phase +atexit "if [ -f ${phasefile} ]; then echo >&2; cat ${phasefile} >&2; fi" + +function run_silent() { + echo "${@}" >${errfile} + "${@}" 2>&1 >>${errfile} + rm ${errfile} +} + +function fail() { + echo >&2 + echo "$1" >&2 + exit 1 +} + +function display() { + if [[ -z "${QUIETMODE}" ]]; then + echo -e "$@" >&2 + fi +} + +function log() { + echo -n "." >&2 + echo "$1" >${phasefile} +} + +function clear_log() { + echo >&2 + rm -f ${phasefile} +} + +LEAVES="\xF0\x9F\x8D\x83" +INFO="\033[32mINFO\033[0m:" + +first_step=1 +function new_step() { + rm -f ${phasefile} + local new_line= + if [ -n "${first_step}" ]; then + first_step= + else + new_line="\n" + fi + display -n "$new_line$LEAVES $1" +} + +function git_sha1() { + if [ -x "$(which git || true)" ] && [ -d .git ]; then + git rev-parse --short HEAD 2>/dev/null || true + fi +} + +if [[ ${PLATFORM} == "darwin" ]]; then + function md5_file() { + echo $(cat $1 | md5) $1 + } +else + function md5_file() { + md5sum $1 + } +fi
diff --git a/scripts/bootstrap/compile.sh b/scripts/bootstrap/compile.sh new file mode 100755 index 0000000..9745a9c --- /dev/null +++ b/scripts/bootstrap/compile.sh
@@ -0,0 +1,315 @@ +#!/bin/bash + +# Copyright 2015 Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Script for building bazel from scratch without bazel + +PROTO_FILES=$(ls src/main/protobuf/*.proto) +LIBRARY_JARS=$(find third_party -name '*.jar' | tr "\n" " ") +DIRS=$(echo src/{main/java,tools/xcode-common/java/com/google/devtools/build/xcode/{common,util}} ${OUTPUT_DIR}/src) + +BLAZE_CC_FILES=( +src/main/cpp/blaze_startup_options.cc +src/main/cpp/blaze_startup_options_common.cc +src/main/cpp/blaze_util.cc +src/main/cpp/blaze_util_${PLATFORM}.cc +src/main/cpp/blaze.cc +src/main/cpp/option_processor.cc +src/main/cpp/util/errors.cc +src/main/cpp/util/file.cc +src/main/cpp/util/md5.cc +src/main/cpp/util/numbers.cc +src/main/cpp/util/port.cc +src/main/cpp/util/strings.cc +third_party/ijar/zip.cc +) + +NATIVE_CC_FILES=( +src/main/cpp/util/md5.cc +src/main/native/localsocket.cc +src/main/native/process.cc +src/main/native/unix_jni.cc +src/main/native/unix_jni_${PLATFORM}.cc +) + +mkdir -p ${OUTPUT_DIR}/classes +mkdir -p ${OUTPUT_DIR}/test_classes +mkdir -p ${OUTPUT_DIR}/src +mkdir -p ${OUTPUT_DIR}/objs +mkdir -p ${OUTPUT_DIR}/native + +# May be passed in from outside. +CXXFLAGS="$CXXFLAGS" +LDFLAGS="$LDFLAGS" +ZIPOPTS="$ZIPOPTS" + +# TODO: CC target architecture needs to match JAVA_HOME. +CC=${CC:-gcc} +CXX=${CXX:-g++} +CXXSTD="c++0x" + +unset JAVA_TOOL_OPTIONS +unset _JAVA_OPTIONS + +LDFLAGS=${LDFLAGS:-""} + +# Extension for executables (.exe on Windows). +EXE_EXT="" + +MSYS_DLLS="" +PATHSEP=":" + +case "${PLATFORM}" in +linux) + LDFLAGS="-lz -lrt $LDFLAGS" + JNILIB="libunix.so" + MD5SUM="md5sum" + # JAVA_HOME must point to a Java installation. + JAVA_HOME="${JAVA_HOME:-$(readlink -f $(which javac) | sed 's_/bin/javac__')}" + PROTOC=${PROTOC:-third_party/protobuf/protoc.linux-i686} + ;; + +darwin) + JNILIB="libunix.dylib" + MD5SUM="md5" + LDFLAGS="-lz $LDFLAGS" + if [[ -z "$JAVA_HOME" ]]; then + JAVA_HOME="$(/usr/libexec/java_home -v ${JAVA_VERSION}+ 2> /dev/null)" \ + || fail "Could not find JAVA_HOME, please ensure a JDK (version ${JAVA_VERSION}+) is installed." + fi + PROTOC=${PROTOC:-third_party/protobuf/protoc.darwin} + ;; + +msys*|mingw*) + # Use a simplified platform string. + PLATFORM="mingw" + # Workaround for msys issue which causes omission of std::to_string. + CXXFLAGS="$CXXFLAGS -D_GLIBCXX_USE_C99 -D_GLIBCXX_USE_C99_DYNAMIC" + LDFLAGS="-lz $LDFLAGS" + MD5SUM="md5sum" + EXE_EXT=".exe" + PATHSEP=";" + # Find the latest available version of the SDK. + JAVA_HOME="${JAVA_HOME:-$(ls -d /c/Program\ Files/Java/jdk* | sort | tail -n 1)}" + # We do not use the JNI library on Windows. + JNILIB="" + PROTOC=${PROTOC:-protoc} + + # The newer version of GCC on msys is stricter and removes some important function + # declarations from the environment if using c++0x / c++11. + CXXSTD="gnu++11" + + # Ensure that we are using the cygwin gcc, not the mingw64 gcc. + ${CC} -v 2>&1 | grep "Target: .*mingw.*" > /dev/null && + fail "mingw gcc detected. Please set CC to point to the msys/Cygwin gcc." + ${CXX} -v 2>&1 | grep "Target: .*mingw.*" > /dev/null && + fail "mingw g++ detected. Please set CXX to point to the msys/Cygwin g++." + + MSYS_DLLS="msys-2.0.dll msys-gcc_s-seh-1.dll msys-stdc++-6.dll" + for dll in $MSYS_DLLS ; do + cp "/usr/bin/$dll" "${OUTPUT_DIR}/$dll" + done +esac + +[[ -x "${PROTOC-}" ]] \ + || fail "Protobuf compiler not found in ${PROTOC-}" + +test -z "$JAVA_HOME" && fail "JDK not found, please set \$JAVA_HOME." +rm -f tools/jdk/jdk && ln -s "${JAVA_HOME}" tools/jdk/jdk + +JAVAC="${JAVA_HOME}/bin/javac" + +[[ -x "${JAVAC}" ]] \ + || fail "JAVA_HOME ($JAVA_HOME) is not a path to a working JDK." + +# Check that javac -version returns a upper version than $JAVA_VERSION. +JAVAC_VERSION=$("${JAVAC}" -version 2>&1) +if [[ "$JAVAC_VERSION" =~ ^"javac "(1\.([789]|[1-9][0-9])).*$ ]]; then + JAVAC_VERSION=${BASH_REMATCH[1]} + [ ${JAVA_VERSION#*.} -le ${JAVAC_VERSION#*.} ] || \ + fail "JDK version (${JAVAC_VERSION}) is lower than ${JAVA_VERSION}, please set \$JAVA_HOME." +else + fail "Cannot determine JDK version, please set \$JAVA_HOME." +fi + +JAR="${JAVA_HOME}/bin/jar" + +# Compiles java classes. +function java_compilation() { + local name=$1 + local directories=$2 + local library_jars=$3 + local output=$4 + + local classpath=${library_jars// /$PATHSEP}:$5 + local sourcepath=${directories// /$PATHSEP} + + tempdir + local tmp="${NEW_TMPDIR}" + local paramfile="${tmp}/param" + touch $paramfile + + mkdir -p "${output}/classes" + + # Compile .java files (incl. generated ones) using javac + log "Compiling $name code..." + find ${directories} -name "*.java" > "$paramfile" + + if [ ! -z "$BAZEL_DEBUG_JAVA_COMPILATION" ]; then + echo "directories=${directories}" >&2 + echo "classpath=${classpath}" >&2 + echo "sourcepath=${sourcepath}" >&2 + echo "libraries=${library_jars}" >&2 + echo "output=${output}/classes" >&2 + echo "List of compiled files:" >&2 + cat "$paramfile" >&2 + fi + + run_silent "${JAVAC}" -classpath "${classpath}" -sourcepath "${sourcepath}" \ + -d "${output}/classes" -source "$JAVA_VERSION" -target "$JAVA_VERSION" \ + "@${paramfile}" + + log "Extracting helper classes for $name..." + for f in ${library_jars} ; do + run_silent unzip -qn ${f} -d "${output}/classes" + done +} + +# Create the deploy JAR +function create_deploy_jar() { + local name=$1 + local mainClass=$2 + local output=$3 + shift 3 + local packages="" + for i in $output/classes/*; do + local package=$(basename $i) + if [[ "$package" != "META-INF" ]]; then + packages="$packages -C $output/classes $package" + fi + done + + log "Creating $name.jar..." + echo "Main-Class: $mainClass" > $output/MANIFEST.MF + run_silent "$JAR" cmf $output/MANIFEST.MF $output/$name.jar $packages "$@" +} + +function cc_compile() { + local OBJDIR=$1 + shift + mkdir -p "${OUTPUT_DIR}/${OBJDIR}" + for FILE in "$@"; do + if [[ ! "${FILE}" =~ ^-.*$ ]]; then + local OBJ=$(basename "${FILE}").o + run_silent "${CXX}" \ + -I. \ + ${CFLAGS} \ + -std=$CXXSTD \ + -c \ + -DBLAZE_JAVA_CPU=\"k8\" \ + -DBLAZE_OPENSOURCE=1 \ + -o "${OUTPUT_DIR}/${OBJDIR}/${OBJ}" \ + "${FILE}" + fi + done +} + +function cc_link() { + local OBJDIR=$1 + local OUTPUT=$2 + shift 2 + local FILES=() + for FILE in "$@"; do + local OBJ=$(basename "${FILE}").o + FILES+=("${OUTPUT_DIR}/${OBJDIR}/${OBJ}") + done + run_silent "${CXX}" -o ${OUTPUT} "${FILES[@]}" -lstdc++ ${LDFLAGS} +} + +function cc_build() { + local NAME=$1 + local OBJDIR=$2 + local OUTPUT=$3 + shift 3 + log "Compiling ${NAME} .cc files..." + cc_compile "${OBJDIR}" "$@" + log "Linking ${NAME}..." + cc_link "${OBJDIR}" "${OUTPUT}" "$@" +} + +if [ -z "${BAZEL_SKIP_JAVA_COMPILATION}" ]; then + log "Compiling Java stubs for protocol buffers..." + for f in $PROTO_FILES ; do + "${PROTOC}" -Isrc/main/protobuf/ --java_out=${OUTPUT_DIR}/src "$f" + done + + java_compilation "Bazel Java" "$DIRS" "$LIBRARY_JARS" "${OUTPUT_DIR}" + + # help files: all non java and BUILD files in src/main/java. + for i in $(find src/main/java -type f -a \! -name '*.java' -a \! -name 'BUILD' | sed 's|src/main/java/||'); do + mkdir -p $(dirname ${OUTPUT_DIR}/classes/$i) + cp src/main/java/$i ${OUTPUT_DIR}/classes/$i + done + + create_deploy_jar "libblaze" "com.google.devtools.build.lib.bazel.BazelMain" \ + ${OUTPUT_DIR} third_party/javascript +fi + +cc_build "client" "objs" "${OUTPUT_DIR}/client" ${BLAZE_CC_FILES[@]} + +if [ ! -z "$JNILIB" ] ; then + log "Compiling JNI libraries..." + for FILE in "${NATIVE_CC_FILES[@]}"; do + OUT=$(basename "${FILE}").o + run_silent "${CXX}" \ + -I . \ + -I "${JAVA_HOME}/include/" \ + -I "${JAVA_HOME}/include/${PLATFORM}" \ + -std=$CXXSTD \ + -fPIC \ + -c \ + -D_JNI_IMPLEMENTATION_ \ + -DBLAZE_JAVA_CPU=\"k8\" \ + -DBLAZE_OPENSOURCE=1 \ + -o "${OUTPUT_DIR}/native/${OUT}" \ + "${FILE}" + done + + log "Linking ${JNILIB}..." + run_silent "${CXX}" -o ${OUTPUT_DIR}/${JNILIB} $JNI_LD_ARGS -shared ${OUTPUT_DIR}/native/*.o -l stdc++ +fi + +log "Compiling build-runfiles..." +# Clang on Linux requires libstdc++ +run_silent "${CXX}" -o ${OUTPUT_DIR}/build-runfiles -std=c++0x -l stdc++ src/main/tools/build-runfiles.cc + +log "Compiling process-wrapper..." +run_silent "${CC}" -o ${OUTPUT_DIR}/process-wrapper -std=c99 src/main/tools/process-wrapper.c + +cp src/main/tools/build_interface_so ${OUTPUT_DIR}/build_interface_so +cp src/main/tools/jdk.* ${OUTPUT_DIR} + +log "Creating Bazel self-extracting archive..." +TO_ZIP="libblaze.jar ${JNILIB} build-runfiles${EXE_EXT} process-wrapper${EXE_EXT} build_interface_so ${MSYS_DLLS} jdk.WORKSPACE jdk.BUILD" + +(cd ${OUTPUT_DIR}/ ; cat client ${TO_ZIP} | ${MD5SUM} | awk '{ print $1; }' > install_base_key) +(cd ${OUTPUT_DIR}/ ; echo "${JAVA_VERSION}" > java.version) +(cd ${OUTPUT_DIR}/ ; find . -type f | xargs -P 10 touch -t 198001010000) +(cd ${OUTPUT_DIR}/ ; zip $ZIPOPTS -q package.zip ${TO_ZIP} install_base_key java.version) +cat ${OUTPUT_DIR}/client ${OUTPUT_DIR}/package.zip > ${OUTPUT_DIR}/bazel +zip -qA ${OUTPUT_DIR}/bazel \ + || echo "(Non-critical error, ignore.)" + +chmod 755 ${OUTPUT_DIR}/bazel
diff --git a/scripts/bootstrap/init_workspace.sh b/scripts/bootstrap/init_workspace.sh new file mode 100755 index 0000000..fba6125 --- /dev/null +++ b/scripts/bootstrap/init_workspace.sh
@@ -0,0 +1,47 @@ +#!/bin/bash + +# Copyright 2015 Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Set-up the base workspace, currently used as package_path to provide +# the tools directory. + +# Create symlinks so we can use tools and examples from the base_workspace. +base_workspace=${WORKSPACE_DIR}/base_workspace +mkdir -p "$base_workspace" +rm -f "${base_workspace}/tools" && ln -s "$(pwd)/tools" "${base_workspace}/tools" +rm -f "${base_workspace}/third_party" && ln -s "$(pwd)/third_party" "${base_workspace}/third_party" +rm -f "${base_workspace}/examples" && ln -s "$(pwd)/examples" "${base_workspace}/examples" + +# Create a bazelrc file with the base_workspace directory in the package path. +bazelrc='build --package_path %workspace%:'${base_workspace} +bazelrc="${bazelrc}"$'\nfetch --package_path %workspace%:'${base_workspace} +bazelrc="${bazelrc}"$'\nquery --package_path %workspace%:'${base_workspace} +if [ -z "${HOME-}" ]; then + warning="$INFO No \$HOME variable set, cannot write .bazelrc file." + warning="$warning Consider adding $base_workspace to your package path" + display $warning +elif [ ! -f $HOME/.bazelrc ]; then + display "$INFO Creating a .bazelrc pointing to $base_workspace" + echo -e "$bazelrc" > $HOME/.bazelrc +else + while read rcline; do + if ! grep -q "$rcline" $HOME/.bazelrc; then + warning="$INFO You already have a .bazelrc. Make sure it contains the " + warning="$warning following package paths:\n\n$bazelrc\n\n" + display "$warning" + break + fi + done <<< "$bazelrc" +fi
diff --git a/site/contributing.md b/site/contributing.md index 224f072..5adf832 100644 --- a/site/contributing.md +++ b/site/contributing.md
@@ -82,45 +82,17 @@ resulting binary can be found at `bazel-bin/src/bazel`. In addition to the Bazel binary, you might want to build the various tools Bazel -uses: - -* For Java support - * JavaBuilder is the java compiler wrapper used by Bazel and its target can be - found at `//src/java_tools/buildjar:JavaBuilder_deploy.jar`. - * SingleJar is a tool to assemble a single jar composed of all classes from - all jar dependencies (build the `*_deploy.jar` files), it can be found at - `//src/java_tools/singlejar:SingleJar_deploy.jar`. - * ijar is a tool to extracts the class interfaces of jars and is a third - party software at `//third_party/ijar`. -* For Objective-C / iOS support - * actoolzip is a utility that runs OS X's actool and zips up its output for - further processing. It is currently compiled and placed into `tools/objc/` - by `compile.sh`. - * ibtoolzip is a utility that runs OS X's ibtool and zips up its output for - further processing. It is currently compiled and placed into `tools/objc/` - by `compile.sh`. - * momczip is a utility that runs OS X's momc and zips up its output for - further processing. It is currently compiled and placed into `tools/objc/` - by `compile.sh`. - * bundlemerge is a tool that can construct iOS bundles (such as .ipa files or - .bndl directories), including plist merging and zip creation. It is currently - compiled and placed into `tools/objc/` by `compile.sh`. - * plmerge is a tool used for merging plists. It is currently compiled and - placed into `tools/objc/` by `compile.sh`. - * xcodegen is a tool that assembles an Xcode project file matching Bazel build - targets. It is currently compiled and placed into `tools/objc/` by - `compile.sh`. - * iossim allows us to run iOS applications built by Bazel on Xcode's iOS - simulator and is third party software located at `//third_party/iossim` +uses. They are located in `//src/java_tools`, `//src/objc_tools` and +`//src/tools` and contains README files describing their respective +utility. When modifying Bazel, you want to make sure that the following still works: -* Bootstrap test with `sh bootstrap_test.sh all` after having removed the +* Bootstrap test with `sh compile.sh all` after having removed the `output` directory: it rebuilds Bazel with `./compile.sh`, Bazel with the `compile.sh` Bazel and Bazel with the Bazel-built binary. It compares if the constructed Bazel builts are identical and then run all bazel tests with - `bazel test //src/...`. -* ijar's tests with `bazel test //third_party/ijar/test/...` + `bazel test //src/... //third_party/ijar/...`. ### Debugging Bazel
diff --git a/src/BUILD b/src/BUILD index c2ab5b8..6a73011 100644 --- a/src/BUILD +++ b/src/BUILD
@@ -1,12 +1,5 @@ # Packaging -genrule( - name = "client-info-file", - outs = ["client_info"], - cmd = "touch $@", - executable = 1, -) - md5_cmd = "set -e -o pipefail && cat $(SRCS) | %s | awk '{ print $$1; }' > $@" # TODO(bazel-team): find a better way to handle dylib extensions. @@ -28,7 +21,6 @@ "//src/main/tools:build-runfiles", "//src/main/tools:process-wrapper", "//src/main/tools:namespace-sandbox", - "client_info", "//src/main/tools:build_interface_so", ], outs = ["install_base_key"], @@ -77,14 +69,13 @@ "//src/main/tools:process-wrapper", "//src/main/tools:jdk-support", "//src/main/tools:namespace-sandbox", - "client_info", "//src/main/tools:build_interface_so", "install_base_key", ":java-version", ], outs = ["package.zip"], # Terrible hack to remove timestamps in the zip file - cmd = "mkdir $(@D)/package-zip && " + + cmd = "mkdir -p $(@D)/package-zip && " + "cp $(SRCS) $(@D)/package-zip && " + "touch -t 198001010000.00 $(@D)/package-zip/* && " + "zip -qj $@ $(@D)/package-zip/* && " +
diff --git a/third_party/ijar/BUILD b/third_party/ijar/BUILD index 2224dd6..5f22b67 100644 --- a/third_party/ijar/BUILD +++ b/third_party/ijar/BUILD
@@ -23,6 +23,7 @@ cc_binary( name = "zipper", srcs = ["zip_main.cc"], + visibility = ["//visibility:public"], deps = [":zip"], ) @@ -32,5 +33,6 @@ "classfile.cc", "ijar.cc", ], + visibility = ["//visibility:public"], deps = [":zip"], )