mirror of https://github.com/ARMmbed/mbed-os.git
Reformat part of project.py
parent
b56a7a6a5a
commit
71323af2f5
199
tools/project.py
199
tools/project.py
|
@ -16,11 +16,22 @@ from argparse import ArgumentParser
|
||||||
|
|
||||||
from tools.paths import EXPORT_DIR, MBED_HAL, MBED_LIBRARIES, MBED_TARGETS_PATH
|
from tools.paths import EXPORT_DIR, MBED_HAL, MBED_LIBRARIES, MBED_TARGETS_PATH
|
||||||
from tools.settings import BUILD_DIR
|
from tools.settings import BUILD_DIR
|
||||||
from tools.export import EXPORTERS, mcu_ide_matrix, mcu_ide_list, export_project, get_exporter_toolchain
|
from tools.export import (
|
||||||
|
EXPORTERS,
|
||||||
|
mcu_ide_matrix,
|
||||||
|
mcu_ide_list,
|
||||||
|
export_project,
|
||||||
|
get_exporter_toolchain,
|
||||||
|
)
|
||||||
from tools.tests import TESTS, TEST_MAP
|
from tools.tests import TESTS, TEST_MAP
|
||||||
from tools.tests import test_known, test_name_known, Test
|
from tools.tests import test_known, test_name_known, Test
|
||||||
from tools.targets import TARGET_NAMES
|
from tools.targets import TARGET_NAMES
|
||||||
from tools.utils import argparse_filestring_type, argparse_profile_filestring_type, argparse_many, args_error
|
from tools.utils import (
|
||||||
|
argparse_filestring_type,
|
||||||
|
argparse_profile_filestring_type,
|
||||||
|
argparse_many,
|
||||||
|
args_error,
|
||||||
|
)
|
||||||
from tools.utils import argparse_force_lowercase_type
|
from tools.utils import argparse_force_lowercase_type
|
||||||
from tools.utils import argparse_force_uppercase_type
|
from tools.utils import argparse_force_uppercase_type
|
||||||
from tools.utils import print_large_string
|
from tools.utils import print_large_string
|
||||||
|
@ -41,7 +52,14 @@ def resolve_exporter_alias(ide):
|
||||||
return ide
|
return ide
|
||||||
|
|
||||||
|
|
||||||
def setup_project(ide, target, program=None, source_dir=None, build=None, export_path=None):
|
def setup_project(
|
||||||
|
ide,
|
||||||
|
target,
|
||||||
|
program=None,
|
||||||
|
source_dir=None,
|
||||||
|
build=None,
|
||||||
|
export_path=None
|
||||||
|
):
|
||||||
"""Generate a name, if not provided, and find dependencies
|
"""Generate a name, if not provided, and find dependencies
|
||||||
|
|
||||||
Positional arguments:
|
Positional arguments:
|
||||||
|
@ -75,7 +93,6 @@ def setup_project(ide, target, program=None, source_dir=None, build=None, export
|
||||||
test.dependencies.append(MBED_HAL)
|
test.dependencies.append(MBED_HAL)
|
||||||
test.dependencies.append(MBED_TARGETS_PATH)
|
test.dependencies.append(MBED_TARGETS_PATH)
|
||||||
|
|
||||||
|
|
||||||
src_paths = [test.source_dir]
|
src_paths = [test.source_dir]
|
||||||
lib_paths = test.dependencies
|
lib_paths = test.dependencies
|
||||||
project_name = "_".join([test.id, ide, target])
|
project_name = "_".join([test.id, ide, target])
|
||||||
|
@ -104,15 +121,31 @@ def export(target, ide, build=None, src=None, macros=None, project_id=None,
|
||||||
|
|
||||||
Returns an object of type Exporter (tools/exports/exporters.py)
|
Returns an object of type Exporter (tools/exports/exporters.py)
|
||||||
"""
|
"""
|
||||||
project_dir, name, src, lib = setup_project(ide, target, program=project_id,
|
project_dir, name, src, lib = setup_project(
|
||||||
source_dir=src, build=build, export_path=export_path)
|
ide,
|
||||||
|
target,
|
||||||
|
program=project_id,
|
||||||
|
source_dir=src,
|
||||||
|
build=build,
|
||||||
|
export_path=export_path,
|
||||||
|
)
|
||||||
|
|
||||||
zip_name = name+".zip" if zip_proj else None
|
zip_name = name+".zip" if zip_proj else None
|
||||||
|
|
||||||
return export_project(src, project_dir, target, ide, name=name,
|
return export_project(
|
||||||
macros=macros, libraries_paths=lib, zip_proj=zip_name,
|
src,
|
||||||
build_profile=build_profile, notify=notify,
|
project_dir,
|
||||||
app_config=app_config, ignore=ignore)
|
target,
|
||||||
|
ide,
|
||||||
|
name=name,
|
||||||
|
macros=macros,
|
||||||
|
libraries_paths=lib,
|
||||||
|
zip_proj=zip_name,
|
||||||
|
build_profile=build_profile,
|
||||||
|
notify=notify,
|
||||||
|
app_config=app_config,
|
||||||
|
ignore=ignore
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
@ -125,100 +158,139 @@ def main():
|
||||||
toolchainlist = list(EXPORTERS.keys() + EXPORTER_ALIASES.keys())
|
toolchainlist = list(EXPORTERS.keys() + EXPORTER_ALIASES.keys())
|
||||||
toolchainlist.sort()
|
toolchainlist.sort()
|
||||||
|
|
||||||
parser.add_argument("-m", "--mcu",
|
parser.add_argument(
|
||||||
|
"-m", "--mcu",
|
||||||
metavar="MCU",
|
metavar="MCU",
|
||||||
help="generate project for the given MCU ({})".format(
|
help="generate project for the given MCU ({})".format(
|
||||||
', '.join(targetnames)))
|
', '.join(targetnames))
|
||||||
|
)
|
||||||
|
|
||||||
parser.add_argument("-i",
|
parser.add_argument(
|
||||||
|
"-i",
|
||||||
dest="ide",
|
dest="ide",
|
||||||
type=argparse_force_lowercase_type(
|
type=argparse_force_lowercase_type(
|
||||||
toolchainlist, "toolchain"),
|
toolchainlist, "toolchain"),
|
||||||
help="The target IDE: %s"% str(toolchainlist))
|
help="The target IDE: %s" % str(toolchainlist)
|
||||||
|
)
|
||||||
|
|
||||||
parser.add_argument("-c", "--clean",
|
parser.add_argument(
|
||||||
|
"-c", "--clean",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
default=False,
|
default=False,
|
||||||
help="clean the export directory")
|
help="clean the export directory"
|
||||||
|
)
|
||||||
|
|
||||||
group = parser.add_mutually_exclusive_group(required=False)
|
group = parser.add_mutually_exclusive_group(required=False)
|
||||||
group.add_argument(
|
group.add_argument(
|
||||||
"-p",
|
"-p",
|
||||||
type=test_known,
|
type=test_known,
|
||||||
dest="program",
|
dest="program",
|
||||||
help="The index of the desired test program: [0-%s]"% (len(TESTS)-1))
|
help="The index of the desired test program: [0-%s]" % (len(TESTS) - 1)
|
||||||
|
)
|
||||||
|
|
||||||
group.add_argument("-n",
|
group.add_argument(
|
||||||
|
"-n",
|
||||||
type=test_name_known,
|
type=test_name_known,
|
||||||
dest="program",
|
dest="program",
|
||||||
help="The name of the desired test program")
|
help="The name of the desired test program"
|
||||||
|
)
|
||||||
|
|
||||||
parser.add_argument("-b",
|
parser.add_argument(
|
||||||
|
"-b",
|
||||||
dest="build",
|
dest="build",
|
||||||
default=False,
|
default=False,
|
||||||
action="store_true",
|
action="store_true",
|
||||||
help="use the mbed library build, instead of the sources")
|
help="use the mbed library build, instead of the sources"
|
||||||
|
)
|
||||||
|
|
||||||
group.add_argument("-L", "--list-tests",
|
group.add_argument(
|
||||||
|
"-L", "--list-tests",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
dest="list_tests",
|
dest="list_tests",
|
||||||
default=False,
|
default=False,
|
||||||
help="list available programs in order and exit")
|
help="list available programs in order and exit"
|
||||||
|
)
|
||||||
|
|
||||||
group.add_argument("-S", "--list-matrix",
|
group.add_argument(
|
||||||
|
"-S", "--list-matrix",
|
||||||
dest="supported_ides",
|
dest="supported_ides",
|
||||||
default=False,
|
default=False,
|
||||||
const="matrix",
|
const="matrix",
|
||||||
choices=["matrix", "ides"],
|
choices=["matrix", "ides"],
|
||||||
nargs="?",
|
nargs="?",
|
||||||
help="displays supported matrix of MCUs and IDEs")
|
help="displays supported matrix of MCUs and IDEs"
|
||||||
|
)
|
||||||
|
|
||||||
parser.add_argument("-E",
|
parser.add_argument(
|
||||||
|
"-E",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
dest="supported_ides_html",
|
dest="supported_ides_html",
|
||||||
default=False,
|
default=False,
|
||||||
help="writes tools/export/README.md")
|
help="writes tools/export/README.md"
|
||||||
|
)
|
||||||
|
|
||||||
parser.add_argument("--build",
|
parser.add_argument(
|
||||||
|
"--build",
|
||||||
type=argparse_filestring_type,
|
type=argparse_filestring_type,
|
||||||
dest="build_dir",
|
dest="build_dir",
|
||||||
default=None,
|
default=None,
|
||||||
help="Directory for the exported project files")
|
help="Directory for the exported project files"
|
||||||
|
)
|
||||||
|
|
||||||
parser.add_argument("--source",
|
parser.add_argument(
|
||||||
|
"--source",
|
||||||
action="append",
|
action="append",
|
||||||
type=argparse_filestring_type,
|
type=argparse_filestring_type,
|
||||||
dest="source_dir",
|
dest="source_dir",
|
||||||
default=[],
|
default=[],
|
||||||
help="The source (input) directory")
|
help="The source (input) directory"
|
||||||
|
)
|
||||||
|
|
||||||
parser.add_argument("-D",
|
parser.add_argument(
|
||||||
|
"-D",
|
||||||
action="append",
|
action="append",
|
||||||
dest="macros",
|
dest="macros",
|
||||||
help="Add a macro definition")
|
help="Add a macro definition"
|
||||||
|
)
|
||||||
|
|
||||||
parser.add_argument("--profile", dest="profile", action="append",
|
parser.add_argument(
|
||||||
|
"--profile",
|
||||||
|
dest="profile",
|
||||||
|
action="append",
|
||||||
type=argparse_profile_filestring_type,
|
type=argparse_profile_filestring_type,
|
||||||
help="Build profile to use. Can be either path to json" \
|
help=("Build profile to use. Can be either path to json"
|
||||||
"file or one of the default one ({})".format(", ".join(list_profiles())),
|
"file or one of the default one ({})".format(
|
||||||
default=[])
|
", ".join(list_profiles()))),
|
||||||
|
default=[]
|
||||||
|
)
|
||||||
|
|
||||||
parser.add_argument("--update-packs",
|
parser.add_argument(
|
||||||
|
"--update-packs",
|
||||||
dest="update_packs",
|
dest="update_packs",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
default=False)
|
default=False
|
||||||
parser.add_argument("--app-config",
|
)
|
||||||
dest="app_config",
|
|
||||||
default=None)
|
|
||||||
|
|
||||||
parser.add_argument("--ignore", dest="ignore", type=argparse_many(str),
|
parser.add_argument(
|
||||||
default=None, help="Comma separated list of patterns to add to mbedignore (eg. ./main.cpp)")
|
"--app-config",
|
||||||
|
dest="app_config",
|
||||||
|
default=None
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"--ignore",
|
||||||
|
dest="ignore",
|
||||||
|
type=argparse_many(str),
|
||||||
|
default=None,
|
||||||
|
help=("Comma separated list of patterns to add to mbedignore "
|
||||||
|
"(eg. ./main.cpp)")
|
||||||
|
)
|
||||||
|
|
||||||
options = parser.parse_args()
|
options = parser.parse_args()
|
||||||
|
|
||||||
# Print available tests in order and exit
|
# Print available tests in order and exit
|
||||||
if options.list_tests is True:
|
if options.list_tests is True:
|
||||||
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()
|
sys.exit()
|
||||||
|
|
||||||
# Only prints matrix of supported IDEs
|
# Only prints matrix of supported IDEs
|
||||||
|
@ -232,17 +304,11 @@ def main():
|
||||||
# Only prints matrix of supported IDEs
|
# Only prints matrix of supported IDEs
|
||||||
if options.supported_ides_html:
|
if options.supported_ides_html:
|
||||||
html = mcu_ide_matrix(verbose_html=True)
|
html = mcu_ide_matrix(verbose_html=True)
|
||||||
try:
|
|
||||||
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)
|
||||||
except IOError as exc:
|
|
||||||
print("I/O error({0}): {1}".format(exc.errno, exc.strerror))
|
|
||||||
except:
|
|
||||||
print("Unexpected error:", sys.exc_info()[0])
|
|
||||||
raise
|
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
if options.update_packs:
|
if options.update_packs:
|
||||||
|
@ -267,14 +333,17 @@ def main():
|
||||||
|
|
||||||
notify = TerminalNotifier()
|
notify = TerminalNotifier()
|
||||||
|
|
||||||
if (options.program is None) and (not options.source_dir):
|
|
||||||
args_error(parser, "one of -p, -n, or --source is required")
|
|
||||||
ide = resolve_exporter_alias(options.ide)
|
ide = resolve_exporter_alias(options.ide)
|
||||||
exporter, toolchain_name = get_exporter_toolchain(ide)
|
exporter, toolchain_name = get_exporter_toolchain(ide)
|
||||||
|
profile = extract_profile(parser, options, toolchain_name, fallback="debug")
|
||||||
mcu = extract_mcus(parser, options)[0]
|
mcu = extract_mcus(parser, options)[0]
|
||||||
|
|
||||||
if not exporter.is_target_supported(mcu):
|
if not exporter.is_target_supported(mcu):
|
||||||
args_error(parser, "%s not supported by %s" % (mcu, ide))
|
args_error(parser, "%s not supported by %s" % (mcu, ide))
|
||||||
profile = extract_profile(parser, options, toolchain_name, fallback="debug")
|
|
||||||
|
if (options.program is None) and (not options.source_dir):
|
||||||
|
args_error(parser, "one of -p, -n, or --source is required")
|
||||||
|
|
||||||
if options.clean:
|
if options.clean:
|
||||||
for cls in EXPORTERS.values():
|
for cls in EXPORTERS.values():
|
||||||
try:
|
try:
|
||||||
|
@ -287,14 +356,22 @@ def main():
|
||||||
except (IOError, OSError):
|
except (IOError, OSError):
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
export(mcu, ide, build=options.build,
|
export(
|
||||||
src=options.source_dir, macros=options.macros,
|
mcu,
|
||||||
project_id=options.program, zip_proj=zip_proj,
|
ide,
|
||||||
build_profile=profile, app_config=options.app_config,
|
build=options.build,
|
||||||
export_path=options.build_dir, notify=notify,
|
src=options.source_dir,
|
||||||
ignore=options.ignore)
|
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:
|
except NotSupportedException as exc:
|
||||||
print("[ERROR] %s" % str(exc))
|
print("[Not Supported] %s" % str(exc))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in New Issue