Gather a bit more information from sysinfo()
[hiphop-php.git] / hphp / hack / scripts / build_and_run.sh
blobbc26eb567616706adb2035cf0fbfb937dcaeb187
1 #!/bin/bash
2 # Copyright (c) 2015, Facebook, Inc.
3 # All rights reserved.
5 # This source code is licensed under the MIT license found in the
6 # LICENSE file in the "hack" directory of this source tree.
8 set -e
9 set -x
11 SCRIPT_DIR="$(dirname "$0")"
12 FBCODE_ROOT="$(realpath "${SCRIPT_DIR}/../../../")"
13 HPHP_ROOT="${FBCODE_ROOT}/hphp"
14 HACK_ROOT="${FBCODE_ROOT}/hphp/hack"
15 FB_DUNE_BUILD_DIR="${HACK_ROOT}/facebook/redirect/dune_build"
17 HACK_SUBDIR="$1"
18 TARGET="$2"
20 ARGS=($@)
21 ARGS=(${ARGS[@]:2})
23 function dune_build() {
24 # OCaml
25 if [ -e "${HACK_ROOT}/${HACK_SUBDIR}/${TARGET}.ml" ]; then
27 cd "${HACK_ROOT}"
28 "${DUNE}" build "${HACK_SUBDIR}/${TARGET}.exe"
30 exec "${DUNE_BUILD_DIR}/default/$HACK_SUBDIR/${TARGET}.exe" "${ARGS[@]}"
33 # Rust
34 if [ -e "${HACK_ROOT}/${HACK_SUBDIR}/${TARGET}.rs" ]; then
35 export CARGO_TARGET_DIR="${DUNE_BUILD_DIR}/cargo"
37 sed '/\/facebook\//d' "${HACK_ROOT}/.cargo/Cargo.toml.ocaml_build" > "${HACK_ROOT}/Cargo.toml"
38 cd "${HACK_ROOT}/${HACK_SUBDIR}"
39 "${CARGO}" build --bin "${TARGET}"
40 [ -e "${HACK_ROOT}/Cargo.toml" ] && rm "${HACK_ROOT}/Cargo.toml"
42 exec "${CARGO_TARGET_DIR}/debug/${TARGET}" "${ARGS[@]}"
46 cd "${FBCODE_ROOT}"
47 if [ -e "${HACK_ROOT}/facebook/dune.sh" ] && [ -e "${FB_DUNE_BUILD_DIR}" ]; then
48 # FB Dune
49 DUNE="${HACK_ROOT}/facebook/dune.sh" \
50 CARGO="${HACK_ROOT}/scripts/facebook/cargo.sh" \
51 DUNE_BUILD_DIR="${FB_DUNE_BUILD_DIR}"
52 dune_build
53 elif [ -e "${FBCODE_ROOT}/third-party/CMakeLists.txt" ]; then
54 # Open Source Dune
55 DUNE="dune" \
56 CARGO="cargo" \
57 dune_build
58 elif [ -e "${HPHP_ROOT}/facebook" ]; then
59 # FB Buck
60 exec buck run "//hphp/hack/${HACK_SUBDIR}:${TARGET}" -- "${ARGS[@]}"
61 else
62 echo "Couldn't determine build system"
63 exit 1