Exemplo n.º 1
0
def mcu_is_enabled(parser, mcu):
    if "Cortex-A" in TARGET_MAP[mcu].core:
        args_error(
            parser,
            ("%s Will be supported in mbed OS 5.6. "
             "To use the %s, please checkout the mbed OS 5.4 release branch. "
             "See https://developer.mbed.org/platforms/Renesas-GR-PEACH/#important-notice "
             "for more information") % (mcu, mcu))
    return True
Exemplo n.º 2
0
def extract_mcus(parser, options):
    try:
        if options.source_dir:
            for source_dir in options.source_dir:
                Target.add_extra_targets(source_dir)
            update_target_data()
    except KeyError:
        pass
    targetnames = TARGET_NAMES
    targetnames.sort()
    try:
        return argparse_many(argparse_force_uppercase_type(targetnames, "MCU"))(options.mcu)
    except ArgumentTypeError as exc:
        args_error(parser, "argument -m/--mcu: {}".format(str(exc)))
Exemplo n.º 3
0
def extract_profile(parser, options, toolchain, fallback="develop"):
    """Extract a Toolchain profile from parsed options

    Positional arguments:
    parser - parser used to parse the command line arguments
    options - The parsed command line arguments
    toolchain - the toolchain that the profile should be extracted for
    """
    profiles = []
    filenames = options.profile or [join(dirname(__file__), "profiles",
                                         fallback + ".json")]
    for filename in filenames:
        contents = load(open(filename))
        if toolchain not in contents:
            args_error(parser, ("argument --profile: toolchain {} is not"
                                " supported by profile {}").format(toolchain,
                                                                   filename))
        profiles.append(contents)

    return profiles
Exemplo n.º 4
0
def extract_profile(parser, options, toolchain):
    """Extract a Toolchain profile from parsed options

    Positional arguments:
    parser - parser used to parse the command line arguments
    options - The parsed command line arguments
    toolchain - the toolchain that the profile should be extracted for
    """
    profile = {'c': [], 'cxx': [], 'ld': [], 'common': [], 'asm': []}
    filenames = options.profile or [join(dirname(__file__), "profiles",
                                         "default.json")]
    for filename in filenames:
        contents = load(open(filename))
        try:
            for key in profile.iterkeys():
                profile[key] += contents[toolchain][key]
        except KeyError:
            args_error(parser, ("argument --profile: toolchain {} is not"
                                " supported by profile {}").format(toolchain,
                                                                   filename))
    return profile
Exemplo n.º 5
0
def extract_profile(parser, options, toolchain, fallback="default"):
    """Extract a Toolchain profile from parsed options

    Positional arguments:
    parser - parser used to parse the command line arguments
    options - The parsed command line arguments
    toolchain - the toolchain that the profile should be extracted for
    """
    profile = {'c': [], 'cxx': [], 'ld': [], 'common': [], 'asm': []}
    filenames = options.profile or [
        join(dirname(__file__), "profiles", fallback + ".json")
    ]
    for filename in filenames:
        contents = load(open(filename))
        try:
            for key in profile.iterkeys():
                profile[key] += contents[toolchain][key]
        except KeyError:
            args_error(parser, ("argument --profile: toolchain {} is not"
                                " supported by profile {}").format(
                                    toolchain, filename))
    return profile
Exemplo n.º 6
0
def main():
    """Entry point"""
    # Parse Options
    parser = ArgumentParser()

    targetnames = TARGET_NAMES
    targetnames.sort()
    toolchainlist = EXPORTERS.keys()
    toolchainlist.sort()

    parser.add_argument("-m",
                        "--mcu",
                        metavar="MCU",
                        default='LPC1768',
                        type=argparse_force_uppercase_type(targetnames, "MCU"),
                        help="generate project for the given MCU ({})".format(
                            ', '.join(targetnames)))

    parser.add_argument("-i",
                        dest="ide",
                        default='uvision',
                        type=argparse_force_lowercase_type(
                            toolchainlist, "toolchain"),
                        help="The target IDE: %s" % str(toolchainlist))

    parser.add_argument("-c",
                        "--clean",
                        action="store_true",
                        default=False,
                        help="clean the export directory")

    group = parser.add_mutually_exclusive_group(required=False)
    group.add_argument("-p",
                       type=test_known,
                       dest="program",
                       help="The index of the desired test program: [0-%s]" %
                       (len(TESTS) - 1))

    group.add_argument("-n",
                       type=test_name_known,
                       dest="program",
                       help="The name of the desired test program")

    parser.add_argument(
        "-b",
        dest="build",
        default=False,
        action="store_true",
        help="use the mbed library build, instead of the sources")

    group.add_argument("-L",
                       "--list-tests",
                       action="store_true",
                       dest="list_tests",
                       default=False,
                       help="list available programs in order and exit")

    group.add_argument("-S",
                       "--list-matrix",
                       action="store_true",
                       dest="supported_ides",
                       default=False,
                       help="displays supported matrix of MCUs and IDEs")

    parser.add_argument("-E",
                        action="store_true",
                        dest="supported_ides_html",
                        default=False,
                        help="writes tools/export/README.md")

    parser.add_argument("--source",
                        action="append",
                        type=argparse_filestring_type,
                        dest="source_dir",
                        default=[],
                        help="The source (input) directory")

    parser.add_argument("-D",
                        action="append",
                        dest="macros",
                        help="Add a macro definition")

    parser.add_argument("-o",
                        type=argparse_many(str),
                        dest="opts",
                        default=["debug-info"],
                        help="Toolchain options")

    options = parser.parse_args()

    # Print available tests in order and exit
    if options.list_tests is True:
        print '\n'.join([str(test) for test in sorted(TEST_MAP.values())])
        sys.exit()

    # Only prints matrix of supported IDEs
    if options.supported_ides:
        print mcu_ide_matrix()
        exit(0)

    # Only prints matrix of supported IDEs
    if options.supported_ides_html:
        html = mcu_ide_matrix(verbose_html=True)
        try:
            with open("./export/README.md", "w") as readme:
                readme.write("Exporter IDE/Platform Support\n")
                readme.write("-----------------------------------\n")
                readme.write("\n")
                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)

    # Clean Export Directory
    if options.clean:
        if exists(EXPORT_DIR):
            rmtree(EXPORT_DIR)

    for mcu in options.mcu:
        zip_proj = not bool(options.source_dir)

    # Target
    if not options.mcu:
        args_error(parser, "argument -m/--mcu is required")

    # Toolchain
    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")
        # Export to selected toolchain
    """modified by lex 20161103, add ", export_path=EXPORT_UVISION_DIR" to move uvision project file into IoT-OS/projects"""
    export(options.mcu,
           options.ide,
           build=options.build,
           src=options.source_dir,
           macros=options.macros,
           project_id=options.program,
           clean=options.clean,
           zip_proj=zip_proj,
           options=options.opts,
           export_path=EXPORT_UVISION_DIR)
Exemplo n.º 7
0
if __name__ == '__main__':
    # Parse Options
    parser = get_default_options_parser(add_clean=False, add_options=False)
    parser.add_argument("--source", dest="source_dir", type=argparse_filestring_type, required=True,
                        default=[], help="The source (input) directory", action="append")
    parser.add_argument("--prefix", dest="prefix", action="append",
                      default=[], help="Restrict listing to parameters that have this prefix")
    parser.add_argument("-v", "--verbose", action="store_true", dest="verbose",
                      default=False, help="Verbose diagnostic output")

    options = parser.parse_args()

    # Target
    if options.mcu is None :
        args_error(parser, "argument -m/--mcu is required")
    target = options.mcu[0]

    # Toolchain
    if options.tool is None:
        args_error(parser, "argument -t/--toolchain is required")
    toolchain = options.tool[0]

    options.prefix = options.prefix or [""]

    try:
        params, macros, features = get_config(options.source_dir, target, toolchain)
        if not params and not macros:
            print "No configuration data available."
            _exit(0)
        if params:
Exemplo n.º 8
0
Arquivo: build.py Projeto: sg-/mbed-os
    options = parser.parse_args()

    # Only prints matrix of supported toolchains
    if options.supported_toolchains:
        print(mcu_toolchain_matrix(platform_filter=options.general_filter_regex))
        exit(0)


    # Get target list
    targets = extract_mcus(parser, options) if options.mcu else TARGET_NAMES

    # Get toolchains list
    toolchains = options.tool if options.tool else TOOLCHAINS

    if options.source_dir and not options.build_dir:
        args_error(parser, "argument --build is required by argument --source")


    # Get libraries list
    libraries = []

    # Additional Libraries
    if options.rpc:
        libraries.extend(["rpc"])
    if options.usb:
        libraries.append("usb")
    if options.dsp:
        libraries.extend(["dsp"])
    if options.cpputest_lib:
        libraries.extend(["cpputest"])
Exemplo n.º 9
0
        dest="prefix",
        action="append",
        default=[],
        help="Restrict listing to parameters that have this prefix")
    parser.add_argument("-v",
                        "--verbose",
                        action="store_true",
                        dest="verbose",
                        default=False,
                        help="Verbose diagnostic output")

    options = parser.parse_args()

    # Target
    if options.mcu is None:
        args_error(parser, "argument -m/--mcu is required")
    target = options.mcu[0]

    # Toolchain
    if options.tool is None:
        args_error(parser, "argument -t/--toolchain is required")
    toolchain = options.tool[0]

    options.prefix = options.prefix or [""]

    try:
        params, macros, features = get_config(options.source_dir, target,
                                              toolchain)
        if not params and not macros:
            print "No configuration data available."
            _exit(0)
Exemplo n.º 10
0
                            help="Verbose diagnostic output")

        options = parser.parse_args()

        # Filter tests by path if specified
        if options.paths:
            all_paths = options.paths
        else:
            all_paths = ["."]

        all_tests = {}
        tests = {}

        # Target
        if options.mcu is None:
            args_error(parser, "argument -m/--mcu is required")
        mcu = options.mcu[0]

        # Toolchain
        if options.tool is None:
            args_error(parser, "argument -t/--tool is required")
        toolchain = options.tool[0]

        # Find all tests in the relevant paths
        for path in all_paths:
            all_tests.update(
                find_tests(path,
                           mcu,
                           toolchain,
                           options.options,
                           app_config=options.app_config))
Exemplo n.º 11
0
        sys.exit()

    # force program to "0" if a source dir is specified
    if options.source_dir is not None:
        p = 0
    else:
    # Program Number or name
        p = options.program

    # If 'p' was set via -n to list of numbers make this a single element integer list
    if type(p) != type([]):
        p = [p]

    # Target
    if options.mcu is None :
        args_error(parser, "argument -m/--mcu is required")
    mcu = options.mcu[0]

    # Toolchain
    if options.tool is None:
        args_error(parser, "argument -t/--tool is required")
    toolchain = options.tool[0]

    if (options.program is None) and (not options.source_dir):
        args_error(parser, "one of -p, -n, or --source is required")

    if options.source_dir and not options.build_dir:
        args_error(parser, "argument --build is required when argument --source is provided")


    if options.color:
Exemplo n.º 12
0
                          help="Verbose diagnostic output")

        options = parser.parse_args()

        # Filter tests by path if specified
        if options.paths:
            all_paths = options.paths
        else:
            all_paths = ["."]

        all_tests = {}
        tests = {}

        # Target
        if options.mcu is None :
            args_error(parser, "[ERROR] You should specify an MCU")
        mcu = options.mcu[0]

        # Toolchain
        if options.tool is None:
            args_error(parser, "[ERROR] You should specify a TOOLCHAIN")
        toolchain = options.tool[0]

        # Find all tests in the relevant paths
        for path in all_paths:
            all_tests.update(find_tests(path, mcu, toolchain, options.options))

        # Filter tests by name if specified
        if options.names:
            all_names = options.names
            all_names = [x.lower() for x in all_names]
def main():
    """Entry point"""

    ide_list = ["iar", "uvision"]

    default_v2 = [test_name_known("MBED_BLINKY")]
    default_v5 = [check_valid_mbed_os('tests-mbedmicro-rtos-mbed-basic')]

    parser = argparse.ArgumentParser(description=
                                     "Test progen builders. Leave any flag off"
                                     " to run with all possible options.")
    parser.add_argument("-i",
                        dest="ides",
                        default=ide_list,
                        type=argparse_many(argparse_force_lowercase_type(
                            ide_list, "toolchain")),
                        help="The target IDE: %s"% str(ide_list))

    parser.add_argument( "-p",
                        type=argparse_many(test_known),
                        dest="programs",
                        help="The index of the desired test program: [0-%d]"
                             % (len(TESTS) - 1))

    parser.add_argument("-n",
                        type=argparse_many(test_name_known),
                        dest="programs",
                        help="The name of the desired test program")

    parser.add_argument("-m", "--mcu",
                        help=("Generate projects for the given MCUs"),
                        metavar="MCU",
                        type=argparse_many(str.upper))

    parser.add_argument("-os-tests",
                        type=argparse_many(check_valid_mbed_os),
                        dest="os_tests",
                        help="Mbed-os tests")

    parser.add_argument("-c", "--clean",
                        dest="clean",
                        action="store_true",
                        help="clean up the exported project files",
                        default=False)

    parser.add_argument("--release",
                        dest="release",
                        type=check_version,
                        help="Which version of mbed to test",
                        default=RELEASE_VERSIONS[-1])

    parser.add_argument("--profile",
                        dest="profile",
                        action="append",
                        type=argparse_filestring_type,
                        default=[])

    options = parser.parse_args()
    # targets in chosen release
    targetnames = [target[0] for target in
                   get_mbed_official_release(options.release)]
    # all targets in release are default
    test_targets = options.mcu or targetnames
    if not all([t in targetnames for t in test_targets]):
        args_error(parser, "Only specify targets in release %s:\n%s"
                   %(options.release, columnate(sorted(targetnames))))

    v2_tests, v5_tests = [],[]
    if options.release == '5':
        v5_tests = options.os_tests or default_v5
    elif options.release == '2':
        v2_tests = options.programs or default_v2

    tests = []
    default_test = {key:None for key in ['ide', 'mcu', 'name', 'id', 'src', 'log']}
    for mcu in test_targets:
        for ide in options.ides:
            log = "build_log.txt" if ide == 'iar' \
                else join('build', 'build_log.txt')
            # add each test case to the tests array
            default_test.update({'mcu': mcu, 'ide': ide, 'log':log})
            for test in v2_tests:
                default_test.update({'name':TESTS[test]["id"], 'id':test})
                tests.append(copy(default_test))
            for test in v5_tests:
                default_test.update({'name':test[0],'src':[test[1],ROOT]})
                tests.append(copy(default_test))
    test = ExportBuildTest(tests, parser, options)
    test.batch_tests(clean=options.clean)
    print_results(test.successes, test.failures, test.skips)
    sys.exit(len(test.failures))
Exemplo n.º 14
0
                f.write(html)
        except IOError as e:
            print "I/O error({0}): {1}".format(e.errno, e.strerror)
        except:
            print "Unexpected error:", sys.exc_info()[0]
            raise
        exit(0)

    # Clean Export Directory
    if options.clean:
        if exists(EXPORT_DIR):
            rmtree(EXPORT_DIR)

    # Target
    if options.mcu is None :
        args_error(parser, "[ERROR] You should specify an MCU")
    mcus = options.mcu

    # IDE
    if options.ide is None:
        args_error(parser, "[ERROR] You should specify an IDE")
    ide = options.ide

    # Export results
    successes = []
    failures = []
    zip = True
    clean = True

    # source_dir = use relative paths, otherwise sources are copied
    sources_relative = True if options.source_dir else False
Exemplo n.º 15
0
    parser.add_argument("-c",
                        "--clean",
                        dest="clean",
                        action="store_true",
                        help="clean up the exported project files",
                        default=False)

    options = parser.parse_args()

    tests = options.tests
    ides = [ide.lower() for ide in options.ides]
    targets = [target.upper() for target in options.targets]

    if any(get_test_from_name(test) is None for test in tests):
        args_error(parser, "[ERROR] test name not recognized")

    if any(target not in accepted_targets for target in targets):
        args_error(
            parser, "[ERROR] mcu must be one of the following:\n %s" %
            '\n '.join(accepted_targets))

    if any(ide not in accepted_ides for ide in ides):
        args_error(parser,
                   "[ERROR] ide must be in %s" % ', '.join(accepted_ides))

    build_test = ProgenBuildTest(ides, targets)
    successes, failures, skips = build_test.generate_and_build(
        tests, options.clean)
    print_results(successes, failures, skips)
    sys.exit(len(failures))
Exemplo n.º 16
0
def main():
    # Parse Options
    parser = get_default_options_parser(add_app_config=True)

    group = parser.add_mutually_exclusive_group(required=False)
    group.add_argument("-p",
                       type=argparse_many(test_known),
                       dest="program",
                       help="The index of the desired test program: [0-%d]" %
                       (len(TESTS) - 1))
    group.add_argument("-n",
                       type=argparse_many(test_name_known),
                       dest="program",
                       help="The name of the desired test program")
    group.add_argument("-L",
                       "--list-tests",
                       action="store_true",
                       dest="list_tests",
                       default=False,
                       help="List available tests in order and exit")
    group.add_argument("-S",
                       "--supported-toolchains",
                       dest="supported_toolchains",
                       default=False,
                       const="matrix",
                       choices=["matrix", "toolchains", "targets"],
                       nargs="?",
                       help="Displays supported matrix of MCUs and toolchains")

    parser.add_argument("-j",
                        "--jobs",
                        type=int,
                        dest="jobs",
                        default=0,
                        help="Number of concurrent jobs. Default: 0/auto "
                        "(based on host machine's number of CPUs)")
    parser.add_argument("-v",
                        "--verbose",
                        action="store_true",
                        dest="verbose",
                        default=False,
                        help="Verbose diagnostic output")
    parser.add_argument(
        "--silent",
        action="store_true",
        dest="silent",
        default=False,
        help="Silent diagnostic output (no copy, compile notification)")
    parser.add_argument("-D",
                        action="append",
                        dest="macros",
                        help="Add a macro definition")
    parser.add_argument(
        '-f',
        '--filter',
        dest='general_filter_regex',
        default=None,
        help='For some commands you can use filter to filter out results')
    parser.add_argument("--stats-depth",
                        type=int,
                        dest="stats_depth",
                        default=2,
                        help="Depth level for static memory report")
    parser.add_argument("--automated",
                        action="store_true",
                        dest="automated",
                        default=False,
                        help="Automated test")
    parser.add_argument("--host",
                        dest="host_test",
                        default=None,
                        help="Host test")
    parser.add_argument("--extra",
                        dest="extra",
                        default=None,
                        help="Extra files")
    parser.add_argument("--peripherals",
                        dest="peripherals",
                        default=None,
                        help="Required peripherals")
    parser.add_argument("--dep",
                        dest="dependencies",
                        default=None,
                        help="Dependencies")
    parser.add_argument("--source",
                        dest="source_dir",
                        type=argparse_filestring_type,
                        default=None,
                        action="append",
                        help="The source (input) directory")
    parser.add_argument("--duration",
                        type=int,
                        dest="duration",
                        default=None,
                        help="Duration of the test")
    parser.add_argument("--build",
                        dest="build_dir",
                        type=argparse_dir_not_parent(ROOT),
                        default=None,
                        help="The build (output) directory")
    parser.add_argument("-N",
                        "--artifact-name",
                        dest="artifact_name",
                        default=None,
                        help="The built project's name")
    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)")
    parser.add_argument("-b",
                        "--baud",
                        type=int,
                        dest="baud",
                        default=None,
                        help="The mbed serial baud rate")
    parser.add_argument("--rpc",
                        action="store_true",
                        dest="rpc",
                        default=False,
                        help="Link with RPC library")
    parser.add_argument("--usb",
                        action="store_true",
                        dest="usb",
                        default=False,
                        help="Link with USB Device library")
    parser.add_argument("--dsp",
                        action="store_true",
                        dest="dsp",
                        default=False,
                        help="Link with DSP library")
    parser.add_argument("--testlib",
                        action="store_true",
                        dest="testlib",
                        default=False,
                        help="Link with mbed test library")
    parser.add_argument("--build-data",
                        dest="build_data",
                        default=None,
                        help="Dump build_data to this file")
    parser.add_argument("-l",
                        "--linker",
                        dest="linker_script",
                        type=argparse_filestring_type,
                        default=None,
                        help="use the specified linker script")
    options = parser.parse_args()

    end_warnings = []

    if options.supported_toolchains:
        if options.supported_toolchains == "matrix":
            print_large_string(
                mcu_toolchain_matrix(
                    platform_filter=options.general_filter_regex,
                    release_version=None))
        elif options.supported_toolchains == "toolchains":
            print('\n'.join(get_toolchain_list()))
        elif options.supported_toolchains == "targets":
            print_large_string(mcu_target_list())
    elif options.list_tests is True:
        print('\n'.join(map(str, sorted(TEST_MAP.values()))))
    else:
        # Target
        if options.mcu is None:
            args_error(parser, "argument -m/--mcu is required")
        mcu = extract_mcus(parser, options)[0]

        # Toolchain
        if options.tool is None:
            args_error(parser, "argument -t/--tool is required")
        toolchain = options.tool[0]

        target = Target.get_target(mcu)

        if (options.program is None) and (not options.source_dir):
            args_error(parser, "one of -p, -n, or --source is required")

        if options.source_dir and not options.build_dir:
            args_error(
                parser,
                "argument --build is required when argument --source is provided"
            )

        notify = TerminalNotifier(options.verbose, options.silent,
                                  options.color)

        try:
            toolchain_name, internal_tc_name, end_warnings = find_valid_toolchain(
                target, toolchain)
        except NoValidToolchainException as e:
            print_end_warnings(e.end_warnings)
            args_error(parser, str(e))

        if options.source_dir is not None:
            resource_filter = None
            wrapped_build_project(options.source_dir,
                                  options.build_dir,
                                  mcu,
                                  end_warnings,
                                  options,
                                  toolchain_name,
                                  notify=notify,
                                  build_profile=extract_profile(
                                      parser, options, internal_tc_name),
                                  resource_filter=resource_filter,
                                  **default_args_dict(options))
        else:
            p = options.program

            # If 'p' was set via -n to list of numbers make this a single element
            # integer list
            if not isinstance(p, list):
                p = [p]

            build_data_blob = {} if options.build_data else None
            for test_no in p:
                test = Test(test_no)
                if options.automated is not None:
                    test.automated = options.automated
                if options.dependencies is not None:
                    test.dependencies = options.dependencies
                if options.host_test is not None:
                    test.host_test = options.host_test
                if options.peripherals is not None:
                    test.peripherals = options.peripherals
                if options.duration is not None:
                    test.duration = options.duration
                if options.extra is not None:
                    test.extra_files = options.extra

                if not test.is_supported(mcu, toolchain):
                    print('The selected test is not supported on target '
                          '%s with toolchain %s' % (mcu, toolchain))
                    sys.exit()

                # Linking with extra libraries
                if options.rpc:
                    test.dependencies.append(RPC_LIBRARY)
                if options.usb:
                    test.dependencies.append(USB_LIBRARIES)
                if options.dsp:
                    test.dependencies.append(DSP_LIBRARIES)
                if options.testlib:
                    test.dependencies.append(TEST_MBED_LIB)

                build_dir = join(BUILD_DIR, "test", mcu, toolchain, test.id)
                if options.build_dir is not None:
                    build_dir = options.build_dir

                wrapped_build_project(test.source_dir,
                                      build_dir,
                                      mcu,
                                      end_warnings,
                                      options,
                                      toolchain_name,
                                      set(test.dependencies),
                                      notify=notify,
                                      report=build_data_blob,
                                      inc_dirs=[dirname(MBED_LIBRARIES)],
                                      build_profile=extract_profile(
                                          parser, options, internal_tc_name),
                                      **default_args_dict(options))
            if options.build_data:
                merge_build_data(options.build_data, build_data_blob,
                                 "application")
Exemplo n.º 17
0
def main():
    """Entry point"""
    # Parse Options
    parser = ArgumentParser()

    targetnames = TARGET_NAMES
    targetnames.sort()
    toolchainlist = list(EXPORTERS.keys())
    toolchainlist.sort()

    parser.add_argument("-m", "--mcu",
                        metavar="MCU",
                        help="generate project for the given MCU ({})".format(
                            ', '.join(targetnames)))

    parser.add_argument("-i",
                        dest="ide",
                        type=argparse_force_lowercase_type(
                            toolchainlist, "toolchain"),
                        help="The target IDE: %s"% str(toolchainlist))

    parser.add_argument("-c", "--clean",
                        action="store_true",
                        default=False,
                        help="clean the export directory")

    group = parser.add_mutually_exclusive_group(required=False)
    group.add_argument(
        "-p",
        type=test_known,
        dest="program",
        help="The index of the desired test program: [0-%s]"% (len(TESTS)-1))

    group.add_argument("-n",
                       type=test_name_known,
                       dest="program",
                       help="The name of the desired test program")

    parser.add_argument("-b",
                      dest="build",
                      default=False,
                      action="store_true",
                      help="use the mbed library build, instead of the sources")

    group.add_argument("-L", "--list-tests",
                       action="store_true",
                       dest="list_tests",
                       default=False,
                       help="list available programs in order and exit")

    group.add_argument("-S", "--list-matrix",
                       dest="supported_ides",
                       default=False,
                       const="matrix",
                       choices=["matrix", "ides"],
                       nargs="?",
                       help="displays supported matrix of MCUs and IDEs")

    parser.add_argument("-E",
                        action="store_true",
                        dest="supported_ides_html",
                        default=False,
                        help="writes tools/export/README.md")

    parser.add_argument("--build",
                        type=argparse_filestring_type,
                        dest="build_dir",
                        default=None,
                        help="Directory for the exported project files")

    parser.add_argument("--source",
                        action="append",
                        type=argparse_filestring_type,
                        dest="source_dir",
                        default=[],
                        help="The source (input) directory")

    parser.add_argument("-D",
                        action="append",
                        dest="macros",
                        help="Add a macro definition")

    parser.add_argument("--profile", dest="profile", action="append",
                        type=argparse_profile_filestring_type,
                        help="Build profile to use. Can be either path to json" \
                        "file or one of the default one ({})".format(", ".join(list_profiles())),
                        default=[])

    parser.add_argument("--update-packs",
                        dest="update_packs",
                        action="store_true",
                        default=False)
    parser.add_argument("--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()

    # Print available tests in order and exit
    if options.list_tests is True:
        print('\n'.join([str(test) for test in  sorted(TEST_MAP.values())]))
        sys.exit()

    # Only prints matrix of supported IDEs
    if options.supported_ides:
        if options.supported_ides == "matrix":
            print_large_string(mcu_ide_matrix())
        elif options.supported_ides == "ides":
            print(mcu_ide_list())
        exit(0)

    # Only prints matrix of supported IDEs
    if options.supported_ides_html:
        html = mcu_ide_matrix(verbose_html=True)
        try:
            with open("./export/README.md", "w") as readme:
                readme.write("Exporter IDE/Platform Support\n")
                readme.write("-----------------------------------\n")
                readme.write("\n")
                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)

    if options.update_packs:
        from tools.arm_pack_manager import Cache
        cache = Cache(True, True)
        cache.cache_everything()

    # Target
    if not options.mcu:
        args_error(parser, "argument -m/--mcu is required")

    # Toolchain
    if not options.ide:
        args_error(parser, "argument -i is required")

    # Clean Export Directory
    if options.clean:
        if exists(EXPORT_DIR):
            rmtree(EXPORT_DIR)

    zip_proj = not bool(options.source_dir)

    notify = TerminalNotifier()

    if (options.program is None) and (not options.source_dir):
        args_error(parser, "one of -p, -n, or --source is required")
    exporter, toolchain_name = get_exporter_toolchain(options.ide)
    mcu = extract_mcus(parser, options)[0]
    if not exporter.is_target_supported(mcu):
        args_error(parser, "%s not supported by %s"%(mcu,options.ide))
    profile = extract_profile(parser, options, toolchain_name, fallback="debug")
    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, options.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("[ERROR] %s" % str(exc))
Exemplo n.º 18
0
if __name__ == '__main__':
    # Parse Options
    parser = get_default_options_parser(add_clean=False, add_options=False)
    parser.add_option("--source", dest="source_dir",
                      default=None, help="The source (input) directory", action="append")
    parser.add_option("--prefix", dest="prefix", action="append",
                      default=None, help="Restrict listing to parameters that have this prefix")
    parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
                      default=False, help="Verbose diagnostic output")

    (options, args) = parser.parse_args()

    for path in options.source_dir :
        if not isdir(path) :
            args_error(parser, "[ERROR] you passed \"{}\" to --source, which does not exist".
                       format(path))
    # Target
    if options.mcu is None :
        args_error(parser, "[ERROR] You should specify an MCU")
    target = options.mcu

    # Toolchain
    if options.tool is None:
        args_error(parser, "[ERROR] You should specify a TOOLCHAIN")
    toolchain = options.tool

    options.prefix = options.prefix or [""]

    try:
        params, macros = get_config(options.source_dir, target, toolchain)
        if not params and not macros:
Exemplo n.º 19
0
def main():
    """Entry point"""
    # Parse Options
    parser = ArgumentParser()

    targetnames = TARGET_NAMES
    targetnames.sort()
    toolchainlist = EXPORTERS.keys()
    toolchainlist.sort()

    parser.add_argument("-m", "--mcu",
                        metavar="MCU",
                        default='LPC1768',
                        type=argparse_force_uppercase_type(targetnames, "MCU"),
                        help="generate project for the given MCU ({})".format(
                            ', '.join(targetnames)))

    parser.add_argument("-i",
                        dest="ide",
                        default='uvision',
                        type=argparse_force_lowercase_type(
                            toolchainlist, "toolchain"),
                        help="The target IDE: %s"% str(toolchainlist))

    parser.add_argument("-c", "--clean",
                        action="store_true",
                        default=False,
                        help="clean the export directory")

    group = parser.add_mutually_exclusive_group(required=False)
    group.add_argument(
        "-p",
        type=test_known,
        dest="program",
        help="The index of the desired test program: [0-%s]"% (len(TESTS)-1))

    group.add_argument("-n",
                       type=test_name_known,
                       dest="program",
                       help="The name of the desired test program")

    parser.add_argument("-b",
                      dest="build",
                      default=False,
                      action="store_true",
                      help="use the mbed library build, instead of the sources")

    group.add_argument("-L", "--list-tests",
                       action="store_true",
                       dest="list_tests",
                       default=False,
                       help="list available programs in order and exit")

    group.add_argument("-S", "--list-matrix",
                       action="store_true",
                       dest="supported_ides",
                       default=False,
                       help="displays supported matrix of MCUs and IDEs")

    parser.add_argument("-E",
                        action="store_true",
                        dest="supported_ides_html",
                        default=False,
                        help="writes tools/export/README.md")

    parser.add_argument("--source",
                        action="append",
                        type=argparse_filestring_type,
                        dest="source_dir",
                        default=[],
                        help="The source (input) directory")

    parser.add_argument("-D",
                        action="append",
                        dest="macros",
                        help="Add a macro definition")

    parser.add_argument("--profile",
                        type=argparse_filestring_type,
                        default=[],
                        help="Toolchain profile")

    parser.add_argument("--update-packs",
                        dest="update_packs",
                        action="store_true",
                        default=False)

    options = parser.parse_args()

    # Print available tests in order and exit
    if options.list_tests is True:
        print '\n'.join([str(test) for test in  sorted(TEST_MAP.values())])
        sys.exit()

    # Only prints matrix of supported IDEs
    if options.supported_ides:
        print_large_string(mcu_ide_matrix())
        exit(0)

    # Only prints matrix of supported IDEs
    if options.supported_ides_html:
        html = mcu_ide_matrix(verbose_html=True)
        try:
            with open("./export/README.md", "w") as readme:
                readme.write("Exporter IDE/Platform Support\n")
                readme.write("-----------------------------------\n")
                readme.write("\n")
                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)

    if options.update_packs:
        from tools.arm_pack_manager import Cache
        cache = Cache(True, True)
        cache.cache_descriptors()

    # Clean Export Directory
    if options.clean:
        if exists(EXPORT_DIR):
            rmtree(EXPORT_DIR)

    for mcu in options.mcu:
        zip_proj = not bool(options.source_dir)

    # Target
    if not options.mcu:
        args_error(parser, "argument -m/--mcu is required")

    # Toolchain
    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")
        # Export to selected toolchain
    exporter, toolchain_name = get_exporter_toolchain(options.ide)
    if options.mcu not in exporter.TARGETS:
        args_error(parser, "%s not supported by %s"%(options.mcu,options.ide))
    profile = extract_profile(parser, options, toolchain_name)
    export(options.mcu, options.ide, build=options.build,
           src=options.source_dir, macros=options.macros,
           project_id=options.program, clean=options.clean,
           zip_proj=zip_proj, build_profile=profile)
Exemplo n.º 20
0
        action="append",
        default=None,
        help="Restrict listing to parameters that have this prefix")
    parser.add_option("-v",
                      "--verbose",
                      action="store_true",
                      dest="verbose",
                      default=False,
                      help="Verbose diagnostic output")

    (options, args) = parser.parse_args()

    for path in options.source_dir:
        if not isdir(path):
            args_error(
                parser,
                "[ERROR] you passed \"{}\" to --source, which does not exist".
                format(path))
    # Target
    if options.mcu is None:
        args_error(parser, "[ERROR] You should specify an MCU")
    target = options.mcu

    # Toolchain
    if options.tool is None:
        args_error(parser, "[ERROR] You should specify a TOOLCHAIN")
    toolchain = options.tool

    options.prefix = options.prefix or [""]

    try:
        params, macros = get_config(options.source_dir, target, toolchain)
Exemplo n.º 21
0
        dest="prefix",
        action="append",
        default=[],
        help="Restrict listing to parameters that have this prefix")
    parser.add_argument("-v",
                        "--verbose",
                        action="store_true",
                        dest="verbose",
                        default=False,
                        help="Verbose diagnostic output")

    options = parser.parse_args()

    # Target
    if options.mcu is None:
        args_error(parser, "argument -m/--mcu is required")
    target = extract_mcus(parser, options)[0]

    options.prefix = options.prefix or [""]

    try:
        params, macros, features, _ = get_config(
            options.source_dir,
            target,
            options.tool[0] if options.tool else None,
            app_config=options.app_config)
        if not params and not macros:
            print("No configuration data available.")
            sys.exit(0)
        if params:
            print("Configuration parameters")
Exemplo n.º 22
0
    # Specify a different linker script
    parser.add_option("-l", "--linker", dest="linker_script",
                      default=None, help="use the specified linker script")

    (options, args) = parser.parse_args()

    # Only prints matrix of supported toolchains
    if options.supported_toolchains:
        print mcu_toolchain_matrix(platform_filter=options.general_filter_regex)
        exit(0)

    if options.source_dir:
        for path in options.source_dir :
            if not isfile(path) and not isdir(path) :
                args_error(parser, "[ERROR] you passed \"{}\" to --source, which does not exist".
                           format(path))

    # Print available tests in order and exit
    if options.list_tests is True:
        print '\n'.join(map(str, sorted(TEST_MAP.values())))
        sys.exit()

    # force program to "0" if a source dir is specified
    if options.source_dir is not None:
        p = 0
        n = None
    else:
    # Program Number or name
        p, n = options.program, options.program_name

    if n is not None and p is not None:
Exemplo n.º 23
0
        if options.paths:
            all_paths = options.paths
        else:
            all_paths = ["."]

        all_tests = {}
        tests = {}

        # As default both test tools are enabled
        if not (options.greentea or options.icetea):
            options.greentea = True
            options.icetea = True

        # Target
        if options.mcu is None:
            args_error(parser, "argument -m/--mcu is required")
        mcu = extract_mcus(parser, options)[0]
        mcu_secured = Target.get_target(mcu).is_PSA_secure_target

        # Toolchain
        if options.tool is None:
            args_error(parser, "argument -t/--tool is required")
        toolchain = options.tool[0]

        if not TOOLCHAIN_CLASSES[toolchain].check_executable():
            search_path = TOOLCHAIN_PATHS[toolchain] or "No path set"
            args_error(
                parser, "Could not find executable for %s.\n"
                "Currently set search path: %s" % (toolchain, search_path))

        # Assign config file. Precedence: test_config>app_config
Exemplo n.º 24
0
def main():
    error = False
    try:
        # Parse Options
        parser = get_default_options_parser(add_app_config=True)

        parser.add_argument("-D",
                            action="append",
                            dest="macros",
                            help="Add a macro definition")

        parser.add_argument(
            "-j",
            "--jobs",
            type=int,
            dest="jobs",
            default=0,
            help=
            "Number of concurrent jobs. Default: 0/auto (based on host machine's number of CPUs)"
        )

        parser.add_argument(
            "--source",
            dest="source_dir",
            type=argparse_filestring_type,
            default=None,
            help=
            "The source (input) directory (for sources other than tests). Defaults to current directory.",
            action="append")

        parser.add_argument("--build",
                            dest="build_dir",
                            type=argparse_dir_not_parent(ROOT),
                            default=None,
                            help="The build (output) directory")

        parser.add_argument(
            "-l",
            "--list",
            action="store_true",
            dest="list",
            default=False,
            help="List (recursively) available tests in order and exit")

        parser.add_argument(
            "-p",
            "--paths",
            dest="paths",
            type=argparse_many(argparse_filestring_type),
            default=None,
            help=
            "Limit the tests to those within the specified comma separated list of paths"
        )

        format_choices = ["list", "json"]
        format_default_choice = "list"
        format_help = "Change the format in which tests are listed. Choices include: %s. Default: %s" % (
            ", ".join(format_choices), format_default_choice)
        parser.add_argument("-f",
                            "--format",
                            dest="format",
                            type=argparse_lowercase_type(
                                format_choices, "format"),
                            default=format_default_choice,
                            help=format_help)

        parser.add_argument(
            "--continue-on-build-fail",
            action="store_true",
            dest="continue_on_build_fail",
            default=None,
            help="Continue trying to build all tests if a build failure occurs"
        )

        #TODO validate the names instead of just passing through str
        parser.add_argument(
            "-n",
            "--names",
            dest="names",
            type=argparse_many(str),
            default=None,
            help="Limit the tests to a comma separated list of names")

        parser.add_argument("--test-config",
                            dest="test_config",
                            type=str,
                            default=None,
                            help="Test config for a module")

        parser.add_argument(
            "--test-spec",
            dest="test_spec",
            default=None,
            help=
            "Destination path for a test spec file that can be used by the Greentea automated test tool"
        )

        parser.add_argument(
            "--build-report-junit",
            dest="build_report_junit",
            default=None,
            help="Destination path for a build report in the JUnit xml format")
        parser.add_argument("--build-data",
                            dest="build_data",
                            default=None,
                            help="Dump build_data to this file")

        parser.add_argument("-v",
                            "--verbose",
                            action="store_true",
                            dest="verbose",
                            default=False,
                            help="Verbose diagnostic output")

        parser.add_argument(
            "--silent",
            action="store_true",
            dest="silent",
            default=False,
            help="Silent diagnostic output (no copy, compile notification)")

        parser.add_argument("--stats-depth",
                            type=int,
                            dest="stats_depth",
                            default=2,
                            help="Depth level for static memory report")

        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)"
        )

        parser.add_argument("--icetea",
                            action="store_true",
                            dest="icetea",
                            default=False,
                            help="Only icetea tests")

        parser.add_argument("--greentea",
                            action="store_true",
                            dest="greentea",
                            default=False,
                            help="Only greentea tests")

        options = parser.parse_args()

        # Filter tests by path if specified
        if options.paths:
            all_paths = options.paths
        else:
            all_paths = ["."]

        all_tests = {}
        tests = {}
        end_warnings = []

        # As default both test tools are enabled
        if not (options.greentea or options.icetea):
            options.greentea = True
            options.icetea = True

        # Target
        if options.mcu is None:
            args_error(parser, "argument -m/--mcu is required")
        mcu = extract_mcus(parser, options)[0]
        target = Target.get_target(mcu)

        # Toolchain
        if options.tool is None:
            args_error(parser, "argument -t/--tool is required")
        toolchain = options.tool[0]

        try:
            toolchain_name, internal_tc_name, end_warnings = find_valid_toolchain(
                target, toolchain)
        except NoValidToolchainException as e:
            print_end_warnings(e.end_warnings)
            args_error(parser, str(e))

        # Assign config file. Precedence: test_config>app_config
        # TODO: merge configs if both given
        if options.test_config:
            config = get_test_config(options.test_config, mcu)
            if not config:
                args_error(
                    parser,
                    "argument --test-config contains invalid path or identifier"
                )
        elif options.app_config:
            config = options.app_config
        else:
            config = Config.find_app_config(options.source_dir)

        if not config:
            config = get_default_config(options.source_dir or ['.'], mcu)

        # Find all tests in the relevant paths
        for path in all_paths:
            all_tests.update(
                find_tests(base_dir=path,
                           target_name=mcu,
                           toolchain_name=toolchain_name,
                           icetea=options.icetea,
                           greentea=options.greentea,
                           app_config=config))

        # Filter tests by name if specified
        if options.names:
            all_names = options.names
            all_names = [x.lower() for x in all_names]

            for name in all_names:
                if any(
                        fnmatch.fnmatch(testname, name)
                        for testname in all_tests):
                    for testname, test in all_tests.items():
                        if fnmatch.fnmatch(testname, name):
                            tests[testname] = test
                else:
                    print("[Warning] Test with name '%s' was not found in the "
                          "available tests" % (name))
        else:
            tests = all_tests

        if options.list:
            # Print available tests in order and exit
            print_tests(tests, options.format)
            sys.exit(0)
        else:
            # Build all tests
            if not options.build_dir:
                args_error(parser, "argument --build is required")

            base_source_paths = options.source_dir

            # Default base source path is the current directory
            if not base_source_paths:
                base_source_paths = ['.']

            build_report = {}
            build_properties = {}

            library_build_success = False
            profile = extract_profile(parser, options, internal_tc_name)
            try:
                resource_filter = None
                if target.is_PSA_secure_target:
                    resource_filter = OsAndSpeResourceFilter()
                    generate_psa_sources(source_dirs=base_source_paths,
                                         ignore_paths=[options.build_dir])

                # Build sources
                notify = TerminalNotifier(options.verbose, options.silent)
                build_library(base_source_paths,
                              options.build_dir,
                              mcu,
                              toolchain_name,
                              jobs=options.jobs,
                              clean=options.clean,
                              report=build_report,
                              properties=build_properties,
                              name="mbed-build",
                              macros=options.macros,
                              notify=notify,
                              archive=False,
                              app_config=config,
                              build_profile=profile,
                              ignore=options.ignore,
                              resource_filter=resource_filter)

                library_build_success = True
            except ToolException as e:
                # ToolException output is handled by the build log
                print("[ERROR] " + str(e))
                pass
            except NotSupportedException as e:
                # NotSupportedException is handled by the build log
                print("[ERROR] " + str(e))
                pass
            except Exception as e:
                if options.verbose:
                    import traceback
                    traceback.print_exc()
                # Some other exception occurred, print the error message
                print(e)

            if not library_build_success:
                print("Failed to build library")
            else:
                if target.is_PSA_secure_target:
                    resource_filter = SpeOnlyResourceFilter()
                else:
                    resource_filter = None

                # Build all the tests
                notify = TerminalNotifier(options.verbose, options.silent)
                test_build_success, test_build = build_tests(
                    tests, [os.path.relpath(options.build_dir)],
                    options.build_dir,
                    mcu,
                    toolchain_name,
                    clean=options.clean,
                    report=build_report,
                    properties=build_properties,
                    macros=options.macros,
                    notify=notify,
                    jobs=options.jobs,
                    continue_on_build_fail=options.continue_on_build_fail,
                    app_config=config,
                    build_profile=profile,
                    stats_depth=options.stats_depth,
                    ignore=options.ignore,
                    resource_filter=resource_filter)

                # If a path to a test spec is provided, write it to a file
                if options.test_spec:
                    write_json_to_file(test_spec_from_test_builds(test_build),
                                       options.test_spec)

            # If a path to a JUnit build report spec is provided, write it to a file
            if options.build_report_junit:
                report_exporter = ReportExporter(ResultExporterType.JUNIT,
                                                 package="build")
                report_exporter.report_to_file(
                    build_report,
                    options.build_report_junit,
                    test_suite_properties=build_properties)

            # Print memory map summary on screen
            if build_report:
                print()
                print(print_build_memory_usage(build_report))

            print_report_exporter = ReportExporter(ResultExporterType.PRINT,
                                                   package="build")
            status = print_report_exporter.report(build_report)
            if options.build_data:
                merge_build_data(options.build_data, build_report, "test")

            if status:
                sys.exit(0)
            else:
                sys.exit(1)

    except KeyboardInterrupt as e:
        print("\n[CTRL+c] exit")
    except ConfigException as e:
        # Catching ConfigException here to prevent a traceback
        print("[ERROR] %s" % str(e))
        error = True
    except Exception as e:
        import traceback
        traceback.print_exc(file=sys.stdout)
        print("[ERROR] %s" % str(e))
        error = True

    print_end_warnings(end_warnings)
    if error:
        sys.exit(1)
Exemplo n.º 25
0
def main():
    start = time()

    # Parse Options
    parser = get_default_options_parser()

    parser.add_argument("--source", dest="source_dir", type=argparse_filestring_type,
                        default=None, help="The source (input) directory", action="append")

    parser.add_argument("--build", dest="build_dir", type=argparse_dir_not_parent(ROOT),
                      default=None, help="The build (output) directory")

    parser.add_argument("--no-archive", dest="no_archive", action="store_true",
                      default=False, help="Do not produce archive (.ar) file, but rather .o")

    # Extra libraries
    parser.add_argument("-r", "--rtos",
                      action="store_true",
                      dest="rtos",
                      default=False,
                      help="Compile the rtos")

    parser.add_argument("--rpc",
                      action="store_true",
                      dest="rpc",
                      default=False,
                      help="Compile the rpc library")

    parser.add_argument("-u", "--usb",
                      action="store_true",
                      dest="usb",
                      default=False,
                      help="Compile the USB Device library")

    parser.add_argument("-d", "--dsp",
                      action="store_true",
                      dest="dsp",
                      default=False,
                      help="Compile the DSP library")

    parser.add_argument( "--cpputest",
                      action="store_true",
                      dest="cpputest_lib",
                      default=False,
                      help="Compiles 'cpputest' unit test library (library should be on the same directory level as mbed repository)")

    parser.add_argument("-D",
                      action="append",
                      dest="macros",
                      help="Add a macro definition")

    parser.add_argument("-S", "--supported-toolchains",
                      action="store_true",
                      dest="supported_toolchains",
                      default=False,
                      help="Displays supported matrix of MCUs and toolchains")

    parser.add_argument('-f', '--filter',
                      dest='general_filter_regex',
                      default=None,
                      help='For some commands you can use filter to filter out results')

    parser.add_argument("-j", "--jobs", type=int, dest="jobs",
                      default=0, help="Number of concurrent jobs. Default: 0/auto (based on host machine's number of CPUs)")
    parser.add_argument("-N", "--artifact-name", dest="artifact_name",
                      default=None, help="The built project's name")

    parser.add_argument("-v", "--verbose",
                      action="store_true",
                      dest="verbose",
                      default=False,
                      help="Verbose diagnostic output")

    parser.add_argument("--silent",
                      action="store_true",
                      dest="silent",
                      default=False,
                      help="Silent diagnostic output (no copy, compile notification)")

    parser.add_argument("-x", "--extra-verbose-notifications",
                      action="store_true",
                      dest="extra_verbose_notify",
                      default=False,
                      help="Makes compiler more verbose, CI friendly.")

    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()

    # Only prints matrix of supported toolchains
    if options.supported_toolchains:
        print(mcu_toolchain_matrix(platform_filter=options.general_filter_regex))
        exit(0)


    # Get target list
    targets = extract_mcus(parser, options) if options.mcu else TARGET_NAMES

    # Get toolchains list
    toolchains = options.tool if options.tool else TOOLCHAINS

    if options.source_dir and not options.build_dir:
        args_error(parser, "argument --build is required by argument --source")


    # Get libraries list
    libraries = []

    # Additional Libraries
    if options.rpc:
        libraries.extend(["rpc"])
    if options.usb:
        libraries.append("usb")
    if options.dsp:
        libraries.extend(["dsp"])
    if options.cpputest_lib:
        libraries.extend(["cpputest"])

    # Build results
    failures = []
    successes = []
    skipped = []
    end_warnings = []

    if options.clean:
        clean_psa_autogen()

    for toolchain in toolchains:
        for target_name in targets:
            target = Target.get_target(target_name)

            try:
                toolchain_name, internal_tc_name, end_warnings = find_valid_toolchain(
                    target, toolchain
                )
            except NoValidToolchainException as e:
                print_end_warnings(e.end_warnings)
                args_error(parser, str(e))
            tt_id = "%s::%s" % (internal_tc_name, target_name)
            if not target_supports_toolchain(target, toolchain_name):
                # Log this later
                print("%s skipped: toolchain not supported" % tt_id)
                skipped.append(tt_id)
            else:
                try:
                    notifier = TerminalNotifier(options.verbose, options.silent)
                    profile = extract_profile(parser, options, internal_tc_name)

                    if options.source_dir:
                        if target.is_PSA_target:
                            generate_psa_sources(
                                source_dirs=options.source_dir,
                                ignore_paths=[options.build_dir]
                            )

                        resource_filter = None
                        if target.is_PSA_secure_target:
                            resource_filter = OsAndSpeResourceFilter()

                        lib_build_res = build_library(
                            options.source_dir, options.build_dir, target, toolchain_name,
                            jobs=options.jobs,
                            clean=options.clean,
                            archive=(not options.no_archive),
                            macros=options.macros,
                            name=options.artifact_name,
                            build_profile=profile,
                            ignore=options.ignore,
                            notify=notifier,
                            resource_filter=resource_filter
                        )
                    else:
                        lib_build_res = build_mbed_libs(
                            target, toolchain_name,
                            jobs=options.jobs,
                            clean=options.clean,
                            macros=options.macros,
                            build_profile=profile,
                            ignore=options.ignore,
                            notify=notifier,
                        )

                    for lib_id in libraries:
                        build_lib(
                            lib_id, target, toolchain_name,
                            clean=options.clean,
                            macros=options.macros,
                            jobs=options.jobs,
                            build_profile=profile,
                            ignore=options.ignore,
                        )
                    if lib_build_res:
                        successes.append(tt_id)
                    else:
                        skipped.append(tt_id)
                except KeyboardInterrupt as e:
                    print("\n[CTRL+c] exit")
                    print_end_warnings(end_warnings)
                    sys.exit(0)
                except Exception as e:
                    if options.verbose:
                        import traceback
                        traceback.print_exc(file=sys.stdout)
                        print_end_warnings(end_warnings)
                        sys.exit(1)
                    failures.append(tt_id)
                    print(e)

    # Write summary of the builds
    print("\nCompleted in: (%.2f)s\n" % (time() - start))

    for report, report_name in [(successes, "Build successes:"),
                                (skipped, "Build skipped:"),
                                (failures, "Build failures:"),
                               ]:
        if report:
            print(print_build_results(report, report_name))

    print_end_warnings(end_warnings)
    if failures:
        sys.exit(1)
Exemplo n.º 26
0
        sys.exit()

    # force program to "0" if a source dir is specified
    if options.source_dir is not None:
        p = 0
    else:
        # Program Number or name
        p = options.program

    # If 'p' was set via -n to list of numbers make this a single element integer list
    if type(p) != type([]):
        p = [p]

    # Target
    if options.mcu is None:
        args_error(parser, "argument -m/--mcu is required")
    mcu = options.mcu[0]

    # Toolchain
    if options.tool is None:
        args_error(parser, "argument -t/--tool is required")
    toolchain = options.tool[0]

    if (options.program is None) and (not options.source_dir):
        args_error(parser, "one of -p, -n, or --source is required")

    if options.source_dir and not options.build_dir:
        args_error(
            parser,
            "argument --build is required when argument --source is provided")
Exemplo n.º 27
0
def main():
    """Entry point"""
    # Parse Options
    options, parser = get_args(sys.argv[1:])

    # Print available tests in order and exit
    if options.list_tests:
        print('\n'.join(str(test) for test in sorted(TEST_MAP.values())))
    elif options.supported_ides:
        if options.supported_ides == "matrix":
            print_large_string(mcu_ide_matrix())
        elif options.supported_ides == "ides":
            print(mcu_ide_list())
    elif options.supported_ides_html:
        html = mcu_ide_matrix(verbose_html=True)
        with open("README.md", "w") as readme:
            readme.write("Exporter IDE/Platform Support\n")
            readme.write("-----------------------------------\n")
            readme.write("\n")
            readme.write(html)
    elif options.update_packs:
        from tools.arm_pack_manager import Cache
        cache = Cache(True, True)
        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")

        if options.clean:
            clean(options.source_dir)

        ide = resolve_exporter_alias(options.ide)
        exporter, toolchain_name = get_exporter_toolchain(ide)
        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))

        try:
            export(mcu,
                   ide,
                   build=options.build,
                   src=options.source_dir,
                   macros=options.macros,
                   project_id=options.program,
                   zip_proj=not bool(options.source_dir) or options.zip,
                   build_profile=profile,
                   app_config=options.app_config,
                   export_path=options.build_dir,
                   ignore=options.ignore)
        except NotSupportedException as exc:
            args_error(parser, "%s not supported by %s" % (mcu, ide))
            print("[Not Supported] %s" % str(exc))
    exit(0)
Exemplo n.º 28
0
def main():
    """Entry point"""

    ide_list = ["iar", "uvision"]

    default_v2 = [test_name_known("MBED_BLINKY")]
    default_v5 = [check_valid_mbed_os('tests-mbedmicro-rtos-mbed-basic')]

    parser = argparse.ArgumentParser(
        description="Test progen builders. Leave any flag off"
        " to run with all possible options.")
    parser.add_argument("-i",
                        dest="ides",
                        default=ide_list,
                        type=argparse_many(
                            argparse_force_lowercase_type(
                                ide_list, "toolchain")),
                        help="The target IDE: %s" % str(ide_list))

    parser.add_argument("-p",
                        type=argparse_many(test_known),
                        dest="programs",
                        help="The index of the desired test program: [0-%d]" %
                        (len(TESTS) - 1))

    parser.add_argument("-n",
                        type=argparse_many(test_name_known),
                        dest="programs",
                        help="The name of the desired test program")

    parser.add_argument("-m",
                        "--mcu",
                        help=("Generate projects for the given MCUs"),
                        metavar="MCU",
                        type=argparse_many(str.upper))

    parser.add_argument("-os-tests",
                        type=argparse_many(check_valid_mbed_os),
                        dest="os_tests",
                        help="Mbed-os tests")

    parser.add_argument("-c",
                        "--clean",
                        dest="clean",
                        action="store_true",
                        help="clean up the exported project files",
                        default=False)

    parser.add_argument("--release",
                        dest="release",
                        type=check_version,
                        help="Which version of mbed to test",
                        default=RELEASE_VERSIONS[-1])

    parser.add_argument("--profile",
                        dest="profile",
                        action="append",
                        type=argparse_filestring_type,
                        default=[])

    options = parser.parse_args()
    # targets in chosen release
    targetnames = [
        target[0] for target in get_mbed_official_release(options.release)
    ]
    # all targets in release are default
    test_targets = options.mcu or targetnames
    if not all([t in targetnames for t in test_targets]):
        args_error(
            parser, "Only specify targets in release %s:\n%s" %
            (options.release, columnate(sorted(targetnames))))

    v2_tests, v5_tests = [], []
    if options.release == '5':
        v5_tests = options.os_tests or default_v5
    elif options.release == '2':
        v2_tests = options.programs or default_v2

    tests = []
    default_test = {
        key: None
        for key in ['ide', 'mcu', 'name', 'id', 'src', 'log']
    }
    for mcu in test_targets:
        for ide in options.ides:
            log = "build_log.txt" if ide == 'iar' \
                else join('build', 'build_log.txt')
            # add each test case to the tests array
            default_test.update({'mcu': mcu, 'ide': ide, 'log': log})
            for test in v2_tests:
                default_test.update({'name': TESTS[test]["id"], 'id': test})
                tests.append(copy(default_test))
            for test in v5_tests:
                default_test.update({'name': test[0], 'src': [test[1], ROOT]})
                tests.append(copy(default_test))
    test = ExportBuildTest(tests, parser, options)
    test.batch_tests(clean=options.clean)
    print_results(test.successes, test.failures, test.skips)
    sys.exit(len(test.failures))
Exemplo n.º 29
0
                            help="Verbose diagnostic output")

        options = parser.parse_args()

        # Filter tests by path if specified
        if options.paths:
            all_paths = options.paths
        else:
            all_paths = ["."]

        all_tests = {}
        tests = {}

        # Target
        if options.mcu is None:
            args_error(parser, "argument -m/--mcu is required")
        mcu = options.mcu[0]

        # Toolchain
        if options.tool is None:
            args_error(parser, "argument -t/--tool is required")
        toolchain = options.tool[0]

        if not TOOLCHAIN_CLASSES[toolchain].check_executable():
            search_path = TOOLCHAIN_PATHS[toolchain] or "No path set"
            args_error(
                parser, "Could not find executable for %s.\n"
                "Currently set search path: %s" % (toolchain, search_path))

        # App config
        # Disable finding `mbed_app.json` files in the source tree if not
Exemplo n.º 30
0
                      default=None,
                      help="use the specified linker script")

    (options, args) = parser.parse_args()

    # Only prints matrix of supported toolchains
    if options.supported_toolchains:
        print mcu_toolchain_matrix(
            platform_filter=options.general_filter_regex)
        exit(0)

    if options.source_dir:
        for path in options.source_dir:
            if not isfile(path) and not isdir(path):
                args_error(
                    parser,
                    "[ERROR] you passed \"{}\" to --source, which does not exist"
                    .format(path))

    # Print available tests in order and exit
    if options.list_tests is True:
        print '\n'.join(map(str, sorted(TEST_MAP.values())))
        sys.exit()

    # force program to "0" if a source dir is specified
    if options.source_dir is not None:
        p = 0
        n = None
    else:
        # Program Number or name
        p, n = options.program, options.program_name
Exemplo n.º 31
0
def main():
    """Entry point"""
    # Parse Options
    parser = ArgumentParser()

    targetnames = TARGET_NAMES
    targetnames.sort()
    toolchainlist = EXPORTERS.keys()
    toolchainlist.sort()

    parser.add_argument("-m",
                        "--mcu",
                        metavar="MCU",
                        type=str.upper,
                        help="generate project for the given MCU ({})".format(
                            ', '.join(targetnames)))

    parser.add_argument("-i",
                        dest="ide",
                        type=argparse_force_lowercase_type(
                            toolchainlist, "toolchain"),
                        help="The target IDE: %s" % str(toolchainlist))

    parser.add_argument("-c",
                        "--clean",
                        action="store_true",
                        default=False,
                        help="clean the export directory")

    group = parser.add_mutually_exclusive_group(required=False)
    group.add_argument("-p",
                       type=test_known,
                       dest="program",
                       help="The index of the desired test program: [0-%s]" %
                       (len(TESTS) - 1))

    group.add_argument("-n",
                       type=test_name_known,
                       dest="program",
                       help="The name of the desired test program")

    parser.add_argument(
        "-b",
        dest="build",
        default=False,
        action="store_true",
        help="use the mbed library build, instead of the sources")

    group.add_argument("-L",
                       "--list-tests",
                       action="store_true",
                       dest="list_tests",
                       default=False,
                       help="list available programs in order and exit")

    group.add_argument("-S",
                       "--list-matrix",
                       dest="supported_ides",
                       default=False,
                       const="matrix",
                       choices=["matrix", "ides"],
                       nargs="?",
                       help="displays supported matrix of MCUs and IDEs")

    parser.add_argument("-E",
                        action="store_true",
                        dest="supported_ides_html",
                        default=False,
                        help="writes tools/export/README.md")

    parser.add_argument("--source",
                        action="append",
                        type=argparse_filestring_type,
                        dest="source_dir",
                        default=[],
                        help="The source (input) directory")

    parser.add_argument("-D",
                        action="append",
                        dest="macros",
                        help="Add a macro definition")

    parser.add_argument("--profile", dest="profile", action="append",
                        type=argparse_profile_filestring_type,
                        help="Build profile to use. Can be either path to json" \
                        "file or one of the default one ({})".format(", ".join(list_profiles())),
                        default=[])

    parser.add_argument("--update-packs",
                        dest="update_packs",
                        action="store_true",
                        default=False)
    parser.add_argument("--app-config", dest="app_config", default=None)

    options = parser.parse_args()

    # Print available tests in order and exit
    if options.list_tests is True:
        print '\n'.join([str(test) for test in sorted(TEST_MAP.values())])
        sys.exit()

    # Only prints matrix of supported IDEs
    if options.supported_ides:
        if options.supported_ides == "matrix":
            print_large_string(mcu_ide_matrix())
        elif options.supported_ides == "ides":
            print mcu_ide_list()
        exit(0)

    # Only prints matrix of supported IDEs
    if options.supported_ides_html:
        html = mcu_ide_matrix(verbose_html=True)
        try:
            with open("./export/README.md", "w") as readme:
                readme.write("Exporter IDE/Platform Support\n")
                readme.write("-----------------------------------\n")
                readme.write("\n")
                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)

    if options.update_packs:
        from tools.arm_pack_manager import Cache
        cache = Cache(True, True)
        cache.cache_everything()

    # Target
    if not options.mcu:
        args_error(parser, "argument -m/--mcu is required")

    # Toolchain
    if not options.ide:
        args_error(parser, "argument -i is required")

    # Clean Export Directory
    if options.clean:
        if exists(EXPORT_DIR):
            rmtree(EXPORT_DIR)

    zip_proj = not bool(options.source_dir)

    if (options.program is None) and (not options.source_dir):
        args_error(parser, "one of -p, -n, or --source is required")
    exporter, toolchain_name = get_exporter_toolchain(options.ide)
    mcu = extract_mcus(parser, options)[0]
    if not exporter.is_target_supported(mcu):
        args_error(parser, "%s not supported by %s" % (mcu, options.ide))
    profile = extract_profile(parser,
                              options,
                              toolchain_name,
                              fallback="debug")
    if options.clean:
        rmtree(BUILD_DIR)
    try:
        export(mcu,
               options.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)
    except NotSupportedException as exc:
        print "[ERROR] %s" % str(exc)
Exemplo n.º 32
0
                f.write(html)
        except IOError as e:
            print "I/O error({0}): {1}".format(e.errno, e.strerror)
        except:
            print "Unexpected error:", sys.exc_info()[0]
            raise
        exit(0)

    # Clean Export Directory
    if options.clean:
        if exists(EXPORT_DIR):
            rmtree(EXPORT_DIR)

    # Target
    if options.mcu is None :
        args_error(parser, "[ERROR] You should specify an MCU")
    mcus = options.mcu

    # IDE
    if options.ide is None:
        args_error(parser, "[ERROR] You should specify an IDE")
    ide = options.ide

    # Export results
    successes = []
    failures = []
    zip = True
    clean = True

    # source_dir = use relative paths, otherwise sources are copied
    sources_relative = True if options.source_dir else False
Exemplo n.º 33
0
        sys.exit()

    # force program to "0" if a source dir is specified
    if options.source_dir is not None:
        p = 0
    else:
        # Program Number or name
        p = options.program

    # If 'p' was set via -n to list of numbers make this a single element integer list
    if type(p) != type([]):
        p = [p]

    # Target
    if options.mcu is None:
        args_error(parser, "argument -m/--mcu is required")
    mcu = options.mcu[0]

    # Toolchain
    if options.tool is None:
        args_error(parser, "argument -t/--tool is required")
    toolchain = options.tool[0]

    if (options.program is None) and (not options.source_dir):
        args_error(parser, "one of -p, -n, or --source is required")

    if options.source_dir and not options.build_dir:
        args_error(
            parser,
            "argument --build is required when argument --source is provided")
Exemplo n.º 34
0
                      default = accepted_targets)

    parser.add_argument("-c", "--clean",
                        dest="clean",
                        action = "store_true",
                        help="clean up the exported project files",
                        default=False)

    options = parser.parse_args()

    tests = options.tests
    ides = [ide.lower() for ide in options.ides]
    targets = [target.upper() for target in options.targets]

    if any(get_test_from_name(test) is None for test in tests):
        args_error(parser, "[ERROR] test name not recognized")

    if any(target not in accepted_targets for target in targets):
        args_error(parser, "[ERROR] mcu must be one of the following:\n %s" % '\n '.join(accepted_targets))

    if any(ide not in accepted_ides for ide in ides):
        args_error(parser, "[ERROR] ide must be in %s" % ', '.join(accepted_ides))

    build_test = ProgenBuildTest(ides, targets)
    successes, failures, skips = build_test.generate_and_build(tests, options.clean)
    print_results(successes, failures, skips)
    sys.exit(len(failures))