|
2 | 2 | # Copyright (c) 2020 Intel, Inc. All rights reserved.
|
3 | 3 | # Copyright (c) 2020 Cisco Systems, Inc. All rights reserved
|
4 | 4 | # Copyright (c) 2021-2022 Nanook Consulting. All rights reserved.
|
| 5 | +# Copyright (c) 2022 Triad National Security, LLC. All rights reserved. |
5 | 6 | # $COPYRIGHT$
|
6 | 7 | #
|
7 | 8 | # Construct a dictionary for translating attributes to/from
|
|
10 | 11 | #
|
11 | 12 |
|
12 | 13 | from __future__ import print_function
|
13 |
| -import os, os.path, sys, shutil |
| 14 | +import os |
| 15 | +import os.path |
| 16 | +import sys |
14 | 17 | from optparse import OptionParser, OptionGroup
|
15 | 18 |
|
16 | 19 | index = 0
|
17 | 20 |
|
| 21 | + |
18 | 22 | def harvest_constants(options, path, constants):
|
19 | 23 | global index
|
20 | 24 | # open the file
|
@@ -234,6 +238,47 @@ def harvest_constants(options, path, constants):
|
234 | 238 | inputfile.close()
|
235 | 239 | return 0
|
236 | 240 |
|
| 241 | + |
| 242 | +def _write_header(options, base_path, num_elements): |
| 243 | + contents = '''/* |
| 244 | + * This file is autogenerated by construct_dictionary.py. |
| 245 | + * Do not edit this file by hand. |
| 246 | + */ |
| 247 | +
|
| 248 | +#include "src/include/pmix_config.h" |
| 249 | +#include "src/include/pmix_globals.h" |
| 250 | +#include "include/pmix_common.h" |
| 251 | +
|
| 252 | +#ifndef PMIX_DICTIONARY_H |
| 253 | +#define PMIX_DICTIONARY_H |
| 254 | +
|
| 255 | +BEGIN_C_DECLS |
| 256 | +
|
| 257 | +PMIX_EXPORT extern const pmix_regattr_input_t pmix_dictionary[{}]; |
| 258 | +
|
| 259 | +#define PMIX_INDEX_BOUNDARY {} |
| 260 | +
|
| 261 | +END_C_DECLS |
| 262 | +
|
| 263 | +#endif\n |
| 264 | +'''.format(num_elements, num_elements - 1) |
| 265 | + |
| 266 | + if options.dryrun: |
| 267 | + constants = sys.stdout |
| 268 | + outpath = None |
| 269 | + else: |
| 270 | + outpath = os.path.join(base_path, "pmix_dictionary.h") |
| 271 | + try: |
| 272 | + constants = open(outpath, "w+") |
| 273 | + except Exception as e: |
| 274 | + print("{outpath} CANNOT BE OPENED - DICTIONARY COULD NOT BE CONSTRUCTED: {e}" |
| 275 | + .format(outpath=outpath, e=e)) |
| 276 | + return 1 |
| 277 | + constants.write(contents) |
| 278 | + constants.close() |
| 279 | + return 0 |
| 280 | + |
| 281 | + |
237 | 282 | def main():
|
238 | 283 | parser = OptionParser("usage: %prog [options]")
|
239 | 284 | debugGroup = OptionGroup(parser, "Debug Options")
|
@@ -272,24 +317,23 @@ def main():
|
272 | 317 | constants = sys.stdout
|
273 | 318 | outpath = None
|
274 | 319 | else:
|
275 |
| - outpath = os.path.join(build_src_include_dir, "dictionary.h") |
| 320 | + outpath = os.path.join(build_src_include_dir, "pmix_dictionary.c") |
276 | 321 | try:
|
277 | 322 | constants = open(outpath, "w+")
|
278 | 323 | except Exception as e:
|
279 | 324 | print("{outpath} CANNOT BE OPENED - DICTIONARY COULD NOT BE CONSTRUCTED: {e}"
|
280 | 325 | .format(outpath=outpath, e=e))
|
281 | 326 | return 1
|
282 | 327 |
|
283 |
| - # write the header |
| 328 | + # write the source file |
284 | 329 | constants.write("""/*
|
285 | 330 | * This file is autogenerated by construct_dictionary.py.
|
286 | 331 | * Do not edit this file by hand.
|
287 | 332 | */
|
288 | 333 |
|
289 |
| -#include "src/include/pmix_config.h" |
290 |
| -#include "src/include/pmix_globals.h" |
| 334 | +#include "src/include/pmix_dictionary.h" |
291 | 335 |
|
292 |
| -static pmix_regattr_input_t dictionary[] = { |
| 336 | +const pmix_regattr_input_t pmix_dictionary[] = { |
293 | 337 | """)
|
294 | 338 |
|
295 | 339 | # scan across the header files in the src directory
|
@@ -323,9 +367,12 @@ def main():
|
323 | 367 | {.index = UINT32_MAX, .name = "", .string = "", .type = PMIX_POINTER, .description = (char *[]){"NONE", NULL}}
|
324 | 368 | };
|
325 | 369 | """)
|
326 |
| - constants.write("\n#define PMIX_INDEX_BOUNDARY " + str(index) + "\n") |
| 370 | + constants.write("\n") |
327 | 371 | constants.close()
|
328 |
| - return 0 |
| 372 | + |
| 373 | + # write the header |
| 374 | + return _write_header(options, build_src_include_dir, index + 1) |
| 375 | + |
329 | 376 |
|
330 | 377 | if __name__ == '__main__':
|
331 | 378 | exit(main())
|
0 commit comments