From 552d8a2821f03046896a728d6e4cec0ef754d3f4 Mon Sep 17 00:00:00 2001 From: Magnus Ihse Bursie Date: Mon, 17 Oct 2022 09:28:23 +0000 Subject: [PATCH] 8295192: Use original configure command line when called from a script Reviewed-by: erikj --- bin/jib.sh | 36 +++++++++++++++++++++++++++++++++++- make/Init.gmk | 9 +++++++-- make/autoconf/basic.m4 | 5 +++++ make/autoconf/help.m4 | 5 +++++ make/autoconf/spec.gmk.in | 5 +++++ 5 files changed, 57 insertions(+), 3 deletions(-) diff --git a/bin/jib.sh b/bin/jib.sh index aab198990cc..da2f84153cc 100644 --- a/bin/jib.sh +++ b/bin/jib.sh @@ -1,6 +1,6 @@ #!/bin/bash # -# Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it @@ -135,6 +135,28 @@ install_jib() { echo "${data_string}" > "${install_data}" } +# Returns a shell-escaped version of the argument given. +shell_quote() { + if [[ -n "$1" ]]; then + # Uses only shell-safe characters? No quoting needed. + # '=' is a zsh meta-character, but only in word-initial position. + if echo "$1" | grep '^[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\.:,%/+=_-]\{1,\}$' > /dev/null \ + && ! echo "$1" | grep '^=' > /dev/null; then + quoted="$1" + else + if echo "$1" | grep "[\'!]" > /dev/null; then + # csh does history expansion within single quotes, but not + # when backslash-escaped! + local quoted_quote="'\\''" quoted_exclam="'\\!'" + word="${1//\'/${quoted_quote}}" + word="${1//\!/${quoted_exclam}}" + fi + quoted="'$1'" + fi + echo "$quoted" + fi +} + # Main body starts here setup_url @@ -151,4 +173,16 @@ if [ -z "${JIB_SRC_DIR}" ]; then export JIB_SRC_DIR="${mydir}/../" fi + +# Save the original command line +conf_quoted_arguments=() +for conf_option; do + conf_quoted_arguments=("${conf_quoted_arguments[@]}" "$(shell_quote "$conf_option")") +done +export REAL_CONFIGURE_COMMAND_LINE="${conf_quoted_arguments[@]}" + +myfulldir="$(cd "${mydir}" > /dev/null && pwd)" +export REAL_CONFIGURE_COMMAND_EXEC_FULL="$BASH $myfulldir/$myname" +export REAL_CONFIGURE_COMMAND_EXEC_SHORT="$myname" + ${installed_jib_script} "$@" diff --git a/make/Init.gmk b/make/Init.gmk index d20ea3b6f05..53652e64b3f 100644 --- a/make/Init.gmk +++ b/make/Init.gmk @@ -277,15 +277,20 @@ else # HAS_SPEC=true $(ECHO) $(CONFIGURE_COMMAND_LINE) reconfigure: - ifneq ($(CONFIGURE_COMMAND_LINE), ) + ifneq ($(REAL_CONFIGURE_COMMAND_EXEC_FULL), ) + $(ECHO) "Re-running configure using original command line '$(REAL_CONFIGURE_COMMAND_EXEC_SHORT) $(REAL_CONFIGURE_COMMAND_LINE)'" + $(eval RECONFIGURE_COMMAND := $(REAL_CONFIGURE_COMMAND_EXEC_FULL) $(REAL_CONFIGURE_COMMAND_LINE)) + else ifneq ($(CONFIGURE_COMMAND_LINE), ) $(ECHO) "Re-running configure using arguments '$(CONFIGURE_COMMAND_LINE)'" + $(eval RECONFIGURE_COMMAND := $(BASH) $(TOPDIR)/configure $(CONFIGURE_COMMAND_LINE)) else $(ECHO) "Re-running configure using default settings" + $(eval RECONFIGURE_COMMAND := $(BASH) $(TOPDIR)/configure) endif ( cd $(CONFIGURE_START_DIR) && PATH="$(ORIGINAL_PATH)" AUTOCONF="$(AUTOCONF)" \ CUSTOM_ROOT="$(CUSTOM_ROOT)" \ CUSTOM_CONFIG_DIR="$(CUSTOM_CONFIG_DIR)" \ - $(BASH) $(TOPDIR)/configure $(CONFIGURE_COMMAND_LINE) ) + $(RECONFIGURE_COMMAND) ) ############################################################################## # The main target, for delegating into Main.gmk diff --git a/make/autoconf/basic.m4 b/make/autoconf/basic.m4 index ff076ca7689..ef4cbf3e8f6 100644 --- a/make/autoconf/basic.m4 +++ b/make/autoconf/basic.m4 @@ -31,6 +31,11 @@ AC_DEFUN_ONCE([BASIC_INIT], [ # Save the original command line. This is passed to us by the wrapper configure script. AC_SUBST(CONFIGURE_COMMAND_LINE) + # We might have the original command line if the wrapper was called by some + # other script. + AC_SUBST(REAL_CONFIGURE_COMMAND_EXEC_SHORT) + AC_SUBST(REAL_CONFIGURE_COMMAND_EXEC_FULL) + AC_SUBST(REAL_CONFIGURE_COMMAND_LINE) # AUTOCONF might be set in the environment by the user. Preserve for "make reconfigure". AC_SUBST(AUTOCONF) # Save the path variable before it gets changed diff --git a/make/autoconf/help.m4 b/make/autoconf/help.m4 index c651dd692dc..4d1b3c37bbb 100644 --- a/make/autoconf/help.m4 +++ b/make/autoconf/help.m4 @@ -278,6 +278,11 @@ AC_DEFUN_ONCE([HELP_PRINT_SUMMARY_AND_WARNINGS], printf "using default settings.\n" fi + if test "x$REAL_CONFIGURE_COMMAND_EXEC_FULL" != x; then + printf "\n" + printf "The original configure invocation was '$REAL_CONFIGURE_COMMAND_EXEC_SHORT $REAL_CONFIGURE_COMMAND_LINE'.\n" + fi + printf "\n" printf "Configuration summary:\n" printf "* Name: $CONF_NAME\n" diff --git a/make/autoconf/spec.gmk.in b/make/autoconf/spec.gmk.in index fef845f37a2..9448cb9b7e8 100644 --- a/make/autoconf/spec.gmk.in +++ b/make/autoconf/spec.gmk.in @@ -35,6 +35,11 @@ CONFIGURE_COMMAND_LINE:=@CONFIGURE_COMMAND_LINE@ # The current directory when configure was run CONFIGURE_START_DIR:=@CONFIGURE_START_DIR@ +# How configure was originally called, if not called directly +REAL_CONFIGURE_COMMAND_EXEC_SHORT := @REAL_CONFIGURE_COMMAND_EXEC_SHORT@ +REAL_CONFIGURE_COMMAND_EXEC_FULL := @REAL_CONFIGURE_COMMAND_EXEC_FULL@ +REAL_CONFIGURE_COMMAND_LINE := @REAL_CONFIGURE_COMMAND_LINE@ + # A self-referential reference to this file. SPEC:=@SPEC@