Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Copyright 2014 Google Inc. All rights reserved. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | set -o errexit |
| 18 | |
| 19 | cd "$(dirname "$0")" |
| 20 | |
| 21 | mkdir -p output/classes |
| 22 | mkdir -p output/test_classes |
| 23 | mkdir -p output/src |
| 24 | mkdir -p output/objs |
| 25 | mkdir -p output/native |
| 26 | |
| 27 | # May be passed in from outside. |
Kyle Moffett | 3fb7581 | 2015-04-23 17:24:02 +0000 | [diff] [blame] | 28 | CXXFLAGS="$CXXFLAGS" |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 29 | LDFLAGS="$LDFLAGS" |
| 30 | ZIPOPTS="$ZIPOPTS" |
| 31 | |
| 32 | # TODO: CC target architecture needs to match JAVA_HOME. |
| 33 | CC=${CC:-gcc} |
Kyle Moffett | 3fb7581 | 2015-04-23 17:24:02 +0000 | [diff] [blame] | 34 | CXX=${CXX:-g++} |
| 35 | CXXSTD="c++0x" |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 36 | |
Damien Martin-Guillerez | f925f07 | 2015-03-25 15:00:40 +0000 | [diff] [blame] | 37 | unset JAVA_TOOL_OPTIONS |
| 38 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 39 | JAVA_VERSION=${JAVA_VERSION:-"1.8"} |
| 40 | PLATFORM="$(uname -s | tr 'A-Z' 'a-z')" |
| 41 | ARCHIVE_CFLAGS=${ARCHIVE_CFLAGS:-""} |
| 42 | LDFLAGS=${LDFLAGS:-""} |
| 43 | |
| 44 | # Extension for executables (.exe on Windows). |
| 45 | EXE_EXT="" |
| 46 | |
| 47 | PROTO_FILES=$(ls src/main/protobuf/*.proto) |
| 48 | LIBRARY_JARS=$(find third_party -name *.jar | tr "\n" " ") |
| 49 | DIRS=$(echo src/{main/java,tools/xcode-common/java/com/google/devtools/build/xcode/{common,util}} output/src) |
| 50 | SINGLEJAR_DIRS="src/java_tools/singlejar/java src/main/java/com/google/devtools/build/lib/shell" |
| 51 | SINGLEJAR_LIBRARIES="third_party/guava/guava-18.0.jar third_party/jsr305/jsr-305.jar" |
Damien Martin-Guillerez | 07d744b | 2015-03-04 14:35:39 +0000 | [diff] [blame] | 52 | BUILDJAR_DIRS="src/java_tools/buildjar/java/com/google/devtools/build/buildjar output/src/com/google/devtools/build/lib/view/proto" |
Liam Miller-Cushon | 29e46b2 | 2015-05-18 19:50:00 +0000 | [diff] [blame] | 53 | BUILDJAR_LIBRARIES="third_party/error_prone/error_prone_core-2.0.2.jar third_party/guava/guava-18.0.jar third_party/protobuf/protobuf-2.5.0.jar third_party/jsr305/jsr-305.jar" |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 54 | |
| 55 | MSYS_DLLS="" |
| 56 | PATHSEP=":" |
| 57 | |
| 58 | function fail() { |
| 59 | echo "$1" >&2 |
| 60 | exit 1 |
| 61 | } |
| 62 | |
| 63 | function log() { |
| 64 | if [[ -z "${QUIETMODE}" ]]; then |
Kristina Chodorow | 45a2469 | 2015-05-18 15:30:30 +0000 | [diff] [blame] | 65 | echo -e "$1" >&2 |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 66 | fi |
| 67 | } |
| 68 | |
Kristina Chodorow | ac27114 | 2015-03-06 16:00:46 +0000 | [diff] [blame] | 69 | function write_fromhost_build() { |
| 70 | case "${PLATFORM}" in |
| 71 | linux) |
| 72 | cat << EOF > fromhost/BUILD |
| 73 | package(default_visibility = ["//visibility:public"]) |
| 74 | cc_library( |
| 75 | name = "libarchive", |
| 76 | srcs = [], |
| 77 | hdrs = [], |
| 78 | ) |
| 79 | EOF |
| 80 | |
| 81 | ;; |
| 82 | darwin) |
Kristina Chodorow | ac27114 | 2015-03-06 16:00:46 +0000 | [diff] [blame] | 83 | if [[ -e $homebrew_header ]]; then |
| 84 | rm -f fromhost/*.[ah] |
| 85 | touch fromhost/empty.c |
| 86 | # For use with Homebrew. |
| 87 | archive_dir=$(dirname $(dirname $homebrew_header)) |
Kristina Chodorow | ac27114 | 2015-03-06 16:00:46 +0000 | [diff] [blame] | 88 | cp ${archive_dir}/lib/*.a ${archive_dir}/include/*.h fromhost/ |
| 89 | cat << EOF > fromhost/BUILD |
| 90 | package(default_visibility = ["//visibility:public"]) |
| 91 | cc_library( |
| 92 | name = "libarchive", |
| 93 | srcs = glob(["*.a"]) + ["empty.c"], |
| 94 | hdrs = glob(["*.h"]), |
| 95 | includes = ["."], |
| 96 | linkopts = ["-lxml2", "-liconv", "-lbz2", "-lz", ], |
| 97 | ) |
| 98 | EOF |
| 99 | |
Kristina Chodorow | bdc2496 | 2015-03-18 15:17:12 +0000 | [diff] [blame] | 100 | elif [[ -e $macports_header ]]; then |
Kristina Chodorow | ac27114 | 2015-03-06 16:00:46 +0000 | [diff] [blame] | 101 | # For use with Macports. |
Allen Porter | e936383 | 2015-04-21 18:04:28 +0000 | [diff] [blame] | 102 | archive_dir=$(dirname $(dirname $macports_header)) |
| 103 | rm -f fromhost/*.[ah] |
Kristina Chodorow | ac27114 | 2015-03-06 16:00:46 +0000 | [diff] [blame] | 104 | touch fromhost/empty.c |
Volker Braun | 1f422dc | 2015-04-01 12:17:13 +0000 | [diff] [blame] | 105 | cp "${archive_dir}"/include/{archive.h,archive_entry.h} fromhost/ |
| 106 | cp "${archive_dir}"/lib/{libarchive,liblzo2,liblzma,libcharset,libbz2,libxml2,libz,libiconv}.a \ |
Kristina Chodorow | ac27114 | 2015-03-06 16:00:46 +0000 | [diff] [blame] | 107 | fromhost/ |
Kristina Chodorow | ac27114 | 2015-03-06 16:00:46 +0000 | [diff] [blame] | 108 | cat << EOF > fromhost/BUILD |
| 109 | package(default_visibility = ["//visibility:public"]) |
| 110 | cc_library( |
| 111 | name = "libarchive", |
| 112 | srcs = glob(["*.a"]) + ["empty.c"], |
| 113 | hdrs = glob(["*.h"]), |
| 114 | includes = ["."], |
| 115 | ) |
| 116 | EOF |
Kristina Chodorow | ac27114 | 2015-03-06 16:00:46 +0000 | [diff] [blame] | 117 | fi |
| 118 | esac |
| 119 | } |
| 120 | |
Kristina Chodorow | 8c6b3bb | 2015-04-09 19:05:34 +0000 | [diff] [blame] | 121 | # Create symlinks so we can use tools and examples from the base_workspace. |
| 122 | base_workspace=$(pwd)/base_workspace |
Kristina Chodorow | 633ecbd | 2015-04-28 18:36:43 +0000 | [diff] [blame] | 123 | mkdir -p "$base_workspace" |
| 124 | rm -f "${base_workspace}/tools" && ln -s "$(pwd)/tools" "${base_workspace}/tools" |
| 125 | rm -f "${base_workspace}/third_party" && ln -s "$(pwd)/third_party" "${base_workspace}/third_party" |
| 126 | rm -f "${base_workspace}/examples" && ln -s "$(pwd)/examples" "${base_workspace}/examples" |
Kristina Chodorow | 8c6b3bb | 2015-04-09 19:05:34 +0000 | [diff] [blame] | 127 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 128 | case "${PLATFORM}" in |
| 129 | linux) |
| 130 | # Sorry, no static linking on linux for now. |
| 131 | LDFLAGS="$(pkg-config libarchive --libs) -lrt $LDFLAGS" |
| 132 | JNILIB="libunix.so" |
| 133 | MD5SUM="md5sum" |
| 134 | # JAVA_HOME must point to a Java 8 installation. |
Damien Martin-Guillerez | e86ac8b | 2015-04-16 13:56:00 +0000 | [diff] [blame] | 135 | JAVA_HOME="${JAVA_HOME:-$(readlink -f $(which javac) | sed 's_/bin/javac__')}" |
Han-Wen Nienhuys | b5bac8b | 2015-04-09 17:50:19 +0000 | [diff] [blame] | 136 | PROTOC=${PROTOC:-third_party/protobuf/protoc.linux-i686} |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 137 | ;; |
Kristina Chodorow | ac27114 | 2015-03-06 16:00:46 +0000 | [diff] [blame] | 138 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 139 | darwin) |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 140 | JNILIB="libunix.dylib" |
| 141 | MD5SUM="md5" |
| 142 | if [[ -z "$JAVA_HOME" ]]; then |
Damien Martin-Guillerez | e86ac8b | 2015-04-16 13:56:00 +0000 | [diff] [blame] | 143 | JAVA_HOME="$(/usr/libexec/java_home -v 1.8+ 2> /dev/null)" \ |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 144 | || fail "Could not find JAVA_HOME, please ensure a JDK (version 1.8+) is installed." |
| 145 | fi |
| 146 | PROTOC=${PROTOC:-third_party/protobuf/protoc.darwin} |
Kristina Chodorow | bdc2496 | 2015-03-18 15:17:12 +0000 | [diff] [blame] | 147 | |
Damien Martin-Guillerez | 9a0dc1b | 2015-03-25 12:02:22 +0000 | [diff] [blame] | 148 | homebrew_header=$(ls -1 $(brew --prefix libarchive 2>/dev/null)/include/archive.h 2>/dev/null | head -n1) |
Volker Braun | 1f422dc | 2015-04-01 12:17:13 +0000 | [diff] [blame] | 149 | macports_header=$(port contents libarchive 2>/dev/null | grep /archive.h$ | xargs) |
Kristina Chodorow | bdc2496 | 2015-03-18 15:17:12 +0000 | [diff] [blame] | 150 | if [[ -e $homebrew_header ]]; then |
| 151 | # For use with Homebrew. |
| 152 | archive_dir=$(dirname $(dirname $homebrew_header)) |
| 153 | ARCHIVE_CFLAGS="-I${archive_dir}/include" |
| 154 | LDFLAGS="-L${archive_dir}/lib -larchive $LDFLAGS" |
| 155 | |
| 156 | elif [[ -e $macports_header ]]; then |
| 157 | # For use with Macports. |
| 158 | ARCHIVE_CFLAGS="-Ifromhost" |
| 159 | # Link libarchive statically |
| 160 | LDFLAGS="fromhost/libarchive.a fromhost/liblzo2.a \ |
| 161 | fromhost/liblzma.a fromhost/libcharset.a \ |
| 162 | fromhost/libbz2.a fromhost/libxml2.a \ |
| 163 | fromhost/libz.a fromhost/libiconv.a \ |
| 164 | $LDFLAGS" |
| 165 | else |
| 166 | log "WARNING: Could not find libarchive installation, proceeding bravely." |
| 167 | fi |
| 168 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 169 | ;; |
| 170 | |
| 171 | msys*|mingw*) |
| 172 | # Use a simplified platform string. |
| 173 | PLATFORM="mingw" |
| 174 | # Workaround for msys issue which causes omission of std::to_string. |
Kyle Moffett | 3fb7581 | 2015-04-23 17:24:02 +0000 | [diff] [blame] | 175 | CXXFLAGS="$CXXFLAGS -D_GLIBCXX_USE_C99 -D_GLIBCXX_USE_C99_DYNAMIC" |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 176 | LDFLAGS="-larchive ${LDFLAGS}" |
| 177 | MD5SUM="md5sum" |
| 178 | EXE_EXT=".exe" |
| 179 | PATHSEP=";" |
| 180 | # Find the latest available version of the SDK. |
| 181 | JAVA_HOME="${JAVA_HOME:-$(ls -d /c/Program\ Files/Java/jdk* | sort | tail -n 1)}" |
| 182 | # We do not use the JNI library on Windows. |
| 183 | JNILIB="" |
| 184 | PROTOC=${PROTOC:-protoc} |
| 185 | |
| 186 | # The newer version of GCC on msys is stricter and removes some important function |
| 187 | # declarations from the environment if using c++0x / c++11. |
Kyle Moffett | 3fb7581 | 2015-04-23 17:24:02 +0000 | [diff] [blame] | 188 | CXXSTD="gnu++11" |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 189 | |
| 190 | # Ensure that we are using the cygwin gcc, not the mingw64 gcc. |
| 191 | ${CC} -v 2>&1 | grep "Target: .*mingw.*" > /dev/null && |
| 192 | fail "mingw gcc detected. Please set CC to point to the msys/Cygwin gcc." |
Kyle Moffett | 3fb7581 | 2015-04-23 17:24:02 +0000 | [diff] [blame] | 193 | ${CXX} -v 2>&1 | grep "Target: .*mingw.*" > /dev/null && |
| 194 | fail "mingw g++ detected. Please set CXX to point to the msys/Cygwin g++." |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 195 | |
| 196 | MSYS_DLLS="msys-2.0.dll msys-gcc_s-seh-1.dll msys-stdc++-6.dll" |
| 197 | for dll in $MSYS_DLLS ; do |
| 198 | cp "/usr/bin/$dll" "output/$dll" |
| 199 | done |
| 200 | esac |
| 201 | |
Damien Martin-Guillerez | 24eaf9d | 2015-04-16 14:30:49 +0000 | [diff] [blame] | 202 | [[ -x "${PROTOC-}" ]] \ |
| 203 | || fail "Protobuf compiler not found in ${PROTOC-}" |
| 204 | |
Kristina Chodorow | bdc2496 | 2015-03-18 15:17:12 +0000 | [diff] [blame] | 205 | mkdir -p fromhost |
| 206 | if [ ! -f fromhost/BUILD ]; then |
| 207 | write_fromhost_build |
| 208 | fi |
| 209 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 210 | test -z "$JAVA_HOME" && fail "JDK not found, please set \$JAVA_HOME." |
| 211 | rm -f tools/jdk/jdk && ln -s "${JAVA_HOME}" tools/jdk/jdk |
| 212 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 213 | JAVAC="${JAVA_HOME}/bin/javac" |
| 214 | |
Damien Martin-Guillerez | e86ac8b | 2015-04-16 13:56:00 +0000 | [diff] [blame] | 215 | [[ -x "${JAVAC}" ]] \ |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 216 | || fail "JAVA_HOME ($JAVA_HOME) is not a path to a working JDK." |
| 217 | |
Damien Martin-Guillerez | e86ac8b | 2015-04-16 13:56:00 +0000 | [diff] [blame] | 218 | JAVAC_VERSION=$("${JAVAC}" -version 2>&1) |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 219 | [[ "$JAVAC_VERSION" =~ ^"javac 1"\.([89]|[1-9][0-9]).*$ ]] \ |
| 220 | || fail "JDK version is lower than 1.8, please set \$JAVA_HOME." |
| 221 | |
| 222 | JAR="${JAVA_HOME}/bin/jar" |
| 223 | |
| 224 | BLAZE_CC_FILES=( |
| 225 | src/main/cpp/blaze_startup_options.cc |
| 226 | src/main/cpp/blaze_startup_options_common.cc |
| 227 | src/main/cpp/blaze_util.cc |
| 228 | src/main/cpp/blaze_util_${PLATFORM}.cc |
| 229 | src/main/cpp/blaze.cc |
| 230 | src/main/cpp/option_processor.cc |
Thiago Farina | 241f46c | 2015-04-13 14:33:30 +0000 | [diff] [blame] | 231 | src/main/cpp/util/errors.cc |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 232 | src/main/cpp/util/file.cc |
| 233 | src/main/cpp/util/md5.cc |
| 234 | src/main/cpp/util/numbers.cc |
Thiago Farina | 241f46c | 2015-04-13 14:33:30 +0000 | [diff] [blame] | 235 | src/main/cpp/util/port.cc |
| 236 | src/main/cpp/util/strings.cc |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 237 | ) |
| 238 | |
| 239 | NATIVE_CC_FILES=( |
| 240 | src/main/cpp/util/md5.cc |
| 241 | src/main/native/localsocket.cc |
| 242 | src/main/native/process.cc |
| 243 | src/main/native/unix_jni.cc |
| 244 | src/main/native/unix_jni_${PLATFORM}.cc |
| 245 | ) |
| 246 | |
| 247 | IJAR_CC_FILES=( |
| 248 | third_party/ijar/ijar.cc |
| 249 | third_party/ijar/zip.cc |
| 250 | third_party/ijar/classfile.cc |
| 251 | ) |
| 252 | |
| 253 | # Compiles java classes. |
| 254 | function java_compilation() { |
| 255 | name=$1 |
| 256 | directories=$2 |
| 257 | library_jars=$3 |
| 258 | output=$4 |
| 259 | |
| 260 | classpath=${library_jars// /$PATHSEP}:$5 |
| 261 | sourcepath=${directories// /$PATHSEP} |
| 262 | |
| 263 | tmp="$(mktemp -d ${TMPDIR:-/tmp}/bazel.XXXXXXXX)" |
| 264 | paramfile="${tmp}/param" |
| 265 | errfile="${tmp}/err" |
| 266 | |
| 267 | mkdir -p "${output}/classes" |
| 268 | |
| 269 | trap "cat \"$errfile\"; rm -f \"$paramfile\" \"$errfile\"; rmdir \"$tmp\"" EXIT |
| 270 | |
| 271 | # Compile .java files (incl. generated ones) using javac |
| 272 | log "Compiling $name code..." |
| 273 | find ${directories} -name "*.java" > "$paramfile" |
| 274 | |
| 275 | if [ ! -z "$BAZEL_DEBUG_JAVA_COMPILATION" ]; then |
| 276 | echo "directories=${directories}" >&2 |
| 277 | echo "classpath=${classpath}" >&2 |
| 278 | echo "sourcepath=${sourcepath}" >&2 |
| 279 | echo "libraries=${library_jars}" >&2 |
| 280 | echo "output=${output}/classes" >&2 |
| 281 | echo "List of compiled files:" >&2 |
| 282 | cat "$paramfile" >&2 |
| 283 | fi |
| 284 | |
| 285 | "${JAVAC}" -classpath "${classpath}" -sourcepath "${sourcepath}" \ |
| 286 | -d "${output}/classes" -source "$JAVA_VERSION" -target "$JAVA_VERSION" \ |
| 287 | "@${paramfile}" &> "$errfile" || |
| 288 | exit $? |
| 289 | trap - EXIT |
| 290 | rm "$paramfile" "$errfile" |
| 291 | rmdir "$tmp" |
| 292 | |
| 293 | log "Extracting helper classes for $name..." |
| 294 | for f in ${library_jars} ; do |
| 295 | unzip -qn ${f} -d "${output}/classes" |
| 296 | done |
| 297 | } |
| 298 | |
| 299 | # Create the deploy JAR |
| 300 | function create_deploy_jar() { |
| 301 | name=$1 |
| 302 | mainClass=$2 |
| 303 | output=$3 |
| 304 | shift 3 |
| 305 | packages="" |
| 306 | for i in $output/classes/*; do |
| 307 | package=$(basename $i) |
| 308 | if [[ "$package" != "META-INF" ]]; then |
| 309 | packages="$packages -C $output/classes $package" |
| 310 | fi |
| 311 | done |
| 312 | |
| 313 | log "Creating $name.jar..." |
| 314 | echo "Main-Class: $mainClass" > $output/MANIFEST.MF |
| 315 | "$JAR" cmf $output/MANIFEST.MF $output/$name.jar $packages "$@" |
| 316 | } |
| 317 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 318 | function cc_compile() { |
| 319 | local OBJDIR=$1 |
| 320 | shift |
| 321 | mkdir -p "output/${OBJDIR}" |
| 322 | for FILE in "$@"; do |
| 323 | if [[ ! "${FILE}" =~ ^-.*$ ]]; then |
| 324 | local OBJ=$(basename "${FILE}").o |
Kyle Moffett | 3fb7581 | 2015-04-23 17:24:02 +0000 | [diff] [blame] | 325 | "${CXX}" \ |
Han-Wen Nienhuys | 36fbe63 | 2015-04-21 13:58:08 +0000 | [diff] [blame] | 326 | -I. \ |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 327 | ${ARCHIVE_CFLAGS} \ |
| 328 | ${CFLAGS} \ |
Kyle Moffett | 3fb7581 | 2015-04-23 17:24:02 +0000 | [diff] [blame] | 329 | -std=$CXXSTD \ |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 330 | -c \ |
| 331 | -DBLAZE_JAVA_CPU=\"k8\" \ |
| 332 | -DBLAZE_OPENSOURCE=1 \ |
| 333 | -o "output/${OBJDIR}/${OBJ}" \ |
| 334 | "${FILE}" |
| 335 | fi |
| 336 | done |
| 337 | } |
| 338 | |
| 339 | function cc_link() { |
| 340 | local OBJDIR=$1 |
| 341 | local OUTPUT=$2 |
| 342 | shift 2 |
| 343 | local FILES=() |
| 344 | for FILE in "$@"; do |
| 345 | local OBJ=$(basename "${FILE}").o |
| 346 | FILES+=("output/${OBJDIR}/${OBJ}") |
| 347 | done |
Kyle Moffett | 3fb7581 | 2015-04-23 17:24:02 +0000 | [diff] [blame] | 348 | "${CXX}" -o ${OUTPUT} "${FILES[@]}" -lstdc++ ${LDFLAGS} |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | function cc_build() { |
| 352 | local NAME=$1 |
| 353 | local OBJDIR=$2 |
| 354 | local OUTPUT=$3 |
| 355 | shift 3 |
| 356 | log "Compiling ${NAME} .cc files..." |
| 357 | cc_compile "${OBJDIR}" "$@" |
| 358 | log "Linking ${NAME}..." |
| 359 | cc_link "${OBJDIR}" "${OUTPUT}" "$@" |
| 360 | } |
| 361 | |
Daniel Wagner-Hall | 13ba331 | 2015-03-20 05:45:45 +0000 | [diff] [blame] | 362 | if [ -z "${BAZEL_SKIP_JAVA_COMPILATION}" ]; then |
| 363 | log "Compiling Java stubs for protocol buffers..." |
| 364 | for f in $PROTO_FILES ; do |
| 365 | "${PROTOC}" -Isrc/main/protobuf/ --java_out=output/src "$f" |
| 366 | done |
| 367 | |
| 368 | java_compilation "Bazel Java" "$DIRS" "$LIBRARY_JARS" "output" |
| 369 | |
Damien Martin-Guillerez | a0a7968 | 2015-04-20 09:44:08 +0000 | [diff] [blame] | 370 | # help files: all non java and BUILD files in src/main/java. |
| 371 | for i in $(find src/main/java -type f -a \! -name '*.java' -a \! -name 'BUILD' | sed 's|src/main/java/||'); do |
Daniel Wagner-Hall | 13ba331 | 2015-03-20 05:45:45 +0000 | [diff] [blame] | 372 | mkdir -p $(dirname output/classes/$i) |
| 373 | cp src/main/java/$i output/classes/$i |
| 374 | done |
| 375 | |
Damien Martin-Guillerez | 7d429ac | 2015-05-20 14:55:57 +0000 | [diff] [blame] | 376 | # build-data.properties |
| 377 | git_version="non-git" |
| 378 | if [ -x "$(which git || true)" ] && [ -d .git ]; then |
| 379 | git_version=$(git log -1 --oneline | cut -d " " -f 1 2>/dev/null || \ |
| 380 | echo "non-git") |
| 381 | fi |
| 382 | cat >output/classes/build-data.properties <<EOF |
| 383 | build.time=$(date) |
| 384 | build.label=bazel-compile.sh-${git_version} |
| 385 | EOF |
Daniel Wagner-Hall | 13ba331 | 2015-03-20 05:45:45 +0000 | [diff] [blame] | 386 | create_deploy_jar "libblaze" "com.google.devtools.build.lib.bazel.BazelMain" \ |
| 387 | output third_party/javascript |
| 388 | fi |
| 389 | |
| 390 | if [ -z "${BAZEL_SKIP_SINGLEJAR_COMPILATION}" ]; then |
| 391 | # Compile singlejar, a jar suitable for deployment. |
| 392 | java_compilation "SingleJar tool" "$SINGLEJAR_DIRS" "$SINGLEJAR_LIBRARIES" \ |
| 393 | "output/singlejar" |
| 394 | |
| 395 | create_deploy_jar "SingleJar_deploy" \ |
| 396 | "com.google.devtools.build.singlejar.SingleJar" "output/singlejar" |
| 397 | mkdir -p tools/jdk |
| 398 | cp -f output/singlejar/SingleJar_deploy.jar tools/jdk |
| 399 | fi |
| 400 | |
| 401 | if [ -z "${BAZEL_SKIP_BUILDJAR_COMPILATION}" ]; then |
| 402 | # Compile buildjar, a wrapper around javac. |
| 403 | java_compilation "JavaBuilder tool" "$BUILDJAR_DIRS" "$BUILDJAR_LIBRARIES" \ |
| 404 | "output/buildjar" $JAVA_HOME/lib/tools.jar |
| 405 | |
| 406 | create_deploy_jar "JavaBuilder_deploy" \ |
| 407 | "com.google.devtools.build.buildjar.BazelJavaBuilder" "output/buildjar" |
| 408 | mkdir -p tools/jdk |
| 409 | cp -f output/buildjar/JavaBuilder_deploy.jar tools/jdk |
| 410 | fi |
| 411 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 412 | cc_build "client" "objs" "output/client" ${BLAZE_CC_FILES[@]} |
| 413 | |
Damien Martin-Guillerez | bfcb7f3 | 2015-02-19 13:18:11 +0000 | [diff] [blame] | 414 | LDFLAGS="$LDFLAGS -lz" cc_build "ijar" "ijar" "tools/jdk/ijar" ${IJAR_CC_FILES[@]} |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 415 | |
| 416 | if [ ! -z "$JNILIB" ] ; then |
| 417 | log "Compiling JNI libraries..." |
| 418 | for FILE in "${NATIVE_CC_FILES[@]}"; do |
| 419 | OUT=$(basename "${FILE}").o |
Kyle Moffett | 3fb7581 | 2015-04-23 17:24:02 +0000 | [diff] [blame] | 420 | "${CXX}" \ |
Han-Wen Nienhuys | 36fbe63 | 2015-04-21 13:58:08 +0000 | [diff] [blame] | 421 | -I . \ |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 422 | -I "${JAVA_HOME}/include/" \ |
| 423 | -I "${JAVA_HOME}/include/${PLATFORM}" \ |
Kyle Moffett | 3fb7581 | 2015-04-23 17:24:02 +0000 | [diff] [blame] | 424 | -std=$CXXSTD \ |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 425 | -fPIC \ |
| 426 | -c \ |
| 427 | -D_JNI_IMPLEMENTATION_ \ |
| 428 | -DBLAZE_JAVA_CPU=\"k8\" \ |
| 429 | -DBLAZE_OPENSOURCE=1 \ |
| 430 | -o "output/native/${OUT}" \ |
| 431 | "${FILE}" |
| 432 | done |
| 433 | |
| 434 | log "Linking ${JNILIB}..." |
Kyle Moffett | 3fb7581 | 2015-04-23 17:24:02 +0000 | [diff] [blame] | 435 | "${CXX}" -o output/${JNILIB} $JNI_LD_ARGS -shared output/native/*.o -l stdc++ |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 436 | fi |
| 437 | |
| 438 | log "Compiling build-runfiles..." |
| 439 | # Clang on Linux requires libstdc++ |
Kyle Moffett | 3fb7581 | 2015-04-23 17:24:02 +0000 | [diff] [blame] | 440 | "${CXX}" -o output/build-runfiles -std=c++0x -l stdc++ src/main/tools/build-runfiles.cc |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 441 | |
| 442 | log "Compiling process-wrapper..." |
| 443 | "${CC}" -o output/process-wrapper -std=c99 src/main/tools/process-wrapper.c |
| 444 | if [[ $PLATFORM == "linux" ]]; then |
| 445 | log "Compiling sandbox..." |
| 446 | "${CC}" -o output/namespace-sandbox -std=c99 src/main/tools/namespace-sandbox.c |
| 447 | fi |
| 448 | |
| 449 | cp src/main/tools/build_interface_so output/build_interface_so |
Kristina Chodorow | b5ecdab | 2015-03-16 17:55:04 +0000 | [diff] [blame] | 450 | cp src/main/tools/jdk.* output |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 451 | |
| 452 | touch output/client_info |
| 453 | chmod 755 output/client_info |
| 454 | |
| 455 | log "Creating Bazel self-extracting archive..." |
Kristina Chodorow | b5ecdab | 2015-03-16 17:55:04 +0000 | [diff] [blame] | 456 | TO_ZIP="libblaze.jar ${JNILIB} build-runfiles${EXE_EXT} process-wrapper${EXE_EXT} client_info build_interface_so ${MSYS_DLLS} jdk.WORKSPACE jdk.BUILD" |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 457 | if [[ $PLATFORM == "linux" ]]; then |
| 458 | TO_ZIP="$TO_ZIP namespace-sandbox${EXE_EXT}" |
| 459 | fi |
| 460 | |
| 461 | (cd output/ ; cat client ${TO_ZIP} | ${MD5SUM} | awk '{ print $1; }' > install_base_key) |
| 462 | (cd output/ ; echo "${JAVA_VERSION}" > java.version) |
| 463 | (cd output/ ; find . -type f | xargs -P 10 touch -t 198001010000) |
| 464 | (cd output/ ; zip $ZIPOPTS -q package.zip ${TO_ZIP} install_base_key java.version) |
| 465 | cat output/client output/package.zip > output/bazel |
| 466 | zip -qA output/bazel \ |
| 467 | || echo "(Non-critical error, ignore.)" |
| 468 | |
| 469 | chmod 755 output/bazel |
Daniel Wagner-Hall | b92fbb0 | 2015-03-20 19:50:42 +0000 | [diff] [blame] | 470 | |
Thiago Farina | dd02a92 | 2015-05-14 20:17:45 +0000 | [diff] [blame] | 471 | if [[ $PLATFORM == "darwin" ]]; then |
| 472 | log "Creating objc helper tools..." |
Daniel Wagner-Hall | b92fbb0 | 2015-03-20 19:50:42 +0000 | [diff] [blame] | 473 | |
Thiago Farina | dd02a92 | 2015-05-14 20:17:45 +0000 | [diff] [blame] | 474 | zip_common="src/tools/xcode-common/java/com/google/devtools/build/xcode/zip src/tools/xcode-common/java/com/google/devtools/build/xcode/util src/java_tools/singlejar/java/com/google/devtools/build/zip src/java_tools/singlejar/java/com/google/devtools/build/singlejar/ZipCombiner.java src/java_tools/singlejar/java/com/google/devtools/build/singlejar/ZipEntryFilter.java src/java_tools/singlejar/java/com/google/devtools/build/singlejar/CopyEntryFilter.java" |
Daniel Wagner-Hall | b92fbb0 | 2015-03-20 19:50:42 +0000 | [diff] [blame] | 475 | |
Thiago Farina | dd02a92 | 2015-05-14 20:17:45 +0000 | [diff] [blame] | 476 | java_compilation "actoolzip" "src/tools/xcode-common/java/com/google/devtools/build/xcode/actoolzip src/tools/xcode-common/java/com/google/devtools/build/xcode/zippingoutput ${zip_common}" "third_party/guava/guava-18.0.jar third_party/jsr305/jsr-305.jar" "output/actoolzip" |
| 477 | create_deploy_jar "precomp_actoolzip_deploy" "com.google.devtools.build.xcode.actoolzip.ActoolZip" "output/actoolzip" |
Daniel Wagner-Hall | b92fbb0 | 2015-03-20 19:50:42 +0000 | [diff] [blame] | 478 | |
Thiago Farina | dd02a92 | 2015-05-14 20:17:45 +0000 | [diff] [blame] | 479 | java_compilation "ibtoolzip" "src/tools/xcode-common/java/com/google/devtools/build/xcode/ibtoolzip src/tools/xcode-common/java/com/google/devtools/build/xcode/zippingoutput ${zip_common}" "third_party/guava/guava-18.0.jar third_party/jsr305/jsr-305.jar" "output/ibtoolzip" |
| 480 | create_deploy_jar "precomp_ibtoolzip_deploy" "com.google.devtools.build.xcode.ibtoolzip.IbtoolZip" "output/ibtoolzip" |
Daniel Wagner-Hall | b92fbb0 | 2015-03-20 19:50:42 +0000 | [diff] [blame] | 481 | |
Thiago Farina | dd02a92 | 2015-05-14 20:17:45 +0000 | [diff] [blame] | 482 | java_compilation "momczip" "src/objc_tools/momczip/java/com/google/devtools/build/xcode/momczip src/tools/xcode-common/java/com/google/devtools/build/xcode/zippingoutput ${zip_common}" "third_party/guava/guava-18.0.jar third_party/jsr305/jsr-305.jar" "output/momczip" |
| 483 | create_deploy_jar "precomp_momczip_deploy" "com.google.devtools.build.xcode.momczip.MomcZip" "output/momczip" |
Daniel Wagner-Hall | b92fbb0 | 2015-03-20 19:50:42 +0000 | [diff] [blame] | 484 | |
Thiago Farina | dd02a92 | 2015-05-14 20:17:45 +0000 | [diff] [blame] | 485 | java_compilation "bundlemerge" "src/objc_tools/bundlemerge/java/com/google/devtools/build/xcode/bundlemerge src/objc_tools/plmerge/java/com/google/devtools/build/xcode/plmerge src/tools/xcode-common/java/com/google/devtools/build/xcode/common output/src/com/google/devtools/build/xcode/bundlemerge/proto/BundleMergeProtos.java ${zip_common} third_party/java/dd_plist src/main/java/com/google/devtools/common/options" "third_party/guava/guava-18.0.jar third_party/jsr305/jsr-305.jar third_party/protobuf/protobuf-2.5.0.jar" "output/bundlemerge" |
| 486 | create_deploy_jar "precomp_bundlemerge_deploy" "com.google.devtools.build.xcode.bundlemerge.BundleMerge" "output/bundlemerge" |
Daniel Wagner-Hall | b92fbb0 | 2015-03-20 19:50:42 +0000 | [diff] [blame] | 487 | |
Thiago Farina | dd02a92 | 2015-05-14 20:17:45 +0000 | [diff] [blame] | 488 | java_compilation "plmerge" "src/objc_tools/plmerge/java/com/google/devtools/build/xcode/plmerge src/tools/xcode-common/java/com/google/devtools/build/xcode/common third_party/java/dd_plist src/main/java/com/google/devtools/common/options ${zip_common}" "third_party/guava/guava-18.0.jar third_party/jsr305/jsr-305.jar" "output/plmerge" |
| 489 | create_deploy_jar "precomp_plmerge_deploy" "com.google.devtools.build.xcode.plmerge.PlMerge" "output/plmerge" |
Daniel Wagner-Hall | b92fbb0 | 2015-03-20 19:50:42 +0000 | [diff] [blame] | 490 | |
Thiago Farina | dd02a92 | 2015-05-14 20:17:45 +0000 | [diff] [blame] | 491 | java_compilation "xcodegen" "src/objc_tools/xcodegen/java/com/google/devtools/build/xcode/xcodegen src/main/java/com/google/devtools/common/options output/src/com/google/devtools/build/xcode/xcodegen/proto/XcodeGenProtos.java third_party/java/buck-ios-support/java src/objc_tools/plmerge/java/com/google/devtools/build/xcode/plmerge src/tools/xcode-common/java/com/google/devtools/build/xcode/common src/tools/xcode-common/java/com/google/devtools/build/xcode/util third_party/java/dd_plist" "third_party/guava/guava-18.0.jar third_party/jsr305/jsr-305.jar third_party/protobuf/protobuf-2.5.0.jar" "output/xcodegen" |
| 492 | create_deploy_jar "precomp_xcodegen_deploy" "com.google.devtools.build.xcode.xcodegen.XcodeGen" "output/xcodegen" |
Daniel Wagner-Hall | b92fbb0 | 2015-03-20 19:50:42 +0000 | [diff] [blame] | 493 | |
Thiago Farina | dd02a92 | 2015-05-14 20:17:45 +0000 | [diff] [blame] | 494 | cp -f output/actoolzip/precomp_actoolzip_deploy.jar output/ibtoolzip/precomp_ibtoolzip_deploy.jar output/momczip/precomp_momczip_deploy.jar output/bundlemerge/precomp_bundlemerge_deploy.jar output/plmerge/precomp_plmerge_deploy.jar output/xcodegen/precomp_xcodegen_deploy.jar tools/objc/ |
| 495 | fi |
Daniel Wagner-Hall | b92fbb0 | 2015-03-20 19:50:42 +0000 | [diff] [blame] | 496 | |
Kristina Chodorow | 8c6b3bb | 2015-04-09 19:05:34 +0000 | [diff] [blame] | 497 | # Create a bazelrc file with the base_workspace directory in the package path. |
Kristina Chodorow | 45a2469 | 2015-05-18 15:30:30 +0000 | [diff] [blame] | 498 | bazelrc='build --package_path %workspace%:'${base_workspace} |
| 499 | bazelrc="${bazelrc}"$'\nfetch --package_path %workspace%:'${base_workspace} |
| 500 | bazelrc="${bazelrc}"$'\nquery --package_path %workspace%:'${base_workspace} |
Damien Martin-Guillerez | feb0939 | 2015-05-12 14:48:12 +0000 | [diff] [blame] | 501 | if [ -z "${HOME-}" ]; then |
| 502 | warning="No \$HOME variable set, cannot write .bazelrc file." |
| 503 | warning="$warning Consider adding $base_workspace to your package path" |
| 504 | log $warning |
| 505 | elif [ ! -f $HOME/.bazelrc ]; then |
Kristina Chodorow | 8c6b3bb | 2015-04-09 19:05:34 +0000 | [diff] [blame] | 506 | log "Creating a .bazelrc pointing to $base_workspace" |
Kristina Chodorow | 45a2469 | 2015-05-18 15:30:30 +0000 | [diff] [blame] | 507 | echo "$bazelrc" > $HOME/.bazelrc |
Kristina Chodorow | 06f446a | 2015-04-06 15:54:03 +0000 | [diff] [blame] | 508 | else |
Kristina Chodorow | 45a2469 | 2015-05-18 15:30:30 +0000 | [diff] [blame] | 509 | while read rcline; do |
| 510 | if ! grep -q "$rcline" $HOME/.bazelrc; then |
| 511 | warning="You already have a .bazelrc. Make sure it contains the " |
| 512 | warning="$warning following package paths:\n$bazelrc" |
| 513 | log "$warning" |
| 514 | break |
| 515 | fi |
| 516 | done <<< "$bazelrc" |
Kristina Chodorow | 06f446a | 2015-04-06 15:54:03 +0000 | [diff] [blame] | 517 | fi |
| 518 | |
Kristina Chodorow | 4fa24ee | 2015-05-13 17:08:29 +0000 | [diff] [blame] | 519 | # Run "bazel fetch" to bring in the JDK (so users don't have to). |
| 520 | ${PWD}/output/bazel fetch //... |
| 521 | |
Laurent Le Brun | 627a63d | 2015-03-25 13:35:51 +0000 | [diff] [blame] | 522 | log "Build successful! Binary is here: ${PWD}/output/bazel" |