chore: add error handling and cc-opt injection to build scripts
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -Eeuo pipefail
|
||||||
|
|
||||||
MODULE_NAME="${MODULE_NAME:-ngx_http_monitoring_module}"
|
MODULE_NAME="${MODULE_NAME:-ngx_http_monitoring_module}"
|
||||||
DEB_PACKAGE_NAME="${DEB_PACKAGE_NAME:-libnginx-mod-http-monitoring}"
|
DEB_PACKAGE_NAME="${DEB_PACKAGE_NAME:-libnginx-mod-http-monitoring}"
|
||||||
@@ -18,6 +18,22 @@ GITHUB_SHA="${GITHUB_SHA:-unknown}"
|
|||||||
|
|
||||||
export DEBIAN_FRONTEND=noninteractive
|
export DEBIAN_FRONTEND=noninteractive
|
||||||
|
|
||||||
|
on_error() {
|
||||||
|
local status="$?"
|
||||||
|
local line="${BASH_LINENO[0]:-unknown}"
|
||||||
|
|
||||||
|
echo "::error::distro release build failed at line ${line} with exit code ${status}" >&2
|
||||||
|
|
||||||
|
if [[ -n "${WORK_ROOT:-}" && -d "$WORK_ROOT" ]]; then
|
||||||
|
find "$WORK_ROOT" -path '*/objs/autoconf.err' -type f -print -exec sed -n '1,160p' {} \; >&2 || true
|
||||||
|
find "$WORK_ROOT" -path '*/objs/*.log' -type f -print -exec sed -n '1,160p' {} \; >&2 || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit "$status"
|
||||||
|
}
|
||||||
|
|
||||||
|
trap on_error ERR
|
||||||
|
|
||||||
slugify() {
|
slugify() {
|
||||||
tr '[:upper:]' '[:lower:]' \
|
tr '[:upper:]' '[:lower:]' \
|
||||||
| sed -E 's/[^a-z0-9.+~]+/./g; s/^[.]+//; s/[.]+$//'
|
| sed -E 's/[^a-z0-9.+~]+/./g; s/^[.]+//; s/[.]+$//'
|
||||||
@@ -255,9 +271,7 @@ apt-get build-dep -y --no-install-recommends "${source_package}=${source_version
|
|||||||
|| apt-get build-dep -y --no-install-recommends "$source_package"
|
|| apt-get build-dep -y --no-install-recommends "$source_package"
|
||||||
|
|
||||||
nginx_build_info="$build_root/nginx-build-info.json"
|
nginx_build_info="$build_root/nginx-build-info.json"
|
||||||
python3 /work/scripts/nginx-build-info.py --nginx-src "$nginx_src" --json > "$nginx_build_info"
|
|
||||||
modules_path="$(python3 /work/scripts/nginx-build-info.py --modules-path)"
|
modules_path="$(python3 /work/scripts/nginx-build-info.py --modules-path)"
|
||||||
configure_line="$(python3 /work/scripts/nginx-build-info.py --nginx-src "$nginx_src" --configure-line)"
|
|
||||||
|
|
||||||
case "$modules_path" in
|
case "$modules_path" in
|
||||||
/*) ;;
|
/*) ;;
|
||||||
@@ -269,9 +283,17 @@ deb_revision_slug="$(printf '%s%s.nginx%s' "$distro_id" "$distro_version" "$sour
|
|||||||
deb_version="${NEXT_VERSION}-1+${deb_revision_slug}"
|
deb_version="${NEXT_VERSION}-1+${deb_revision_slug}"
|
||||||
build_metadata="$(printf '%s.%s.%s' "$distro_slug" "$deb_arch" "$source_version_slug" | slugify)"
|
build_metadata="$(printf '%s.%s.%s' "$distro_slug" "$deb_arch" "$source_version_slug" | slugify)"
|
||||||
module_cflags="-DNGX_HTTP_MONITORING_MODULE_VERSION=\\\"${NEXT_VERSION}\\\" -DNGX_HTTP_MONITORING_BUILD_METADATA=\\\"${build_metadata}\\\""
|
module_cflags="-DNGX_HTTP_MONITORING_MODULE_VERSION=\\\"${NEXT_VERSION}\\\" -DNGX_HTTP_MONITORING_BUILD_METADATA=\\\"${build_metadata}\\\""
|
||||||
|
python3 /work/scripts/nginx-build-info.py \
|
||||||
|
--nginx-src "$nginx_src" \
|
||||||
|
--extra-cc-opt "$module_cflags" \
|
||||||
|
--json > "$nginx_build_info"
|
||||||
|
configure_line="$(python3 /work/scripts/nginx-build-info.py \
|
||||||
|
--nginx-src "$nginx_src" \
|
||||||
|
--extra-cc-opt "$module_cflags" \
|
||||||
|
--configure-line)"
|
||||||
|
|
||||||
cd "$nginx_src"
|
cd "$nginx_src"
|
||||||
eval "./configure ${configure_line} --with-cc-opt=\"${module_cflags}\" --add-dynamic-module=/work"
|
eval "./configure ${configure_line} --add-dynamic-module=/work"
|
||||||
|
|
||||||
build_jobs="$(nproc)"
|
build_jobs="$(nproc)"
|
||||||
if [[ "$TARGET_ARCH" != "linux-x86_64" && "$build_jobs" -gt 2 ]]; then
|
if [[ "$TARGET_ARCH" != "linux-x86_64" && "$build_jobs" -gt 2 ]]; then
|
||||||
|
|||||||
@@ -68,17 +68,39 @@ def rewrite_module_path(arg, nginx_src):
|
|||||||
return arg
|
return arg
|
||||||
|
|
||||||
|
|
||||||
def rewrite_configure_args(args, nginx_src):
|
def add_extra_cc_opt(args, extra_cc_opt):
|
||||||
if not nginx_src:
|
if not extra_cc_opt:
|
||||||
return args
|
return args
|
||||||
|
|
||||||
return [rewrite_module_path(arg, nginx_src) for arg in args]
|
rewritten = []
|
||||||
|
found = False
|
||||||
|
|
||||||
|
for arg in args:
|
||||||
|
if arg.startswith("--with-cc-opt="):
|
||||||
|
found = True
|
||||||
|
rewritten.append(arg + " " + extra_cc_opt)
|
||||||
|
else:
|
||||||
|
rewritten.append(arg)
|
||||||
|
|
||||||
|
if not found:
|
||||||
|
rewritten.append("--with-cc-opt=" + extra_cc_opt)
|
||||||
|
|
||||||
|
return rewritten
|
||||||
|
|
||||||
|
|
||||||
|
def rewrite_configure_args(args, nginx_src, extra_cc_opt):
|
||||||
|
if not nginx_src:
|
||||||
|
return add_extra_cc_opt(args, extra_cc_opt)
|
||||||
|
|
||||||
|
rewritten = [rewrite_module_path(arg, nginx_src) for arg in args]
|
||||||
|
return add_extra_cc_opt(rewritten, extra_cc_opt)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("--nginx-bin", default="nginx")
|
parser.add_argument("--nginx-bin", default="nginx")
|
||||||
parser.add_argument("--nginx-src", default="")
|
parser.add_argument("--nginx-src", default="")
|
||||||
|
parser.add_argument("--extra-cc-opt", default="")
|
||||||
parser.add_argument("--json", action="store_true")
|
parser.add_argument("--json", action="store_true")
|
||||||
parser.add_argument("--configure-line", action="store_true")
|
parser.add_argument("--configure-line", action="store_true")
|
||||||
parser.add_argument("--modules-path", action="store_true")
|
parser.add_argument("--modules-path", action="store_true")
|
||||||
@@ -86,7 +108,11 @@ def main():
|
|||||||
|
|
||||||
output = nginx_v_output(args.nginx_bin)
|
output = nginx_v_output(args.nginx_bin)
|
||||||
version, configure_line, configure_args = parse_nginx_v(output)
|
version, configure_line, configure_args = parse_nginx_v(output)
|
||||||
rewritten_args = rewrite_configure_args(configure_args, args.nginx_src)
|
rewritten_args = rewrite_configure_args(
|
||||||
|
configure_args,
|
||||||
|
args.nginx_src,
|
||||||
|
args.extra_cc_opt,
|
||||||
|
)
|
||||||
|
|
||||||
modules_path = option_value(configure_args, "--modules-path")
|
modules_path = option_value(configure_args, "--modules-path")
|
||||||
if not modules_path:
|
if not modules_path:
|
||||||
|
|||||||
Reference in New Issue
Block a user