mirror of https://github.com/ARMmbed/mbed-os.git
Simplify main function
parent
71323af2f5
commit
44030c23d3
146
tools/project.py
146
tools/project.py
|
@ -142,15 +142,27 @@ def export(target, ide, build=None, src=None, macros=None, project_id=None,
|
||||||
libraries_paths=lib,
|
libraries_paths=lib,
|
||||||
zip_proj=zip_name,
|
zip_proj=zip_name,
|
||||||
build_profile=build_profile,
|
build_profile=build_profile,
|
||||||
notify=notify,
|
notify=TerminalNotifier(),
|
||||||
app_config=app_config,
|
app_config=app_config,
|
||||||
ignore=ignore
|
ignore=ignore
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def clean(source_dir):
|
||||||
|
if exists(EXPORT_DIR):
|
||||||
|
rmtree(EXPORT_DIR)
|
||||||
|
for cls in EXPORTERS.values():
|
||||||
|
try:
|
||||||
|
cls.clean(basename(abspath(source_dir[0])))
|
||||||
|
except (NotImplementedError, IOError, OSError):
|
||||||
|
pass
|
||||||
|
for f in list(EXPORTERS.values())[0].CLEAN_FILES:
|
||||||
|
try:
|
||||||
|
remove(f)
|
||||||
|
except (IOError, OSError):
|
||||||
|
pass
|
||||||
|
|
||||||
def main():
|
|
||||||
"""Entry point"""
|
def get_args(argv):
|
||||||
# Parse Options
|
|
||||||
parser = ArgumentParser()
|
parser = ArgumentParser()
|
||||||
|
|
||||||
targetnames = TARGET_NAMES
|
targetnames = TARGET_NAMES
|
||||||
|
@ -221,6 +233,13 @@ def main():
|
||||||
help="displays supported matrix of MCUs and IDEs"
|
help="displays supported matrix of MCUs and IDEs"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
group.add_argument(
|
||||||
|
"--update-packs",
|
||||||
|
dest="update_packs",
|
||||||
|
action="store_true",
|
||||||
|
default=False
|
||||||
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-E",
|
"-E",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
|
@ -264,13 +283,6 @@ def main():
|
||||||
default=[]
|
default=[]
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
|
||||||
"--update-packs",
|
|
||||||
dest="update_packs",
|
|
||||||
action="store_true",
|
|
||||||
default=False
|
|
||||||
)
|
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--app-config",
|
"--app-config",
|
||||||
dest="app_config",
|
dest="app_config",
|
||||||
|
@ -286,92 +298,70 @@ def main():
|
||||||
"(eg. ./main.cpp)")
|
"(eg. ./main.cpp)")
|
||||||
)
|
)
|
||||||
|
|
||||||
options = parser.parse_args()
|
return parser.parse_args(argv), parser
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""Entry point"""
|
||||||
|
# Parse Options
|
||||||
|
options, parser = get_args(sys.argv)
|
||||||
|
|
||||||
# Print available tests in order and exit
|
# Print available tests in order and exit
|
||||||
if options.list_tests is True:
|
if options.list_tests:
|
||||||
print('\n'.join(str(test) for test in sorted(TEST_MAP.values())))
|
print('\n'.join(str(test) for test in sorted(TEST_MAP.values())))
|
||||||
sys.exit()
|
elif options.supported_ides:
|
||||||
|
|
||||||
# Only prints matrix of supported IDEs
|
|
||||||
if options.supported_ides:
|
|
||||||
if options.supported_ides == "matrix":
|
if options.supported_ides == "matrix":
|
||||||
print_large_string(mcu_ide_matrix())
|
print_large_string(mcu_ide_matrix())
|
||||||
elif options.supported_ides == "ides":
|
elif options.supported_ides == "ides":
|
||||||
print(mcu_ide_list())
|
print(mcu_ide_list())
|
||||||
exit(0)
|
elif options.supported_ides_html:
|
||||||
|
|
||||||
# Only prints matrix of supported IDEs
|
|
||||||
if options.supported_ides_html:
|
|
||||||
html = mcu_ide_matrix(verbose_html=True)
|
html = mcu_ide_matrix(verbose_html=True)
|
||||||
with open("./export/README.md", "w") as readme:
|
with open("./export/README.md", "w") as readme:
|
||||||
readme.write("Exporter IDE/Platform Support\n")
|
readme.write("Exporter IDE/Platform Support\n")
|
||||||
readme.write("-----------------------------------\n")
|
readme.write("-----------------------------------\n")
|
||||||
readme.write("\n")
|
readme.write("\n")
|
||||||
readme.write(html)
|
readme.write(html)
|
||||||
exit(0)
|
elif options.update_packs:
|
||||||
|
|
||||||
if options.update_packs:
|
|
||||||
from tools.arm_pack_manager import Cache
|
from tools.arm_pack_manager import Cache
|
||||||
cache = Cache(True, True)
|
cache = Cache(True, True)
|
||||||
cache.cache_everything()
|
cache.cache_everything()
|
||||||
|
else:
|
||||||
|
# Check required arguments
|
||||||
|
if not options.mcu:
|
||||||
|
args_error(parser, "argument -m/--mcu is required")
|
||||||
|
if not options.ide:
|
||||||
|
args_error(parser, "argument -i is required")
|
||||||
|
if (options.program is None) and (not options.source_dir):
|
||||||
|
args_error(parser, "one of -p, -n, or --source is required")
|
||||||
|
|
||||||
# Target
|
if options.clean:
|
||||||
if not options.mcu:
|
clean(options.source_dir)
|
||||||
args_error(parser, "argument -m/--mcu is required")
|
|
||||||
|
|
||||||
# Toolchain
|
ide = resolve_exporter_alias(options.ide)
|
||||||
if not options.ide:
|
exporter, toolchain_name = get_exporter_toolchain(ide)
|
||||||
args_error(parser, "argument -i is required")
|
profile = extract_profile(parser, options, toolchain_name, fallback="debug")
|
||||||
|
mcu = extract_mcus(parser, options)[0]
|
||||||
|
if not exporter.is_target_supported(mcu):
|
||||||
|
args_error(parser, "%s not supported by %s" % (mcu, ide))
|
||||||
|
|
||||||
# Clean Export Directory
|
try:
|
||||||
if options.clean:
|
export(
|
||||||
if exists(EXPORT_DIR):
|
mcu,
|
||||||
rmtree(EXPORT_DIR)
|
ide,
|
||||||
|
build=options.build,
|
||||||
zip_proj = not bool(options.source_dir)
|
src=options.source_dir,
|
||||||
|
macros=options.macros,
|
||||||
notify = TerminalNotifier()
|
project_id=options.program,
|
||||||
|
zip_proj=not bool(options.source_dir),
|
||||||
ide = resolve_exporter_alias(options.ide)
|
build_profile=profile,
|
||||||
exporter, toolchain_name = get_exporter_toolchain(ide)
|
app_config=options.app_config,
|
||||||
profile = extract_profile(parser, options, toolchain_name, fallback="debug")
|
export_path=options.build_dir,
|
||||||
mcu = extract_mcus(parser, options)[0]
|
ignore=options.ignore
|
||||||
|
)
|
||||||
if not exporter.is_target_supported(mcu):
|
except NotSupportedException as exc:
|
||||||
args_error(parser, "%s not supported by %s" % (mcu, ide))
|
args_error(parser, "%s not supported by %s" % (mcu, ide))
|
||||||
|
print("[Not Supported] %s" % str(exc))
|
||||||
if (options.program is None) and (not options.source_dir):
|
exit(0)
|
||||||
args_error(parser, "one of -p, -n, or --source is required")
|
|
||||||
|
|
||||||
if options.clean:
|
|
||||||
for cls in EXPORTERS.values():
|
|
||||||
try:
|
|
||||||
cls.clean(basename(abspath(options.source_dir[0])))
|
|
||||||
except (NotImplementedError, IOError, OSError):
|
|
||||||
pass
|
|
||||||
for f in list(EXPORTERS.values())[0].CLEAN_FILES:
|
|
||||||
try:
|
|
||||||
remove(f)
|
|
||||||
except (IOError, OSError):
|
|
||||||
pass
|
|
||||||
try:
|
|
||||||
export(
|
|
||||||
mcu,
|
|
||||||
ide,
|
|
||||||
build=options.build,
|
|
||||||
src=options.source_dir,
|
|
||||||
macros=options.macros,
|
|
||||||
project_id=options.program,
|
|
||||||
zip_proj=zip_proj,
|
|
||||||
build_profile=profile,
|
|
||||||
app_config=options.app_config,
|
|
||||||
export_path=options.build_dir,
|
|
||||||
notify=notify,
|
|
||||||
ignore=options.ignore
|
|
||||||
)
|
|
||||||
except NotSupportedException as exc:
|
|
||||||
print("[Not Supported] %s" % str(exc))
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in New Issue