Skip to content

Commit 6b01d2b

Browse files
committed
build: Add unique check to OPAL_SUMMARY_ADD
Rewrite OPAL_SUMMARY_ADD with the goal of better supporting the ability to call SUMMARY_ADD with the same section and topic multiple times and having SUMMARY_ADD do the unique check. This patch also changes how strings are stored, so that there is no longer a hacky substitution of the section and topic names to replace spaces with underscores during storage and the opposite during display, meaning that the strings were practically limited to alphabetical characters and spaces. This implementation does use slightly more memory and puts more strings in the environment, but also has significantly fewer corner-case behaviors. Signed-off-by: Brian Barrett <[email protected]>
1 parent 1f6c043 commit 6b01d2b

File tree

1 file changed

+76
-24
lines changed

1 file changed

+76
-24
lines changed

config/opal_summary.m4

Lines changed: 76 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,92 @@
1-
dnl -*- shell-script -*-
1+
dnl -*- autoconf -*-
22
dnl
33
dnl Copyright (c) 2016 Los Alamos National Security, LLC. All rights
44
dnl reserved.
55
dnl Copyright (c) 2016-2018 Cisco Systems, Inc. All rights reserved
66
dnl Copyright (c) 2016 Research Organization for Information Science
77
dnl and Technology (RIST). All rights reserved.
8+
dnl Copyright (c) 2022 Amazon.com, Inc. or its affiliates. All Rights reserved.
89
dnl $COPYRIGHT$
910
dnl
1011
dnl Additional copyrights may follow
1112
dnl
1213
dnl $HEADER$
1314
dnl
14-
AC_DEFUN([OPAL_SUMMARY_ADD],[
15-
OPAL_VAR_SCOPE_PUSH([ompi_summary_section ompi_summary_line ompi_summary_section_current])
16-
17-
dnl need to replace spaces in the section name with somethis else. _ seems like a reasonable
18-
dnl choice. if this changes remember to change OMPI_PRINT_SUMMARY as well.
19-
ompi_summary_section=$(echo $1 | tr ' ' '_')
20-
ompi_summary_line="$2: $4"
21-
ompi_summary_section_current=$(eval echo \$ompi_summary_values_$ompi_summary_section)
2215

23-
if test -z "$ompi_summary_section_current" ; then
24-
if test -z "$ompi_summary_sections" ; then
25-
ompi_summary_sections=$ompi_summary_section
26-
else
27-
ompi_summary_sections="$ompi_summary_sections $ompi_summary_section"
28-
fi
29-
eval ompi_summary_values_$ompi_summary_section=\"$ompi_summary_line\"
30-
else
31-
eval ompi_summary_values_$ompi_summary_section=\"$ompi_summary_section_current,$ompi_summary_line\"
32-
fi
16+
# OPAL_SUMMARY_ADD(section, topic, unused, result)
17+
#
18+
# queue a summary line in the given section of the form:
19+
# topic: result
20+
#
21+
# section:topic lines are only added once; first to add wins.
22+
# The key for uniqification is a shell-variable-ified representation
23+
# of section followed by an underscore followed by a
24+
# shell-variable-ified representation of line.
25+
#
26+
# There are no restrictions on the contents of section and topic; they
27+
# can be variable references (although the use case for this is
28+
# dubious) and they can contain most ASCII characters (escape
29+
# characters excluded). Note that some care must be taken with the
30+
# unique check and this liberal rule, as the unique check is after the
31+
# string has been run through AS_TR_SH. Basically, any character that
32+
# is not legal in a shell variable name will be turned into an
33+
# underscore. So the strings "Section_foo" and "Section-foo" would be
34+
# the same as far as the unique check is concerned.
35+
#
36+
# The input strings are evaluated during OPAL_SUMMARY_ADD, not during
37+
# OPAL_SUMMARY_PRINT. This seems to meet the principle of least
38+
# astonishment. A common pattern is to call
39+
# OPAL_SUMMARY_ADD([Resource Type], [Component Name], [], [$results])
40+
# and then unset $results to avoid namespace pollution. This will
41+
# work properly with the current behavior, but would result in odd
42+
# errors if we delayed evaulation.
43+
#
44+
# As a historical note, the third argument has never been used in
45+
# OPAL_SUMMARY_ADD and its meaning is unclear. Preferred behavior is
46+
# to leave it empty.
47+
#
48+
# As a final historical note, the initial version of SUMMARY_ADD was
49+
# added with implementation of the callers having all of the section
50+
# and topic headers double quoted. This was never necessary, and
51+
# certainly is not with the current implementation. While harmless,
52+
# it is not great practice to over-quote, so we recommend against
53+
# doing so.
54+
# -----------------------------------------------------------
55+
AC_DEFUN([OPAL_SUMMARY_ADD],[
56+
OPAL_VAR_SCOPE_PUSH([opal_summary_line opal_summary_newline opal_summary_key])
57+
58+
# The end quote on the next line is intentional!
59+
opal_summary_newline="
60+
"
61+
opal_summary_line="$2: $4"
62+
opal_summary_key="AS_TR_SH([$1])_AS_TR_SH([$2])"
63+
64+
# Use the section name variable as an indicator for whether or not
65+
# the section has already been created.
66+
AS_IF([AS_VAR_TEST_SET([opal_summary_section_]AS_TR_SH([$1])[_name])],
67+
[],
68+
[AS_VAR_SET([opal_summary_section_]AS_TR_SH([$1])[_name], ["$1"])
69+
OPAL_APPEND([opal_summary_sections], [AS_TR_SH([$1])])])
70+
71+
# Use the summary key as indicator if the section:topic has already
72+
# been added to the results for the given section.
73+
AS_IF([AS_VAR_TEST_SET([${opal_summary_key}])],
74+
[],
75+
[AS_VAR_SET([${opal_summary_key}], [1])
76+
dnl this is a bit overcomplicated, but we are basically implementing
77+
dnl a poor mans AS_VAR_APPEND with the ability to specify a separator,
78+
dnl because we have a newline separator in the string.
79+
AS_IF([AS_VAR_TEST_SET([opal_summary_section_]AS_TR_SH([$1])[_value])],
80+
[AS_VAR_APPEND([opal_summary_section_]AS_TR_SH([$1])[_value],
81+
["${opal_summary_newline}${opal_summary_line}"])],
82+
[AS_VAR_SET([opal_summary_section_]AS_TR_SH([$1])[_value],
83+
["${opal_summary_line}"])])])
3384
3485
OPAL_VAR_SCOPE_POP
3586
])
3687

3788
AC_DEFUN([OPAL_SUMMARY_PRINT],[
38-
OPAL_VAR_SCOPE_PUSH([ompi_summary_section ompi_summary_section_name])
89+
OPAL_VAR_SCOPE_PUSH([opal_summary_section opal_summary_section_name])
3990
cat <<EOF
4091
4192
Open MPI configuration:
@@ -90,11 +141,12 @@ EOF
90141
91142
echo
92143
93-
for ompi_summary_section in $(echo $ompi_summary_sections) ; do
94-
ompi_summary_section_name=$(echo $ompi_summary_section | tr '_' ' ')
95-
echo "$ompi_summary_section_name"
144+
for opal_summary_section in ${opal_summary_sections} ; do
145+
AS_VAR_COPY([opal_summary_section_name], [opal_summary_section_${opal_summary_section}_name])
146+
AS_VAR_COPY([opal_summary_section_value], [opal_summary_section_${opal_summary_section}_value])
147+
echo "${opal_summary_section_name}"
96148
echo "-----------------------"
97-
echo "$(eval echo \$ompi_summary_values_$ompi_summary_section)" | tr ',' $'\n' | sort -f
149+
echo "${opal_summary_section_value}" | sort -f
98150
echo " "
99151
done
100152

0 commit comments

Comments
 (0)