Пример #1
0
    def AddParser(cls, parser):
        super(cls, BuildApCommand).AddParser(parser)

        parser.add_argument(
            '-b',
            '--build-target',
            dest='build_target',
            default=cros_build_lib.GetDefaultBoard(),
            required=not bool(cros_build_lib.GetDefaultBoard()),
            help='The build target whose AP firmware should be built.')

        parser.add_argument(
            '--fw-name',
            '--variant',
            dest='fw_name',
            help='Sets the FW_NAME environment variable. Set to build only the '
            "specified variant's firmware.")

        # TODO(saklein): Remove when added to base parser.
        parser.add_argument(
            '-n',
            '--dry-run',
            action='store_true',
            default=False,
            help='Perform a dry run, describing the steps without running them.'
        )
Пример #2
0
def ParseArguments(argv):
  """Parse command line arguments

  Returns:
    parsed arguments.
  """
  parser = argparse.ArgumentParser(description='Perform a fast approximation '
                                   'to emerge-$board autotest-all, by '
                                   'rsyncing source tree to sysroot.')

  default_board = cros_build_lib.GetDefaultBoard()
  parser.add_argument('--board', metavar='BOARD', default=default_board,
                      help='Board to perform quickmerge for. Default: ' +
                      (default_board or 'Not configured.'))
  parser.add_argument('--pretend', action='store_true',
                      help='Dry run only, do not modify sysroot autotest.')
  parser.add_argument('--overwrite', action='store_true',
                      help='Overwrite existing files even if newer.')
  parser.add_argument('--force', action='store_true',
                      help=argparse.SUPPRESS)
  parser.add_argument('--verbose', action='store_true',
                      help='Print detailed change report.')

  # Used only if test_that is calling autotest_quickmerge and has detected that
  # the sysroot autotest path is still in usr/local/autotest (ie the build
  # pre-dates https://chromium-review.googlesource.com/#/c/62880/ )
  parser.add_argument('--legacy_path', action='store_true',
                      help=argparse.SUPPRESS)

  return parser.parse_args(argv)
    def AddParser(cls, parser):
        super(FlashApCommand, cls).AddParser(parser)
        cls.AddDeviceArgument(parser,
                              schemes=[
                                  commandline.DEVICE_SCHEME_SSH,
                                  commandline.DEVICE_SCHEME_SERVO
                              ])

        parser.add_argument('-i',
                            '--image',
                            required=True,
                            type='path',
                            help='/path/to/BIOS_image.bin')
        parser.add_argument('-b',
                            '--build-target',
                            default=cros_build_lib.GetDefaultBoard(),
                            dest='build_target',
                            help='The name of the build target.')
        parser.add_argument('--flashrom',
                            action='store_true',
                            help='Use flashrom to flash instead of futility.')
        parser.add_argument('--fast',
                            action='store_true',
                            help='Speed up flashing by not validating flash.')
        parser.add_argument(
            '-n',
            '--dry-run',
            action='store_true',
            help=
            'Execute a dry-run. Print the commands that would be run instead '
            'of running them.')
Пример #4
0
def ParseArguments(argv):
    """Parse command line arguments

  Returns: parsed arguments.
  """
    parser = argparse.ArgumentParser(
        description='Perform a fast approximation '
        'to emerge-$board autotest-all, by '
        'rsyncing source tree to sysroot.')

    default_board = cros_build_lib.GetDefaultBoard()
    parser.add_argument('--board',
                        metavar='BOARD',
                        default=default_board,
                        help='Board to perform quickmerge for. Default: ' +
                        (default_board or 'Not configured.'))
    parser.add_argument('--pretend',
                        action='store_true',
                        help='Dry run only, do not modify sysroot autotest.')
    parser.add_argument('--overwrite',
                        action='store_true',
                        help='Overwrite existing files even if newer.')
    parser.add_argument('--force',
                        action='store_true',
                        help='Do not check whether destination tree is newer '
                        'than source tree, always perform quickmerge.')
    parser.add_argument('--verbose',
                        action='store_true',
                        help='Print detailed change report.')

    return parser.parse_args(argv)
Пример #5
0
def _parse_arguments_internal(argv):
    """
    Parse command line arguments

    @param argv: argument list to parse
    @returns:    tuple of parsed arguments and argv suitable for remote runs
    @raises SystemExit if arguments are malformed, or required arguments
            are not present.
    """
    local_parser, remote_argv = parse_local_arguments(argv)

    parser = argparse.ArgumentParser(description='Run remote tests.',
                                     parents=[local_parser])

    parser.add_argument('remote', metavar='REMOTE',
                        help='hostname[:port] for remote device. Specify '
                             ':lab: to run in test lab. When tests are run in '
                             'the lab, test_that will use the client autotest '
                             'package for the build specified with --build, '
                             'and the lab server code rather than local '
                             'changes.')
    test_runner_utils.add_common_args(parser)
    default_board = cros_build_lib.GetDefaultBoard()
    parser.add_argument('-b', '--board', metavar='BOARD', default=default_board,
                        action='store',
                        help='Board for which the test will run. Default: %s' %
                             (default_board or 'Not configured'))
    parser.add_argument('-m', '--model', metavar='MODEL', default='',
                        help='Specific model the test will run against. '
                             'Matches the model:FAKE_MODEL label for the host.')
    parser.add_argument('-i', '--build', metavar='BUILD',
                        default=test_runner_utils.NO_BUILD,
                        help='Build to test. Device will be reimaged if '
                             'necessary. Omit flag to skip reimage and test '
                             'against already installed DUT image. Examples: '
                             'link-paladin/R34-5222.0.0-rc2, '
                             'lumpy-release/R34-5205.0.0')
    parser.add_argument('-p', '--pool', metavar='POOL', default='suites',
                        help='Pool to use when running tests in the lab. '
                             'Default is "suites"')
    parser.add_argument('--autotest_dir', metavar='AUTOTEST_DIR',
                        help='Use AUTOTEST_DIR instead of normal board sysroot '
                             'copy of autotest, and skip the quickmerge step.')
    parser.add_argument('--no-quickmerge', action='store_true', default=False,
                        dest='no_quickmerge',
                        help='Skip the quickmerge step and use the sysroot '
                             'as it currently is. May result in un-merged '
                             'source tree changes not being reflected in the '
                             'run. If using --autotest_dir, this flag is '
                             'automatically applied.')
    parser.add_argument('--whitelist-chrome-crashes', action='store_true',
                        default=False, dest='whitelist_chrome_crashes',
                        help='Ignore chrome crashes when producing test '
                             'report. This flag gets passed along to the '
                             'report generation tool.')
    parser.add_argument('--ssh_private_key', action='store',
                        default=test_runner_utils.TEST_KEY_PATH,
                        help='Path to the private ssh key.')
    return parser.parse_args(argv), remote_argv
Пример #6
0
def GetDefaultBoard():
    """Look up default board.

  In a chrome checkout, return $SDK_BOARD. In a chromeos checkout,
  return the contents of .default_board.
  """
    if path_util.DetermineCheckout().type == path_util.CHECKOUT_TYPE_GCLIENT:
        return os.environ.get(cros_chrome_sdk.SDKFetcher.SDK_BOARD_ENV)
    return cros_build_lib.GetDefaultBoard()
Пример #7
0
 def __init__(self, device, board, image, debug=False, install=False,
              yes=False):
   """Initalizes USBImager."""
   self.device = device
   self.board = board if board else cros_build_lib.GetDefaultBoard()
   self.image = image
   self.debug = debug
   self.debug_level = logging.DEBUG if debug else logging.INFO
   self.install = install
   self.yes = yes
Пример #8
0
def GetParser():
    """Get a CLI parser."""
    parser = commandline.ArgumentParser(description=__doc__)
    parser.add_argument('--board',
                        default=cros_build_lib.GetDefaultBoard(),
                        help='The board to set package keywords for.')
    parser.add_argument('--host',
                        default=False,
                        action='store_true',
                        help='Uses the host instead of board')
    parser.add_argument('--remote',
                        default='',
                        help='For non-workon projects, the git remote to use.')
    parser.add_argument('--revision',
                        default='',
                        help='Use to override the manifest defined default '
                        'revision used for a project')
    parser.add_argument('--command',
                        default='git status',
                        dest='iterate_command',
                        help='The command to be run by forall.')
    parser.add_argument(
        '--workon_only',
        default=False,
        action='store_true',
        help='Apply to packages that have a workon ebuild only')
    parser.add_argument('--all',
                        default=False,
                        action='store_true',
                        help='Apply to all possible packages for the '
                        'given command (overrides workon_only)')

    commands = [
        ('start', 'Moves an ebuild to live (intended to support development)'),
        ('stop', 'Moves an ebuild to stable (use last known good)'),
        ('info', 'Print package name, repo name, and source directory.'),
        ('list', 'List of live ebuilds (workon ebuilds if --all)'),
        ('list-all', 'List all of the live ebuilds for all setup boards'),
        ('iterate', 'For each ebuild, cd to the source dir and run a command'),
    ]
    command_parsers = parser.add_subparsers(dest='command', title='commands')
    for command, description in commands:
        sub_parser = command_parsers.add_parser(command,
                                                description=description,
                                                help=description)
        sub_parser.add_argument('packages',
                                nargs='*',
                                help='The packages to run command against.')

    return parser
Пример #9
0
def _ParseArgs(argv):
  """Parse and validate arguments."""
  parser = GetParser()
  opts = parser.parse_args(argv)

  # Need the board if no image provided or only the basename is provided so
  # we can build out the full path to an image file.
  opts.board = opts.board or cros_build_lib.GetDefaultBoard()
  try:
    opts.image = image_lib.BuildImagePath(opts.board, opts.image)
  except image_lib.ImageDoesNotExistError as e:
    # Replace |arg| with --arg, otherwise messages still relevant.
    message = re.sub(r'\|(\w+)\|', r'--\1', str(e))
    parser.error(message)

  opts.Freeze()
  return opts
Пример #10
0
def Build(board=None, images=None, config=None, extra_env=None):
    """Build an image.

  Args:
    board (str): The board name.
    images (list): The image types to build.
    config (BuildConfig): The build configuration options.
    extra_env (dict): Environment variables to set for build_image.

  Returns:
    BuildResult
  """
    board = board or cros_build_lib.GetDefaultBoard()
    if not board:
        raise InvalidArgumentError('board is required.')
    images = images or [constants.IMAGE_TYPE_BASE]
    config = config or BuildConfig()

    if cros_build_lib.IsInsideChroot():
        cmd = [os.path.join(constants.CROSUTILS_DIR, 'build_image')]
    else:
        cmd = ['./build_image']

    cmd.extend(['--board', board])
    cmd.extend(config.GetArguments())
    cmd.extend(images)

    extra_env_local = extra_env.copy() if extra_env else {}

    with osutils.TempDir() as tempdir:
        status_file = os.path.join(tempdir, PARALLEL_EMERGE_STATUS_FILE_NAME)
        extra_env_local[
            constants.PARALLEL_EMERGE_STATUS_FILE_ENVVAR] = status_file
        result = cros_build_lib.run(cmd,
                                    enter_chroot=True,
                                    check=False,
                                    extra_env=extra_env_local)
        try:
            content = osutils.ReadFile(status_file).strip()
        except IOError:
            # No file means no packages.
            failed = None
        else:
            failed = content.split() if content else None

        return BuildResult(result.returncode, failed)
Пример #11
0
    def __init__(self, options):
        super(BuildCommand, self).__init__(options)
        self.chroot_update = options.chroot_update and options.deps
        if options.chroot_update and not options.deps:
            logging.debug('Skipping chroot update due to --nodeps')
        self.build_pkgs = options.packages
        self.host = False
        self.board = None

        if self.options.host:
            self.host = True
        elif self.options.board:
            self.board = self.options.board
        else:
            # If nothing is explicitly set, use the default board.
            self.board = cros_build_lib.GetDefaultBoard()

        # Set sysroot and friendly name. The latter is None if building for host.
        self.sysroot = cros_build_lib.GetSysroot(self.board)
Пример #12
0
def BuildImagePath(board, image):
    """Build a fully qualified path to the image.

  Args:
    board: str - The name of the board whose image is being tested when an
      image path is not specified.
    image: str - The path to an image (in which case |image| is simply returned)
      or the basename of the image file to use. When |image| is a basename, the
      |board| build directory is always used to find it.
  """
    # Prefer an image path if provided.
    if image and os.sep in image:
        if os.path.exists(image):
            return image
        else:
            raise ImageDoesNotExistError(
                'The provided image does not exist: %s' % image)

    # We have no image or a basename only, so we need the board to build out the
    # full path to an image file.
    if not board:
        board = cros_build_lib.GetDefaultBoard()

    if not board:
        if image:
            raise ImageDoesNotExistError(
                '|image| must be a full path or used with |board|.')
        else:
            raise ImageDoesNotExistError(
                'Either |image| or |board| must be provided.')

    # Build out the full path using the board's build path.
    image_file = image or 'recovery_image.bin'
    image = os.path.join(GetLatestImageLink(board), image_file)

    if not os.path.exists(image):
        raise ImageDoesNotExistError('Image does not exist: %s' % image)

    return image
Пример #13
0
def main(argv):
    shared = commandline.SharedParser()
    shared.add_argument('--board',
                        default=cros_build_lib.GetDefaultBoard(),
                        help='The board to set package keywords for.')
    shared.add_argument('--host',
                        default=False,
                        action='store_true',
                        help='Uses the host instead of board')
    shared.add_argument('--remote',
                        default='',
                        help='For non-workon projects, the git remote to use.')
    shared.add_argument('--revision',
                        default='',
                        help='Use to override the manifest defined default '
                        'revision used for a project')
    shared.add_argument('--command',
                        default='git status',
                        dest='iterate_command',
                        help='The command to be run by forall.')
    shared.add_argument(
        '--workon_only',
        default=False,
        action='store_true',
        help='Apply to packages that have a workon ebuild only')
    shared.add_argument('--all',
                        default=False,
                        action='store_true',
                        help='Apply to all possible packages for the '
                        'given command (overrides workon_only)')

    parser = commandline.ArgumentParser(description=__doc__,
                                        parents=[
                                            shared,
                                        ])

    # Add the shared 'packages' argument after creating the main parser so that
    # it is only bound/shared with the subcommands and doesn't confuse argparse.
    shared.add_argument('packages',
                        nargs='*',
                        help='The packages to run command against.')

    commands = [
        ('start', 'Moves an ebuild to live (intended to support development)'),
        ('stop', 'Moves an ebuild to stable (use last known good)'),
        ('info', 'Print package name, repo name, and source directory.'),
        ('list', 'List of live ebuilds (workon ebuilds if --all)'),
        ('list-all', 'List all of the live ebuilds for all setup boards'),
        ('iterate', 'For each ebuild, cd to the source dir and run a command'),
    ]
    command_parsers = parser.add_subparsers(dest='command', title='commands')
    for command, description in commands:
        command_parsers.add_parser(command,
                                   parents=(shared, ),
                                   help=description,
                                   description=description)

    options = parser.parse_args(argv)
    options.Freeze()

    if options.command == 'list-all':
        board_to_packages = workon_helper.ListAllWorkedOnAtoms()
        color = terminal.Color()
        for board in sorted(board_to_packages):
            print(color.Start(color.GREEN) + board + ':' + color.Stop())
            for package in board_to_packages[board]:
                print('    ' + package)
            print('')
        return 0

    # TODO(wiley): Assert that we're not running as root.
    cros_build_lib.AssertInsideChroot()

    if options.host:
        friendly_name = 'host'
        sysroot = '/'
    elif options.board:
        friendly_name = options.board
        sysroot = cros_build_lib.GetSysroot(board=options.board)
    else:
        cros_build_lib.Die('You must specify either --host, --board')

    helper = workon_helper.WorkonHelper(sysroot, friendly_name)
    try:
        if options.command == 'start':
            helper.StartWorkingOnPackages(options.packages,
                                          use_all=options.all,
                                          use_workon_only=options.workon_only)
        elif options.command == 'stop':
            helper.StopWorkingOnPackages(options.packages,
                                         use_all=options.all,
                                         use_workon_only=options.workon_only)
        elif options.command == 'info':
            triples = helper.GetPackageInfo(
                options.packages,
                use_all=options.all,
                use_workon_only=options.workon_only)
            for package, repos, paths in triples:
                print(package, ','.join(repos), ','.join(paths))
        elif options.command == 'list':
            packages = helper.ListAtoms(use_all=options.all,
                                        use_workon_only=options.workon_only)
            if packages:
                print('\n'.join(packages))
        elif options.command == 'iterate':
            helper.RunCommandInPackages(options.packages,
                                        options.iterate_command,
                                        use_all=options.all,
                                        use_workon_only=options.workon_only)
    except workon_helper.WorkonError as e:
        cros_build_lib.Die(e.message)

    return 0
Пример #14
0
def ParseArgs(argv):
    """Parses program arguments.

  Args:
    argv: The program arguments we want to parse.

  Returns:
    An options object which will tell us which command to run and which options
    to use for that command.
  """
    parser = commandline.ArgumentParser(description=__doc__)

    parser.add_argument('--board',
                        default=cros_build_lib.GetDefaultBoard(),
                        help='Board on which to run test.')

    subparsers = parser.add_subparsers(dest='command')

    subparsers.add_parser('cleanup', help='Undo setup command.')
    coverage_parser = subparsers.add_parser(
        'coverage', help='Get a coverage report for a fuzzer.')

    coverage_parser.add_argument('--package', help='Package to build.')

    corpus_parser = coverage_parser.add_mutually_exclusive_group()
    corpus_parser.add_argument('--corpus', help='Corpus to run fuzzer on.')

    corpus_parser.add_argument(
        '--download',
        action='store_true',
        help='Generate coverage report based on corpus from ClusterFuzz.')

    coverage_parser.add_argument(
        '--fuzzer',
        required=True,
        help='The fuzz target to generate a coverage report for.')

    coverage_parser.add_argument(
        '--fuzz-args',
        default='',
        help='Arguments to pass libFuzzer. '
        'Please use an equals sign or parsing will fail '
        '(i.e. --fuzzer_args="-rss_limit_mb=2048 -print_funcs=1").')

    download_parser = subparsers.add_parser('download',
                                            help='Download a corpus.')

    download_parser.add_argument(
        '--directory', help='Path to directory to download the corpus to.')

    download_parser.add_argument('--fuzzer',
                                 required=True,
                                 help='Fuzzer to download the corpus for.')

    reproduce_parser = subparsers.add_parser(
        'reproduce', help='Run a fuzzer on a testcase.')

    reproduce_parser.add_argument('--testcase',
                                  required=True,
                                  help='Path of testcase to run fuzzer on.')

    reproduce_parser.add_argument('--fuzzer',
                                  required=True,
                                  help='Fuzzer to reproduce the crash on.')

    reproduce_parser.add_argument('--package', help='Package to build.')

    reproduce_parser.add_argument('--build-type',
                                  choices=BuildType.CHOICES,
                                  help='Type of build.',
                                  type=str.lower)  # Ignore sanitizer case.

    subparsers.add_parser('setup', help='Set up the sysroot to test fuzzing.')

    subparsers.add_parser(
        'shell',
        help='Set up sysroot for fuzzing and get a shell in the sysroot.')

    opts = parser.parse_args(argv)
    opts.Freeze()
    return opts