|
| 1 | +From 72ba0a6d531ab0cc325895bf57e5fba2edebd591 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Mika Laitio < [email protected]> |
| 3 | +Date: Wed, 29 May 2024 14:15:28 -0700 |
| 4 | +Subject: [PATCH 3/3] added construct_event_strings.py thats missing tar.gz |
| 5 | + |
| 6 | +patching of git submodules does not work well |
| 7 | +yet with the rcom sdk builder, therefore openmpi |
| 8 | +and all it's submodules has been put to single repo. |
| 9 | + |
| 10 | +release openmpi-5.0.1.tar.bz2 used as a source however missed the |
| 11 | +construct_event_strings.py. |
| 12 | + |
| 13 | +Another patch just added for gcc14 updating the headers |
| 14 | +seems to trigger the usage of this python file. |
| 15 | +(Earlier it compiled ok because this python script was not tried to call) |
| 16 | + |
| 17 | +Signed-off-by: Mika Laitio < [email protected]> |
| 18 | +--- |
| 19 | + .../contrib/construct_event_strings.py | 242 ++++++++++++++++++ |
| 20 | + 1 file changed, 242 insertions(+) |
| 21 | + create mode 100755 3rd-party/openpmix/contrib/construct_event_strings.py |
| 22 | + |
| 23 | +diff --git a/3rd-party/openpmix/contrib/construct_event_strings.py b/3rd-party/openpmix/contrib/construct_event_strings.py |
| 24 | +new file mode 100755 |
| 25 | +index 0000000..52f242f |
| 26 | +--- /dev/null |
| 27 | ++++ b/3rd-party/openpmix/contrib/construct_event_strings.py |
| 28 | +@@ -0,0 +1,242 @@ |
| 29 | ++# |
| 30 | ++# Copyright (c) 2020 Intel, Inc. All rights reserved. |
| 31 | ++# Copyright (c) 2020-2022 Cisco Systems, Inc. All rights reserved |
| 32 | ++# Copyright (c) 2021-2023 Nanook Consulting. All rights reserved. |
| 33 | ++# Copyright (c) 2022 Triad National Security, LLC. All rights reserved. |
| 34 | ++# $COPYRIGHT$ |
| 35 | ++# |
| 36 | ++# Construct a dictionary for translating attributes to/from |
| 37 | ++# their defined name and their string representation - used |
| 38 | ++# by tools to interpret user input |
| 39 | ++# |
| 40 | ++ |
| 41 | ++from __future__ import print_function |
| 42 | ++import os |
| 43 | ++import os.path |
| 44 | ++import sys |
| 45 | ++from optparse import OptionParser, OptionGroup |
| 46 | ++ |
| 47 | ++index = 0 |
| 48 | ++ |
| 49 | ++ |
| 50 | ++def harvest_constants(options, path, constants): |
| 51 | ++ global index |
| 52 | ++ # open the file |
| 53 | ++ try: |
| 54 | ++ inputfile = open(path, "r") |
| 55 | ++ except Exception as e: |
| 56 | ++ print("File {path} could not be opened: {e}" |
| 57 | ++ .format(path=path, e=e)) |
| 58 | ++ return 1 |
| 59 | ++ |
| 60 | ++ # read the file - these files aren't too large |
| 61 | ++ # so ingest the whole thing at one gulp |
| 62 | ++ try: |
| 63 | ++ lines = inputfile.readlines() |
| 64 | ++ except Exception as e: |
| 65 | ++ print("Error reading file {path}: {e}" |
| 66 | ++ .format(path=path, e=e)) |
| 67 | ++ inputfile.close() |
| 68 | ++ return 1 |
| 69 | ++ |
| 70 | ++ inputfile.close() # we read everything, so done with the file |
| 71 | ++ |
| 72 | ++ firstline = True |
| 73 | ++ |
| 74 | ++ # find the start of the event codes |
| 75 | ++ n = 0 |
| 76 | ++ found = False |
| 77 | ++ while n < len(lines): |
| 78 | ++ if "PMIX ERROR CONSTANTS" in lines[n]: |
| 79 | ++ found = True |
| 80 | ++ n = n + 1 |
| 81 | ++ break; |
| 82 | ++ n = n + 1 |
| 83 | ++ # error out if not found |
| 84 | ++ if not found: |
| 85 | ++ print("START OF EVENT CODES NOT FOUND") |
| 86 | ++ return 1 |
| 87 | ++ |
| 88 | ++ # loop over the lines |
| 89 | ++ while n < len(lines): |
| 90 | ++ line = lines[n] |
| 91 | ++ # remove white space at front and back |
| 92 | ++ myline = line.strip() |
| 93 | ++ # remove comment lines |
| 94 | ++ if "/*" in myline or "*/" in myline or myline.startswith("*"): |
| 95 | ++ n = n + 1 |
| 96 | ++ continue |
| 97 | ++ # if we have found the end of the event codes, we are done |
| 98 | ++ if "PMIX_EXTERNAL_ERR_BASE" in myline or "PMIX_ERR_SYS_BASE" in myline or "PMIX_INTERNAL_ERR_DONE" in myline: |
| 99 | ++ return 0 |
| 100 | ++ # skip a well-known macro |
| 101 | ++ if "PMIX_SYSTEM_EVENT" in myline: |
| 102 | ++ n = n + 2 |
| 103 | ++ continue |
| 104 | ++ # if the line starts with #define, then we want it |
| 105 | ++ if not myline.startswith("#define"): |
| 106 | ++ n = n + 1 |
| 107 | ++ continue |
| 108 | ++ |
| 109 | ++ value = myline[8:] |
| 110 | ++ tokens = value.split() |
| 111 | ++ if not firstline: |
| 112 | ++ constants.write(",\n\n") |
| 113 | ++ firstline = False |
| 114 | ++ constants.write(" {.index = " + str(index) + ", .name = \"" + tokens[0] + "\", .code = " + str(tokens[1]) + "}") |
| 115 | ++ index = index + 1 |
| 116 | ++ n = n + 1 |
| 117 | ++ |
| 118 | ++ return 0 |
| 119 | ++ |
| 120 | ++ |
| 121 | ++def _write_header(options, base_path, num_elements): |
| 122 | ++ contents = '''/* |
| 123 | ++ * This file is autogenerated by construct_event_strings.py. |
| 124 | ++ * Do not edit this file by hand. |
| 125 | ++ */ |
| 126 | ++ |
| 127 | ++#include "src/include/pmix_config.h" |
| 128 | ++#include "src/include/pmix_globals.h" |
| 129 | ++#include "include/pmix_common.h" |
| 130 | ++ |
| 131 | ++#ifndef PMIX_EVENT_STRINGS_H |
| 132 | ++#define PMIX_EVENT_STRINGS_H |
| 133 | ++ |
| 134 | ++BEGIN_C_DECLS |
| 135 | ++ |
| 136 | ++PMIX_EXPORT extern const pmix_event_string_t pmix_event_strings[{ne}]; |
| 137 | ++ |
| 138 | ++#define PMIX_EVENT_INDEX_BOUNDARY {nem1} |
| 139 | ++ |
| 140 | ++END_C_DECLS |
| 141 | ++ |
| 142 | ++#endif\n |
| 143 | ++'''.format(ne=num_elements, nem1=num_elements - 1) |
| 144 | ++ |
| 145 | ++ if options.dryrun: |
| 146 | ++ constants = sys.stdout |
| 147 | ++ outpath = None |
| 148 | ++ else: |
| 149 | ++ outpath = os.path.join(base_path, "pmix_event_strings.h") |
| 150 | ++ try: |
| 151 | ++ constants = open(outpath, "w+") |
| 152 | ++ except Exception as e: |
| 153 | ++ print("{outpath} CANNOT BE OPENED - EVENT STRINGS COULD NOT BE CONSTRUCTED: {e}" |
| 154 | ++ .format(outpath=outpath, e=e)) |
| 155 | ++ return 1 |
| 156 | ++ constants.write(contents) |
| 157 | ++ constants.close() |
| 158 | ++ return 0 |
| 159 | ++ |
| 160 | ++ |
| 161 | ++def main(): |
| 162 | ++ parser = OptionParser("usage: %prog [options]") |
| 163 | ++ debugGroup = OptionGroup(parser, "Debug Options") |
| 164 | ++ debugGroup.add_option("--dryrun", |
| 165 | ++ action="store_true", dest="dryrun", default=False, |
| 166 | ++ help="Show output to screen") |
| 167 | ++ parser.add_option_group(debugGroup) |
| 168 | ++ |
| 169 | ++ (options, args) = parser.parse_args() |
| 170 | ++ |
| 171 | ++ # Find the top-level PMIx source tree dir. |
| 172 | ++ # Start with the location of this script, which we know is in |
| 173 | ++ # $top_srcdir/contrib. |
| 174 | ++ top_src_dir = os.path.dirname(sys.argv[0]) |
| 175 | ++ top_src_dir = os.path.join(top_src_dir, "..") |
| 176 | ++ top_src_dir = os.path.abspath(top_src_dir) |
| 177 | ++ |
| 178 | ++ # Sanity check |
| 179 | ++ checkfile = os.path.join(top_src_dir, "VERSION") |
| 180 | ++ if not os.path.exists(checkfile): |
| 181 | ++ print("ERROR: Could not find top source directory for Open PMIx") |
| 182 | ++ return 1 |
| 183 | ++ |
| 184 | ++ source_include_dir = os.path.join(top_src_dir, "include") |
| 185 | ++ util_include_dir = os.path.join(top_src_dir, "src", "util") |
| 186 | ++ |
| 187 | ++ # This script is invoked from src/include/Makefile.am, and |
| 188 | ++ # therefore the cwd will be $(builddir)/src/include. Verify this |
| 189 | ++ # by checking for a file that we know should be in there. |
| 190 | ++ build_src_include_dir = os.getcwd() |
| 191 | ++ checkfile = os.path.join(build_src_include_dir, "pmix_config.h") |
| 192 | ++ if not os.path.exists(checkfile): |
| 193 | ++ print("ERROR: Could not find build directory for Open PMIx") |
| 194 | ++ return 1 |
| 195 | ++ |
| 196 | ++ if options.dryrun: |
| 197 | ++ constants = sys.stdout |
| 198 | ++ outpath = None |
| 199 | ++ else: |
| 200 | ++ outpath = os.path.join(build_src_include_dir, "pmix_event_strings.c") |
| 201 | ++ try: |
| 202 | ++ constants = open(outpath, "w+") |
| 203 | ++ except Exception as e: |
| 204 | ++ print("{outpath} CANNOT BE OPENED - EVENT STRINGS COULD NOT BE CONSTRUCTED: {e}" |
| 205 | ++ .format(outpath=outpath, e=e)) |
| 206 | ++ return 1 |
| 207 | ++ |
| 208 | ++ # write the source file |
| 209 | ++ constants.write("""/* |
| 210 | ++ * This file is autogenerated by construct_event_strings.py. |
| 211 | ++ * Do not edit this file by hand. |
| 212 | ++ */ |
| 213 | ++ |
| 214 | ++#include "src/include/pmix_event_strings.h" |
| 215 | ++ |
| 216 | ++const pmix_event_string_t pmix_event_strings[] = { |
| 217 | ++""") |
| 218 | ++ |
| 219 | ++ # scan across the header files in the src directory |
| 220 | ++ # looking for events |
| 221 | ++ |
| 222 | ++ # pmix_common.h.in is in the src tree |
| 223 | ++ rc = harvest_constants(options, |
| 224 | ++ os.path.join(source_include_dir, "pmix_common.h.in"), |
| 225 | ++ constants) |
| 226 | ++ if 0 != rc: |
| 227 | ++ constants.close() |
| 228 | ++ if outpath: |
| 229 | ++ os.remove(outpath) |
| 230 | ++ print("HARVEST PMIX_COMMON FAILED - EVENT STRINGS COULD NOT BE CONSTRUCTED") |
| 231 | ++ return 1 |
| 232 | ++ constants.write(",\n\n") |
| 233 | ++ |
| 234 | ++ # pmix_deprecated.h is in the source tree |
| 235 | ++ rc = harvest_constants(options, |
| 236 | ++ os.path.join(source_include_dir, "pmix_deprecated.h"), |
| 237 | ++ constants) |
| 238 | ++ if 0 != rc: |
| 239 | ++ constants.close() |
| 240 | ++ if outpath: |
| 241 | ++ os.remove(outpath) |
| 242 | ++ print("HARVEST PMIX_DEPRECATED FAILED - EVENT STRINGS COULD NOT BE CONSTRUCTED") |
| 243 | ++ return 1 |
| 244 | ++ constants.write(",\n\n") |
| 245 | ++ |
| 246 | ++ # pmix_error.h is in the source tree |
| 247 | ++ rc = harvest_constants(options, |
| 248 | ++ os.path.join(util_include_dir, "pmix_error.h"), |
| 249 | ++ constants) |
| 250 | ++ if 0 != rc: |
| 251 | ++ constants.close() |
| 252 | ++ if outpath: |
| 253 | ++ os.remove(outpath) |
| 254 | ++ print("HARVEST PMIX_ERROR FAILED - EVENT STRINGS COULD NOT BE CONSTRUCTED") |
| 255 | ++ return 1 |
| 256 | ++ |
| 257 | ++ # mark the end of the array |
| 258 | ++ constants.write(""",\n |
| 259 | ++ {.index = UINT32_MAX, .name = "", .code = -1} |
| 260 | ++}; |
| 261 | ++""") |
| 262 | ++ constants.write("\n") |
| 263 | ++ constants.close() |
| 264 | ++ |
| 265 | ++ # write the header |
| 266 | ++ return _write_header(options, build_src_include_dir, index + 1) |
| 267 | ++ |
| 268 | ++ |
| 269 | ++if __name__ == '__main__': |
| 270 | ++ exit(main()) |
| 271 | +-- |
| 272 | +2.45.1 |
| 273 | + |
0 commit comments