def main():
    """Entry Point"""
    try:
        # Parse Options
        parser = ArgumentParser()

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

        parser.add_argument('-f', '--filter',
                            dest='general_filter_regex',
                            default=None,
                            help='Filter targets')

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

        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)

        # If auto_detect attribute is present, we assume other auto-detection
        # parameters like 'toolchains_filter' are also set.
        muts = get_autodetected_MUTS_list()

        mcu_filter = options.general_filter_regex or ".*"

        count = 0
        for mut in muts.values():
            if re.match(mcu_filter, mut['mcu'] or "Unknown"):
                interface_version = get_interface_version(mut['disk'])
                print("")
                print("[mbed] Detected %s, port %s, mounted %s, interface "
                      "version %s:" %
                      (mut['mcu'], mut['port'], mut['disk'], interface_version))
                print("[mbed] Supported toolchains for %s" % mut['mcu'])
                print(mcu_toolchain_matrix(platform_filter=mut['mcu']))
                count += 1

        if count == 0:
            print("[mbed] No mbed targets were detected on your system.")

    except KeyboardInterrupt:
        print("\n[CTRL+c] exit")
    except Exception as exc:
        import traceback
        traceback.print_exc(file=sys.stdout)
        print("[ERROR] %s" % str(exc))
        sys.exit(1)
Ejemplo n.º 2
0
def main():
    """Entry Point"""
    try:
        # Parse Options
        parser = ArgumentParser()

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

        parser.add_argument('-f', '--filter',
                            dest='general_filter_regex',
                            default=None,
                            help='Filter targets')

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

        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)

        # If auto_detect attribute is present, we assume other auto-detection
        # parameters like 'toolchains_filter' are also set.
        muts = get_autodetected_MUTS_list()

        mcu_filter = options.general_filter_regex or ".*"

        count = 0
        for mut in muts.values():
            if re.match(mcu_filter, mut['mcu'] or "Unknown"):
                interface_version = get_interface_version(mut['disk'])
                print("")
                print("[mbed] Detected %s, port %s, mounted %s, interface "
                      "version %s:" %
                      (mut['mcu'], mut['port'], mut['disk'], interface_version))
                print("[mbed] Supported toolchains for %s" % mut['mcu'])
                print(mcu_toolchain_matrix(platform_filter=mut['mcu']))
                count += 1

        if count == 0:
            print("[mbed] No mbed targets were detected on your system.")

    except KeyboardInterrupt:
        print("\n[CTRL+c] exit")
    except Exception as exc:
        import traceback
        traceback.print_exc(file=sys.stdout)
        print("[ERROR] %s" % str(exc))
        sys.exit(1)
Ejemplo n.º 3
0
                        help="Dump build_data to this file")

    # Specify a different linker script
    parser.add_argument("-l",
                        "--linker",
                        dest="linker_script",
                        type=argparse_filestring_type,
                        default=None,
                        help="use the specified linker script")

    options = parser.parse_args()

    # Only prints matrix of supported toolchains
    if options.supported_toolchains:
        if options.supported_toolchains == "matrix":
            print mcu_toolchain_matrix(
                platform_filter=options.general_filter_regex)
        elif options.supported_toolchains == "toolchains":
            toolchain_list = mcu_toolchain_list()
            # Only print the lines that matter
            for line in toolchain_list.split("\n"):
                if not "mbed" in line:
                    print line
        elif options.supported_toolchains == "targets":
            print mcu_target_list()
        exit(0)

    # Print available tests in order and exit
    if options.list_tests is True:
        print '\n'.join(map(str, sorted(TEST_MAP.values())))
        sys.exit()
Ejemplo n.º 4
0
                      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.")

    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 = options.mcu if options.mcu else TARGET_NAMES

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

    if options.color:
        # This import happens late to prevent initializing colorization when we don't need it
        import colorize
        if options.verbose:
            notify = mbedToolchain.print_notify_verbose
        else:
            notify = mbedToolchain.print_notify
Ejemplo n.º 5
0
    if opts.test_case_report:
        test_case_report_cols = [
            'id', 'automated', 'description', 'peripherals', 'host_test',
            'duration', 'source_dir'
        ]
        print(
            get_avail_tests_summary_table(
                cols=test_case_report_cols,
                result_summary=False,
                join_delim='\n',
                platform_filter=opts.general_filter_regex))
        exit(0)

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

    test_spec = None
    MUTs = None

    if hasattr(opts, 'auto_detect') and opts.auto_detect:
        # If auto_detect attribute is present, we assume other auto-detection
        # parameters like 'toolchains_filter' are also set.
        print("MBEDLS: Detecting connected mbed-enabled devices... ")

        MUTs = get_autodetected_MUTS_list()

        for mut in MUTs.values():
            print("MBEDLS: Detected %s, port: %s, mounted: %s" %
                  (mut['mcu_unique'] if 'mcu_unique' in mut else mut['mcu'],
Ejemplo n.º 6
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)
Ejemplo n.º 7
0
                            dest='general_filter_regex',
                            default=None,
                            help='Filter targets')

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

        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)

        # If auto_detect attribute is present, we assume other auto-detection
        # parameters like 'toolchains_filter' are also set.
        MUTs = get_autodetected_MUTS_list()

        count = 0
        for mut in MUTs.values():
            print ""
            print "[mbed] Detected %s, port %s, mounted %s" % (
                mut['mcu'], mut['port'], mut['disk'])
            print "[mbed] Supported toolchains for %s" % mut['mcu']
            print mcu_toolchain_matrix(platform_filter=r'^' + mut['mcu'] + '$')
            count += 1
Ejemplo n.º 8
0
    # Specify a different linker script
    parser.add_argument("-l",
                        "--linker",
                        dest="linker_script",
                        type=argparse_filestring_type,
                        default=None,
                        help="use the specified linker script")

    options = parser.parse_args()

    # Only prints matrix of supported toolchains
    if options.supported_toolchains:
        if options.supported_toolchains == "matrix":
            print(
                mcu_toolchain_matrix(
                    platform_filter=options.general_filter_regex,
                    release_version=None))
        elif options.supported_toolchains == "toolchains":
            toolchain_list = mcu_toolchain_list()
            # Only print the lines that matter
            for line in toolchain_list.split("\n"):
                if not "mbed" in line:
                    print(line)
        elif options.supported_toolchains == "targets":
            print(mcu_target_list())
        exit(0)

    # Print available tests in order and exit
    if options.list_tests is True:
        print('\n'.join(map(str, sorted(TEST_MAP.values()))))
        sys.exit()
Ejemplo n.º 9
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")
Ejemplo n.º 10
0
        parser.add_argument('-f', '--filter',
                          dest='general_filter_regex',
                          default=None,
                          help='Filter targets')

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

        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)

        # If auto_detect attribute is present, we assume other auto-detection
        # parameters like 'toolchains_filter' are also set.
        MUTs = get_autodetected_MUTS_list()

        count = 0
        for mut in MUTs.values():
            print ""
            print "[mbed] Detected %s, port %s, mounted %s" % (mut['mcu'], mut['port'], mut['disk'])
            print "[mbed] Supported toolchains for %s" % mut['mcu']
            print mcu_toolchain_matrix(platform_filter=r'^'+mut['mcu']+'$')
            count += 1
        
        if count == 0: