Skip to content

Commit

Permalink
8297963: Partially fix string expansion issues in UTIL_DEFUN_NAMED an…
Browse files Browse the repository at this point in the history
…d related macros

Backport-of: 1a38e26e67570ac01de6e969114b476df933d1eb
  • Loading branch information
RealCLanger committed Feb 16, 2023
1 parent 630c80e commit 06ee0b6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
8 changes: 4 additions & 4 deletions make/autoconf/flags.m4
Expand Up @@ -506,14 +506,14 @@ UTIL_DEFUN_NAMED([FLAGS_CXX_COMPILER_CHECK_ARGUMENTS],
UTIL_DEFUN_NAMED([FLAGS_COMPILER_CHECK_ARGUMENTS],
[*ARGUMENT IF_TRUE IF_FALSE PREFIX], [$@],
[
FLAGS_C_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [ARG_ARGUMENT],
FLAGS_C_COMPILER_CHECK_ARGUMENTS(ARGUMENT: ARG_ARGUMENT,
IF_TRUE: [C_COMP_SUPPORTS="yes"],
IF_FALSE: [C_COMP_SUPPORTS="no"],
PREFIX: [ARG_PREFIX])
FLAGS_CXX_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [ARG_ARGUMENT],
PREFIX: ARG_PREFIX)
FLAGS_CXX_COMPILER_CHECK_ARGUMENTS(ARGUMENT: ARG_ARGUMENT,
IF_TRUE: [CXX_COMP_SUPPORTS="yes"],
IF_FALSE: [CXX_COMP_SUPPORTS="no"],
PREFIX: [ARG_PREFIX])
PREFIX: ARG_PREFIX)
AC_MSG_CHECKING([if both ARG_PREFIX[CC] and ARG_PREFIX[CXX] support "ARG_ARGUMENT"])
supports=no
Expand Down
45 changes: 25 additions & 20 deletions make/autoconf/util.m4
Expand Up @@ -52,7 +52,7 @@ m4_include([util_paths.m4])
AC_DEFUN([UTIL_DEFUN_NAMED],
[
AC_DEFUN($1, [
m4_foreach(arg, m4_split(m4_normalize($2)), [
m4_foreach([arg], m4_split(m4_normalize($2)), [
m4_if(m4_bregexp(arg, [^\*]), -1,
[
m4_set_add(legal_named_args, arg)
Expand All @@ -64,13 +64,18 @@ AC_DEFUN([UTIL_DEFUN_NAMED],
)
])
m4_foreach([arg], [$3], [
m4_if(m4_bregexp(arg, [: ]), -1, m4_define([arg], m4_bpatsubst(arg, [:], [: ])))
m4_define(arg_name, m4_substr(arg, 0, m4_bregexp(arg, [: ])))
# Delicate quoting and unquoting sequence to ensure the actual value is passed along unchanged
# For details on how this works, see https://git.openjdk.org/jdk/pull/11458#discussion_r1038173051
# WARNING: Proceed at the risk of your own sanity, getting this to work has made me completely
# incapable of feeling love or any other positive emotion
# ~Julian
m4_foreach([arg], m4_dquote(m4_dquote_elt($3)), [
m4_if(m4_index(arg, [: ]), -1, [m4_define([arg], m4_dquote(m4_bpatsubst(m4_dquote(arg), [:], [: ])))])
m4_define(arg_name, m4_substr(arg, 0, m4_index(arg, [: ])))
m4_set_contains(legal_named_args, arg_name, [],[AC_MSG_ERROR([Internal error: m4_if(arg_name, , arg, arg_name) is not a valid named argument to [$1]. Valid arguments are 'm4_set_contents(defined_args, [ ]) m4_set_contents(legal_named_args, [ ])'.])])
m4_set_remove(required_named_args, arg_name)
m4_set_remove(legal_named_args, arg_name)
m4_pushdef([ARG_][]arg_name, m4_bpatsubst(m4_substr(arg, m4_incr(m4_incr(m4_bregexp(arg, [: ])))), [^\s*], []))
m4_pushdef([ARG_][]arg_name, m4_bpatsubst(m4_bpatsubst(m4_dquote(m4_dquote(arg)), arg_name[: ]), [^\s*]))
m4_set_add(defined_args, arg_name)
m4_undefine([arg_name])
])
Expand Down Expand Up @@ -380,18 +385,18 @@ UTIL_DEFUN_NAMED([UTIL_ARG_ENABLE],
m4_define(ARG_GIVEN, m4_translit(ARG_NAME, [a-z-], [A-Z_])[_GIVEN])
# If DESC is not specified, set it to a generic description.
m4_define([ARG_DESC], m4_if(ARG_DESC, , [Enable the ARG_NAME feature], m4_normalize(ARG_DESC)))
m4_define([ARG_DESC], m4_if(m4_quote(ARG_DESC), , [[Enable the ARG_NAME feature]], [m4_normalize(ARG_DESC)]))
# If CHECKING_MSG is not specified, set it to a generic description.
m4_define([ARG_CHECKING_MSG], m4_if(ARG_CHECKING_MSG, , [for --enable-ARG_NAME], m4_normalize(ARG_CHECKING_MSG)))
m4_define([ARG_CHECKING_MSG], m4_if(m4_quote(ARG_CHECKING_MSG), , [[for --enable-ARG_NAME]], [m4_normalize(ARG_CHECKING_MSG)]))
# If the code blocks are not given, set them to the empty statements to avoid
# tripping up bash.
m4_define([ARG_CHECK_AVAILABLE], m4_if(ARG_CHECK_AVAILABLE, , :, ARG_CHECK_AVAILABLE))
m4_define([ARG_IF_GIVEN], m4_if(ARG_IF_GIVEN, , :, ARG_IF_GIVEN))
m4_define([ARG_IF_NOT_GIVEN], m4_if(ARG_IF_NOT_GIVEN, , :, ARG_IF_NOT_GIVEN))
m4_define([ARG_IF_ENABLED], m4_if(ARG_IF_ENABLED, , :, ARG_IF_ENABLED))
m4_define([ARG_IF_DISABLED], m4_if(ARG_IF_DISABLED, , :, ARG_IF_DISABLED))
m4_if(ARG_CHECK_AVAILABLE, , [m4_define([ARG_CHECK_AVAILABLE], [:])])
m4_if(ARG_IF_GIVEN, , [m4_define([ARG_IF_GIVEN], [:])])
m4_if(ARG_IF_NOT_GIVEN, , [m4_define([ARG_IF_NOT_GIVEN], [:])])
m4_if(ARG_IF_ENABLED, , [m4_define([ARG_IF_ENABLED], [:])])
m4_if(ARG_IF_DISABLED, , [m4_define([ARG_IF_DISABLED], [:])])
##########################
# Part 2: Set up autoconf shell code
Expand Down Expand Up @@ -654,21 +659,21 @@ UTIL_DEFUN_NAMED([UTIL_ARG_WITH],
m4_define(ARG_GIVEN, m4_translit(ARG_NAME, [a-z-], [A-Z_])[_GIVEN])
# If DESC is not specified, set it to a generic description.
m4_define([ARG_DESC], m4_if(ARG_DESC, , [Give a value for the ARG_NAME feature], m4_normalize(ARG_DESC)))
m4_define([ARG_DESC], m4_if(m4_quote(ARG_DESC), , [[Give a value for the ARG_NAME feature]], [m4_normalize(ARG_DESC)]))
# If CHECKING_MSG is not specified, set it to a generic description.
m4_define([ARG_CHECKING_MSG], m4_if(ARG_CHECKING_MSG, , [for --with-ARG_NAME], m4_normalize(ARG_CHECKING_MSG)))
m4_define([ARG_CHECKING_MSG], m4_if(m4_quote(ARG_CHECKING_MSG), , [[for --with-ARG_NAME]], [m4_normalize(ARG_CHECKING_MSG)]))
m4_define([ARG_HAS_AUTO_BLOCK], m4_if(ARG_IF_AUTO, , false, true))
# If the code blocks are not given, set them to the empty statements to avoid
# tripping up bash.
m4_define([ARG_CHECK_AVAILABLE], m4_if(ARG_CHECK_AVAILABLE, , :, ARG_CHECK_AVAILABLE))
m4_define([ARG_CHECK_VALUE], m4_if(ARG_CHECK_VALUE, , :, ARG_CHECK_VALUE))
m4_define([ARG_CHECK_FOR_FILES], m4_if(ARG_CHECK_FOR_FILES, , :, ARG_CHECK_FOR_FILES))
m4_define([ARG_IF_AUTO], m4_if(ARG_IF_AUTO, , :, ARG_IF_AUTO))
m4_define([ARG_IF_GIVEN], m4_if(ARG_IF_GIVEN, , :, ARG_IF_GIVEN))
m4_define([ARG_IF_NOT_GIVEN], m4_if(ARG_IF_NOT_GIVEN, , :, ARG_IF_NOT_GIVEN))
m4_if(ARG_CHECK_AVAILABLE, , [m4_define([ARG_CHECK_AVAILABLE], [:])])
m4_if(ARG_CHECK_VALUE, , [m4_define([ARG_CHECK_VALUE], [:])])
m4_if(ARG_CHECK_FOR_FILES, , [m4_define([ARG_CHECK_FOR_FILES], [:])])
m4_if(ARG_IF_AUTO, , [m4_define([ARG_IF_AUTO], [:])])
m4_if(ARG_IF_GIVEN, , [m4_define([ARG_IF_GIVEN], [:])])
m4_if(ARG_IF_NOT_GIVEN, , [m4_define([ARG_IF_NOT_GIVEN], [:])])
##########################
# Part 2: Set up autoconf shell code
Expand Down

1 comment on commit 06ee0b6

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.