コード例 #1
0
def main():
    """Launch a device test server with the provided arguments."""
    args = parse_args()

    if "--" in args.runner_args:
        args.runner_args.remove("--")

    log_level = logging.DEBUG if args.verbose else logging.INFO
    pw_arduino_build.log.install(log_level)

    # Get arduino_package_path from either the config file or command line args.
    arduino_package_path = None
    if args.config_file:
        json_file_options, unused_config_path = decode_file_json(
            args.config_file)
        arduino_package_path = json_file_options.get("arduino_package_path",
                                                     None)
        # Must pass --config-file option in the runner_args.
        if "--config-file" not in args.runner_args:
            args.runner_args.append("--config-file")
            args.runner_args.append(args.config_file)

    # Check for arduino_package_path in the runner_args
    try:
        arduino_package_path = args.runner_args[
            args.runner_args.index("--arduino-package-path") + 1]
    except (ValueError, IndexError):
        # Only raise an error if arduino_package_path not set from the json.
        if arduino_package_path is None:
            raise UnknownArduinoCore("Test runner arguments: '{}'".format(
                " ".join(args.runner_args)))

    exit_code = launch_server(args.server_config, args.server_port,
                              args.runner_args, arduino_package_path)
    sys.exit(exit_code)
コード例 #2
0
ファイル: __main__.py プロジェクト: erwincoumans/pigweed
def load_config_file(args):
    """Load a config file and merge with command line options.

    Command line takes precedence over values loaded from a config file."""

    if args.save_config and not args.config_file:
        raise FileNotFoundError(
            "'--save-config' requires the '--config-file' option")

    if not args.config_file:
        return

    default_options = get_default_options()

    commandline_options = {
        # Global option
        "arduino_package_path": args.arduino_package_path,
        "arduino_package_name": args.arduino_package_name,
        "compiler_path_override": args.compiler_path_override,
        # These options may not exist unless show or run command
        "build_path": getattr(args, "build_path", None),
        "project_path": getattr(args, "project_path", None),
        "project_source_path": getattr(args, "project_source_path", None),
        "build_project_name": getattr(args, "build_project_name", None),
        "board": getattr(args, "board", None),
        "menu_options": getattr(args, "menu_options", None),
    }

    # Decode JSON config file.
    json_file_options, config_file_path = decode_file_json(args.config_file)

    # Merge config file with command line options.
    merged_options = {}
    for key, value in commandline_options.items():
        # Use the command line specified option by default
        merged_options[key] = value

        # Is this option in the config file?
        if json_file_options.get(key, None) is not None:
            # Use the json defined option if it's not set on the command
            # line (or is a default value).
            if value is None or value == default_options.get(key, None):
                merged_options[key] = json_file_options[key]

    # Update args namespace to matched merged_options.
    for key, value in merged_options.items():
        setattr(args, key, value)

    # Write merged_options if --save-config.
    if args.save_config:
        encoded_json = json.dumps(merged_options, indent=4)
        # Create parent directories
        os.makedirs(os.path.dirname(config_file_path), exist_ok=True)
        # Save json file.
        with open(config_file_path, "w") as jfile:
            jfile.write(encoded_json)
コード例 #3
0
def main():
    """Set up runner, and then flash/run device test."""
    args = parse_args()

    json_file_options, unused_config_path = decode_file_json(args.config_file)

    log_level = logging.DEBUG if args.verbose else logging.INFO
    pw_arduino_build.log.install(log_level)

    # Construct arduino_builder flash arguments for a given .elf binary.
    arduino_package_path = get_option("arduino_package_path",
                                      json_file_options,
                                      args,
                                      required=True)
    # Arduino core args.
    arduino_builder_args = [
        "--arduino-package-path",
        arduino_package_path,
        "--arduino-package-name",
        get_option("arduino_package_name",
                   json_file_options,
                   args,
                   required=True),
    ]

    # Use CIPD installed compilers.
    compiler_path_override = get_option("compiler_path_override",
                                        json_file_options, args)
    if compiler_path_override:
        arduino_builder_args += [
            "--compiler-path-override", compiler_path_override
        ]

    # Run subcommand with board selection arg.
    arduino_builder_args += [
        "run", "--board",
        get_option("board", json_file_options, args, required=True)
    ]

    # .elf file location args.
    binary = args.binary
    build_path = binary.parent.as_posix()
    arduino_builder_args += ["--build-path", build_path]
    build_project_name = binary.name
    # Remove '.elf' extension.
    match_result = re.match(r'(.*?)\.elf$', binary.name, re.IGNORECASE)
    if match_result:
        build_project_name = match_result[1]
        arduino_builder_args += ["--build-project-name", build_project_name]

    # USB port is passed to arduino_builder_args via --set-variable args.
    if args.set_variable:
        for var in args.set_variable:
            arduino_builder_args += ["--set-variable", var]

    if run_device_test(binary.as_posix(),
                       args.flash_only,
                       args.port,
                       args.baud,
                       args.test_timeout,
                       args.upload_tool,
                       arduino_package_path,
                       test_runner_args=arduino_builder_args):
        sys.exit(0)
    else:
        sys.exit(1)