-
-
Save makotoshimazu/1a9bd0a3f43a471057fc587f192571f9 to your computer and use it in GitHub Desktop.
Wrapper of ninja
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env zsh | |
# default parameters | |
DEFAULT_TARGETS="content_unittests content_browsertests chrome blink_tests browser_tests content_shell chromedriver webkit_unit_tests unit_tests" | |
script=$0 | |
script_dir=$(cd $(dirname $script); pwd) | |
function usage() { | |
cat 1>&2 <<EOL | |
Usage: $script [option] type | |
type: release, debug, tsan, msan, android, cast, fuzzer, compdb, release-chromeos | |
option: | |
--use-master-outdir: Create an out dir as a symbolic link to out/master_TYPE. | |
This won't make a symbolic link if the out dir for this | |
branch already exists. | |
--out-dir=OUTDIR, -o OUTDIR: Use the dir as the out dir. [default: {BRANCH}_{TYPE}] | |
--help, -h: Show this help. | |
EOL | |
} | |
function template_args_file_path() { | |
local build_type=$1 | |
echo "${script_dir}/out/${build_type}/args.gn" | |
} | |
function generate_compdb() { | |
local outdir="$1" | |
local compile_commands="$2" | |
echo "Updating compdb..." | |
ninja -C ${script_dir}/${outdir} -t compdb > $compile_commands cxx cc | |
# Remove flags for optional plugins built in the custom clang in chromium. | |
sed -i -E 's/-Xclang -add-plugin -Xclang find-bad-constructs -Xclang -plugin-arg-find-bad-constructs -Xclang check-ipc//' $compile_commands | |
# Remove dependency file. | |
sed -i -E 's/-MF [^ ]+ //' $compile_commands | |
sed -i -E 's/-MMD //' $compile_commands | |
ln -sf $compile_commands ${script_dir}/compile_commands.json | |
echo "done." | |
} | |
function comment_goma_settings_from_gn_arg() { | |
local outdir=$1 | |
echo "Removing the use_goma settings" | |
sed -i -e 's/^use_goma/## use_goma/' ${outdir}/args.gn | |
echo "Regenerate gn settings." | |
gn gen ${outdir} | |
echo "done." | |
} | |
function uncomment_goma_settings_from_gn_arg() { | |
local outdir=$1 | |
echo "Adding the use_goma settings" | |
sed -i -e 's/^## use_goma/use_goma/' ${outdir}/args.gn | |
echo "Regenerate gn settings." | |
gn gen ${outdir} | |
echo "done." | |
} | |
function check_and_create_outdir_with_compdb() { | |
local outdir=$1 | |
local build_type=$2 | |
if [[ ! -e "$outdir" ]]; then | |
echo "$outdir was not found. Creating the out dir..." | |
gn gen $outdir | |
fi | |
# Update args.gn if there is a diff from the template. | |
diff $(template_args_file_path "$build_type") $outdir/args.gn > /dev/null 2>&1 | |
if [[ "$?" -ne "0" ]]; then | |
echo "Update ninja configuration based on the template (out/$build_type)" | |
cp -v $(template_args_file_path "$build_type") $outdir | |
gn gen $outdir | |
echo "done." | |
fi | |
ln -sf $script_dir/$outdir $script_dir/out/current_outdir | |
local compile_commands="${script_dir}/${outdir}/compile_commands.json" | |
if [[ ! -f "$compile_commands" ]]; then | |
comment_goma_settings_from_gn_arg "$outdir" | |
generate_compdb "$outdir" "$compile_commands" | |
uncomment_goma_settings_from_gn_arg "$outdir" | |
fi | |
} | |
# Options | |
USE_MASTER_OUTDIR=0 | |
# Parse options | |
local -A opthash | |
local overridden_outdir | |
zparseopts -D -A opthash -- -use-master-outdir o: -outdir:=o h -help=h | |
if [[ -n "${opthash[(i)-h]}" ]]; then | |
usage | |
exit 1 | |
fi | |
if [[ -n "${opthash[(i)--use-master-outdir]}" ]]; then | |
USE_MASTER_OUTDIR=1 | |
echo "Use master outdir." | |
fi | |
if [[ -n "${opthash[(i)-o]}" ]]; then | |
overridden_outdir=${opthash[-o]} | |
fi | |
# Check the arguments | |
if [[ $# -lt 1 ]]; then | |
echo "Too few arguments" 1>&2 | |
usage | |
exit 1 | |
fi | |
# arguments | |
local type | |
type=$1 | |
shift 1 | |
branch=$(git rev-parse --abbrev-ref HEAD) | |
# Consume the rest of parameters based on the type. | |
case $type in | |
tsan) | |
export TSAN_OPTIONS="external_symbolizer_path=third_party/llvm-build/Release+Asserts/bin/llvm-symbolizer" | |
if [[ $# -lt 1 ]]; then | |
#targets="base_unittests content_browsertests content_unittests" | |
targets=$DEFAULT_TARGETS | |
else | |
targets=$@ | |
fi | |
;; | |
msan) | |
if [[ $# -lt 1 ]]; then | |
#targets="base_unittests content_browsertests content_unittests browser_tests" | |
targets=$DEFAULT_TARGETS | |
else | |
targets=$@ | |
fi | |
;; | |
asan) | |
if [[ $# -lt 1 ]]; then | |
#targets="base_unittests content_browsertests content_unittests browser_tests" | |
targets=$DEFAULT_TARGETS | |
else | |
targets=$@ | |
fi | |
;; | |
debug) | |
if [[ $# -lt 1 ]]; then | |
targets=$DEFAULT_TARGETS | |
else | |
targets=$@ | |
fi | |
;; | |
release) | |
if [[ $# -lt 1 ]]; then | |
targets=$DEFAULT_TARGETS | |
else | |
targets=$@ | |
fi | |
;; | |
release-chromeos) | |
if [[ $# -lt 1 ]]; then | |
targets=$DEFAULT_TARGETS | |
else | |
targets=$@ | |
fi | |
;; | |
android) | |
if [[ $# -lt 1 ]]; then | |
targets="chrome_public_apk content_shell_apk monochrome_public_apk system_webview_apk" | |
else | |
targets=$@ | |
fi | |
export JAVA_HOME=$(readlink -ne /usr/local/buildtools/java/jdk) | |
;; | |
cast) | |
if [[ $# -lt 1 ]]; then | |
targets="cast_shell" | |
else | |
targets=$@ | |
fi | |
;; | |
fuzzer) | |
if [[ $# -lt 1 ]]; then | |
echo "Please specify the target when compiling fuzzer." 1>&2 | |
exit 1 | |
fi | |
targets=$@ | |
;; | |
compdb) | |
if [[ $# -lt 1 ]]; then | |
echo "Please specify the target build type (release, debug ...) as the second parameter." 1>&2 | |
echo "$ $0 compdb BUILD_TYPE" 1>&2 | |
exit 1 | |
fi | |
type="$1" | |
local outdir="out/${branch}_${type}" | |
if [[ ! -e "$outdir" ]]; then | |
echo "No outdir: ${outdir}" | |
exit 1 | |
fi | |
compile_commands="${script_dir}/${outdir}/compile_commands.json" | |
echo "Re-generate compile_commands.json: $compile_commands" | |
comment_goma_settings_from_gn_arg "$outdir" | |
generate_compdb "$outdir" "$compile_commands" | |
uncomment_goma_settings_from_gn_arg "$outdir" | |
exit | |
;; | |
*) | |
echo "Unknown type: $type" | |
exit 1 | |
;; | |
esac | |
local outdir=out/${branch}_${type} | |
if [[ ! -z "$overridden_outdir" ]]; then | |
outdir=$overridden_outdir | |
fi | |
if [[ $USE_MASTER_OUTDIR == 1 ]]; then | |
local relevant_master_outdir | |
relevant_master_outdir="$script_dir/out/master_${type}" | |
# Create a symbolic link to the master | |
if [[ ! -e $relevant_master_outdir ]]; then | |
echo "No relevant master dir: $relevant_master_outdir" 1>&2 | |
exit 1 | |
fi | |
if [[ ! -e $outdir ]]; then | |
echo "Create a link for $outdir" | |
ln -sf $relevant_master_outdir $script_dir/$outdir | |
fi | |
fi | |
check_and_create_outdir_with_compdb $outdir $type | |
time autoninja -C $outdir $=targets |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment