Skip to content

Commit ba78a7c

Browse files
author
Jianchun Xu
committed
xplat: build.sh improvements
1. Enforce standard `--option=VALUE` syntax (previously accepts --option?VALUE). 2. Use standard `-j [N], --jobs[=N]` syntax. Users used to `make` syntax may run `-j N`, which was handled as `-j` without arg and considered infinity jobs by `make` previously. This hangs Ubuntu VM. Fix the script to accept full `-j [N], --jobs[=N]` syntax. When option is specified without N, use appropriate default to avoid VM hang. 3. Error on unknown command line options (previously silently ignores). 4. Allow current working directory to be a directory other than chakracore repo root.
1 parent 0ede352 commit ba78a7c

1 file changed

Lines changed: 57 additions & 47 deletions

File tree

build.sh

Lines changed: 57 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,27 @@ PRINT_USAGE() {
1717
echo ""
1818
echo "[ChakraCore Build Script Help]"
1919
echo ""
20-
echo " build.sh [options]"
20+
echo "build.sh [options]"
2121
echo ""
22-
echo " options:"
23-
echo " --cxx : Path to Clang++ (see example below)"
24-
echo " --cc : Path to Clang (see example below)"
25-
echo " -d, --debug : Debug build (by default Release build)"
26-
echo " -h, --help : Show help"
27-
echo " --icu : Path to ICU include folder (see example below)"
28-
echo " -j, --jobs : Multicore build (i.e. -j=3 for 3 cores)"
29-
echo " -n, --ninja : Build with ninja instead of make"
30-
echo " -t, --test-build : Test build (by default Release build)"
31-
echo " -v, --verbose : Display verbose output including all options"
22+
echo "options:"
23+
echo " --cxx=PATH Path to Clang++ (see example below)"
24+
echo " --cc=PATH Path to Clang (see example below)"
25+
echo " -d, --debug Debug build (by default Release build)"
26+
echo " -h, --help Show help"
27+
echo " --icu=PATH Path to ICU include folder (see example below)"
28+
echo " -j [N], --jobs[=N] Multicore build, allow N jobs at once"
29+
echo " -n, --ninja Build with ninja instead of make"
30+
echo " -t, --test-build Test build (by default Release build)"
31+
echo " -v, --verbose Display verbose output including all options"
3232
echo ""
33-
echo " example:"
34-
echo " ./build.sh --cxx=/path/to/clang++ --cc=/path/to/clang -j=2"
35-
echo " with icu:"
36-
echo " ./build.sh --icu=/usr/local/Cellar/icu4c/version/include/"
33+
echo "example:"
34+
echo " ./build.sh --cxx=/path/to/clang++ --cc=/path/to/clang -j"
35+
echo "with icu:"
36+
echo " ./build.sh --icu=/usr/local/Cellar/icu4c/version/include/"
3737
echo ""
3838
}
3939

40+
CHAKRACORE_DIR=`dirname $0`
4041
_CXX=""
4142
_CC=""
4243
VERBOSE=""
@@ -47,52 +48,68 @@ MULTICORE_BUILD=""
4748
ICU_PATH=""
4849

4950
while [[ $# -gt 0 ]]; do
50-
if [[ "$1" =~ "--cxx" ]]; then
51+
case "$1" in
52+
--cxx=*)
5153
_CXX=$1
5254
_CXX=${_CXX:6}
53-
fi
55+
;;
5456

55-
if [[ "$1" =~ "--cc" ]]; then
57+
--cc=*)
5658
_CC=$1
5759
_CC=${_CC:5}
58-
fi
60+
;;
5961

60-
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
62+
-h | --help)
6163
PRINT_USAGE
6264
exit
63-
fi
65+
;;
6466

65-
if [[ "$1" == "--verbose" || "$1" == "-v" ]]; then
67+
-v | --verbose)
6668
_VERBOSE="verbose"
67-
fi
69+
;;
6870

69-
if [[ "$1" == "--debug" || "$1" == "-d" ]]; then
71+
-d | --debug)
7072
BUILD_TYPE="Debug"
71-
fi
73+
;;
7274

73-
if [[ "$1" == "--test-build" || "$1" == "-t" ]]; then
75+
-t | --test-build)
7476
BUILD_TYPE="Test"
75-
fi
77+
;;
7678

77-
if [[ "$1" =~ "-j" ]]; then
78-
MULTICORE_BUILD=$1
79-
MULTICORE_BUILD="-j ${MULTICORE_BUILD:3}"
80-
fi
79+
-j | --jobs)
80+
if [[ "$1" == "-j" && "$2" =~ ^[^-] ]]; then
81+
MULTICORE_BUILD="-j $2"
82+
shift
83+
else
84+
MULTICORE_BUILD="-j $(nproc)"
85+
fi
86+
;;
8187

82-
if [[ "$1" =~ "--jobs" ]]; then
88+
-j=* | --jobs=*) # -j=N syntax used in CI
8389
MULTICORE_BUILD=$1
84-
MULTICORE_BUILD="-j ${MULTICORE_BUILD:7}"
85-
fi
90+
if [[ "$1" =~ ^-j= ]]; then
91+
MULTICORE_BUILD="-j ${MULTICORE_BUILD:3}"
92+
else
93+
MULTICORE_BUILD="-j ${MULTICORE_BUILD:7}"
94+
fi
95+
;;
8696

87-
if [[ "$1" =~ "--icu" ]]; then
97+
--icu=*)
8898
ICU_PATH=$1
8999
ICU_PATH="-DICU_INCLUDE_PATH=${ICU_PATH:6}"
90-
fi
100+
;;
91101

92-
if [[ "$1" == "--ninja" || "$1" == "-n" ]]; then
102+
-n | --ninja)
93103
CMAKE_GEN="-G Ninja"
94104
MAKE=ninja
95-
fi
105+
;;
106+
107+
*)
108+
echo "Unknown option $1"
109+
PRINT_USAGE
110+
exit -1
111+
;;
112+
esac
96113

97114
shift
98115
done
@@ -159,15 +176,9 @@ if [[ ${#_CXX} > 0 ]]; then
159176
CC_PREFIX="-DCMAKE_CXX_COMPILER=$_CXX -DCMAKE_C_COMPILER=$_CC"
160177
fi
161178

162-
if [ ! -d "BuildLinux" ]; then
163-
SAFE_RUN 'mkdir BuildLinux'
164-
fi
165-
166-
pushd BuildLinux > /dev/null
167-
168-
build_directory="${BUILD_TYPE,,}"
179+
build_directory="$CHAKRACORE_DIR/BuildLinux/${BUILD_TYPE,,}"
169180
if [ ! -d "$build_directory" ]; then
170-
SAFE_RUN `mkdir $build_directory`
181+
SAFE_RUN `mkdir -p $build_directory`
171182
fi
172183

173184
pushd $build_directory > /dev/null
@@ -177,4 +188,3 @@ cmake $CMAKE_GEN $CC_PREFIX $ICU_PATH -DCMAKE_BUILD_TYPE=$BUILD_TYPE ../..
177188

178189
$MAKE $MULTICORE_BUILD 2>&1 | tee build.log
179190
popd > /dev/null
180-
popd > /dev/null

0 commit comments

Comments
 (0)