Skip to content

Commit

Permalink
Bug 1313615 - opt and m32 build args and default to system architectu…
Browse files Browse the repository at this point in the history
…re, r=ttaubert

--HG--
extra : rebase_source : 7a7c42e549da1207a01a6628dd5ca9044220a9d7
extra : amend_source : 65b905f28d0e80cbd1ee9f4a520bc1bac3fbf643
  • Loading branch information
franziskuskiefer committed Oct 26, 2016
1 parent 2db6654 commit 8762475
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 42 deletions.
4 changes: 2 additions & 2 deletions automation/taskcluster/graph/src/extend.js
Expand Up @@ -104,7 +104,7 @@ export default async function main() {
"-c",
"bin/checkout.sh && nss/automation/taskcluster/scripts/build_gyp.sh"
],
env: {USE_64: "1"},
env: {USE_64: "1"}, // This is only necessary for tests to work.
platform: "linux64",
collection: "gyp",
image: LINUX_IMAGE
Expand Down Expand Up @@ -241,7 +241,7 @@ async function scheduleFuzzing() {
UBSAN_OPTIONS: "print_stacktrace=1",
CC: "clang",
CCC: "clang++",
USE_64: "1"
USE_64: "1" // This is only necessary for tests to work.
},
platform: "linux64",
collection: "fuzz",
Expand Down
96 changes: 56 additions & 40 deletions build.sh
Expand Up @@ -11,6 +11,7 @@ show_help() {
cat << EOF
Usage: ${0##*/} [-hcgv] [-j <n>] [--test] [--fuzz] [--scan-build[=output]]
[-m32] [--opt|-o]
This script builds NSS with gyp and ninja.
Expand All @@ -24,89 +25,104 @@ NSS build tool options:
-g force a rebuild of gyp (and NSPR, because why not)
-j <n> run at most <n> concurrent jobs
-v verbose build
-m32 do a 32-bit build on a 64-bit system
--test ignore map files and export everything we have
--fuzz enable fuzzing mode. this always enables test builds
--scan-build run the build with scan-build (scan-build has to be in the path)
--scan-build=/out/path sets the output path for scan-build
--opt|-o do an opt build
EOF
}

CWD=$(cd $(dirname $0); pwd -P)
OBJ_DIR=$(make -s -C "$CWD" platform)
DIST_DIR="$CWD/../dist/$OBJ_DIR"

if [ -n "$CCC" ] && [ -z "$CXX" ]; then
export CXX="$CCC"
fi

opt_build=0
build_64=0

# try to guess sensible defaults
arch=$(uname -m)
if [ "$arch" = "x86_64" -o "$arch" = "aarch64" ]; then
build_64=1
fi

gyp_params=()
ninja_params=()
scanbuild=()
nspr_env=()

# parse command line arguments
GYP_PARAMS=()
NINJA_PARAMS=()
SCANBUILD=()
while [ $# -gt 0 ]; do
case $1 in
-c) CLEAN=1 ;;
-g) REBUILD_GYP=1 ;;
-j) NINJA_PARAMS+=(-j "$2"); shift ;;
-v) NINJA_PARAMS+=(-v) ;;
--test) GYP_PARAMS+=(-Dtest_build=1) ;;
--fuzz) GYP_PARAMS+=(-Dtest_build=1 -Dfuzz=1) ;;
--scan-build) SCANBUILD=(scan-build) ;;
--scan-build=?*) SCANBUILD=(scan-build -o "${1#*=}") ;;
*)
show_help
exit
;;
-c) clean=1 ;;
-g) rebuild_gyp=1 ;;
-j) ninja_params+=(-j "$2"); shift ;;
-v) ninja_params+=(-v) ;;
--test) gyp_params+=(-Dtest_build=1) ;;
--fuzz) gyp_params+=(-Dtest_build=1 -Dfuzz=1) ;;
--scan-build) scanbuild=(scan-build) ;;
--scan-build=?*) scanbuild=(scan-build -o "${1#*=}") ;;
--opt|-o) opt_build=1; nspr_env+=(BUILD_OPT=1) ;;
-m32|--m32) build_64=0 ;;
*) show_help; exit ;;
esac
shift
done

# set paths
cwd=$(cd $(dirname $0); pwd -P)
obj_dir=$(USE_64=$build_64 make -s -C "$cwd" platform)
dist_dir="$cwd/../dist/$obj_dir"

# -c = clean first
if [ "$CLEAN" = 1 ]; then
rm -rf "$CWD/out"
if [ "$clean" = 1 ]; then
rm -rf "$cwd/out"
rm -rf "$cwd/../nspr/$obj_dir"
fi

if [ "$BUILD_OPT" = "1" ]; then
TARGET=Release
if [ "$opt_build" = "1" ]; then
target=Release
else
TARGET=Debug
target=Debug
fi
if [ "$USE_64" == "1" ]; then
TARGET="${TARGET}_x64"
if [ "$build_64" == "1" ]; then
target="${target}_x64"
nspr_env+=(USE_64=1)
else
GYP_PARAMS+=(-Dtarget_arch=ia32)
gyp_params+=(-Dtarget_arch=ia32)
fi
TARGET_DIR="$CWD/out/$TARGET"
target_dir="$cwd/out/$target"

# figure out scan-build string
if [ "${#SCANBUILD[@]}" -gt 0 ]; then
# figure out the scan-build string
if [ "${#scanbuild[@]}" -gt 0 ]; then
if [ -n "$CC" ]; then
SCANBUILD+=(--use-cc="$CC")
scanbuild+=(--use-cc="$CC")
fi
if [ -n "$CCC" ]; then
SCANBUILD+=(--use-c++="$CCC")
scanbuild+=(--use-c++="$CCC")
fi
fi

# These steps can take a while, so don't overdo them.
# Force a redo with -g.
if [ "$REBUILD_GYP" = 1 -o ! -d "$TARGET_DIR" ]; then
if [ "$rebuild_gyp" = 1 -o ! -d "$target_dir" ]; then
# Build NSPR.
make -C "$CWD" NSS_GYP=1 install_nspr
make "${nspr_env[@]}" -C "$cwd" NSS_GYP=1 install_nspr

# Run gyp.
PKG_CONFIG_PATH="$CWD/../nspr/$OBJ_DIR/config" \
"${SCANBUILD[@]}" gyp -f ninja "${GYP_PARAMS[@]}" --depth="$CWD" \
--generator-output="." "$CWD/nss.gyp"
PKG_CONFIG_PATH="$cwd/../nspr/$obj_dir/config" \
"${scanbuild[@]}" gyp -f ninja "${gyp_params[@]}" --depth="$cwd" \
--generator-output="." "$cwd/nss.gyp"
fi

# Run ninja.
if which ninja >/dev/null 2>&1; then
NINJA=(ninja)
ninja=(ninja)
elif which ninja-build >/dev/null 2>&1; then
NINJA=(ninja-build)
ninja=(ninja-build)
else
echo "Please install ninja" 1>&2
exit 1
fi
"${SCANBUILD[@]}" $NINJA -C "$TARGET_DIR" "${NINJA_PARAMS[@]}"
"${scanbuild[@]}" $ninja -C "$target_dir" "${ninja_params[@]}"

0 comments on commit 8762475

Please sign in to comment.