diff --git a/tools/ldgen/ldgen.py b/tools/ldgen/ldgen.py index 22661ee6df4..369de57cfa0 100755 --- a/tools/ldgen/ldgen.py +++ b/tools/ldgen/ldgen.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2021-2026 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: Apache-2.0 # import argparse @@ -23,7 +23,7 @@ from pyparsing import ParseFatalException def _update_environment(args): - env = [(name, value) for (name,value) in (e.split('=',1) for e in args.env)] + env = [(name, value) for (name, value) in (e.split('=', 1) for e in args.env)] for name, value in env: value = ' '.join(value.split()) os.environ[name] = value @@ -68,71 +68,55 @@ def _run_objdump(objdump, library): def main(): - argparser = argparse.ArgumentParser(description='ESP-IDF linker script generator') - argparser.add_argument( - '--input', '-i', - help='Linker template file', - type=argparse.FileType('r')) + argparser.add_argument('--input', '-i', help='Linker template file', type=argparse.FileType('r')) fragments_group = argparser.add_mutually_exclusive_group() fragments_group.add_argument( - '--fragments', '-f', - type=argparse.FileType('r'), - help='Input fragment files', - nargs='+' + '--fragments', '-f', type=argparse.FileType('r'), help='Input fragment files', nargs='+' ) fragments_group.add_argument( - '--fragments-list', - help='Input fragment files as a semicolon-separated list', - type=str + '--fragments-list', help='Input fragment files as a semicolon-separated list', type=str ) argparser.add_argument( - '--libraries-file', + '--libraries-file', type=argparse.FileType('r'), help='File that contains the list of libraries in the build' + ) + + argparser.add_argument('--output', '-o', help='Output linker script', type=str) + + argparser.add_argument('--config', '-c', help='Project configuration') + + argparser.add_argument('--kconfig', '-k', help='IDF Kconfig file') + + argparser.add_argument( + '--check-mapping', help='Perform a check if a mapping (archive, obj, symbol) exists', action='store_true' + ) + + argparser.add_argument( + '--check-mapping-exceptions', help='Mappings exempted from check', type=argparse.FileType('r') + ) + + argparser.add_argument( + '--env', + '-e', + action='append', + default=[], + help='Environment to set when evaluating the config file', + metavar='NAME=VAL', + ) + + argparser.add_argument( + '--env-file', type=argparse.FileType('r'), - help='File that contains the list of libraries in the build') - - argparser.add_argument( - '--output', '-o', - help='Output linker script', - type=str) - - argparser.add_argument( - '--config', '-c', - help='Project configuration') - - argparser.add_argument( - '--kconfig', '-k', - help='IDF Kconfig file') - - argparser.add_argument( - '--check-mapping', - help='Perform a check if a mapping (archive, obj, symbol) exists', - action='store_true' + help='Optional file to load environment variables from. Contents ' + 'should be a JSON object where each key/value pair is a variable.', ) - argparser.add_argument( - '--check-mapping-exceptions', - help='Mappings exempted from check', - type=argparse.FileType('r') - ) - - argparser.add_argument( - '--env', '-e', - action='append', default=[], - help='Environment to set when evaluating the config file', metavar='NAME=VAL') - - argparser.add_argument('--env-file', type=argparse.FileType('r'), - help='Optional file to load environment variables from. Contents ' - 'should be a JSON object where each key/value pair is a variable.') - - argparser.add_argument( - '--objdump', - help='Path to toolchain objdump') + argparser.add_argument('--objdump', help='Path to toolchain objdump') args = argparser.parse_args() @@ -210,7 +194,9 @@ def main(): if exc.errno != errno.EEXIST: raise - with open(output_path, 'w', encoding='utf-8') as f: # only create output file after generation has succeeded + with open( + output_path, 'w', encoding='utf-8' + ) as f: # only create output file after generation has succeeded f.write(output.read()) except LdGenFailure as e: print('linker script generation failed for %s\nERROR: %s' % (input_file.name, e))