Skip to content

Commit

Permalink
enhancement: by default, the script will output symbols, unless the -…
Browse files Browse the repository at this point in the history
…-diff option is provided
  • Loading branch information
mattkae committed Apr 19, 2024
1 parent 5a7d34f commit 377750b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 16 deletions.
1 change: 0 additions & 1 deletion src/miral/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ add_custom_target(
--symbols-map-path="${CMAKE_CURRENT_SOURCE_DIR}/symbols.map"
--external-headers-directory="${PROJECT_SOURCE_DIR}/include/miral"
--include-dirs "$<JOIN:$<TARGET_PROPERTY:miral,INCLUDE_DIRECTORIES>,:>"
--output-symbols
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}")

add_custom_target(
Expand Down
1 change: 0 additions & 1 deletion src/miroil/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ add_custom_target(
--symbols-map-path="${CMAKE_CURRENT_SOURCE_DIR}/symbols.map"
--external-headers-directory="${PROJECT_SOURCE_DIR}/include/miroil"
--include-dirs "$<JOIN:$<TARGET_PROPERTY:miroil,INCLUDE_DIRECTORIES>,:>"
--output-symbols
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}")

add_custom_target(
Expand Down
21 changes: 7 additions & 14 deletions tools/symbols_map_generator/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ def report_symbols_diff(previous_symbols: list[Symbol], new_symbols: set[str], i
def main():
parser = argparse.ArgumentParser(description="This tool parses the header files of a provided in the Mir project "
"and process a list of new internal and external symbols. "
"To view this list, the user may provide the --diff option. To modify the corresponding "
"symbols.map files automatically, the user may specify the --output_symbols option. "
"By default, the script updates the corresponding symbols.map file automatically. "
"To view this diff only, the user may provide the --diff option. "
"The tool uses https://pypi.org/project/libclang/ to process "
"the AST of the project's header files.\n\nIf the content of the outputted map "
"file appears incorrect, trying using a later version of clang (e.g. clang 19). You can do this "
Expand Down Expand Up @@ -321,20 +321,16 @@ def main():
required=True)
parser.add_argument('--diff', action='store_true',
help='if true a diff should be output to the console')
parser.add_argument('--output-symbols', action='store_true',
help='if true, the symbols.map file will be updated with the new new symbols',
dest='output_symbols')
parser.add_argument('--include-dirs', type=str, help="colon separated list of directories to search for symbols",
required=True, dest='include_dirs')

args = parser.parse_args()
logging.basicConfig(level=logging.INFO)

if args.output_symbols:
_logger.info("symbols_map_generator is running in 'output symbols' mode")

if args.diff:
_logger.info("symbols_map_generator is running in 'diff' mode")
else:
_logger.info("symbols_map_generator is running in 'output symbols' mode")

# Point libclang to a file on the system
if 'MIR_SYMBOLS_MAP_GENERATOR_CLANG_SO_PATH' in os.environ:
Expand Down Expand Up @@ -394,8 +390,9 @@ def main():
print("Internal Symbols Diff:")
has_changed_symbols = has_changed_symbols or report_symbols_diff(previous_symbols, internal_symbols, True)
print("")

if args.output_symbols:
if has_changed_symbols:
exit(1)
else:
_logger.info(f"Outputting the symbols file to: {args.symbols_map_path}")

# We now have a list of new external and internal symbols. Our goal now is to add them to the correct stanzas
Expand Down Expand Up @@ -478,10 +475,6 @@ def main():
'''

f.write(output_str)

if args.diff and has_changed_symbols:
exit(1)



if __name__ == "__main__":
Expand Down

0 comments on commit 377750b

Please sign in to comment.