Exemplo n.º 1
0
    def GetParser():
        """Parse a list of args.

    Args:
      argv: list of command line arguments.

    Returns:
      List of parsed opts.
    """
        parser = commandline.ArgumentParser(description=__doc__)
        parser.add_argument('--start',
                            action='store_true',
                            default=False,
                            help='Start the VM.')
        parser.add_argument('--stop',
                            action='store_true',
                            default=False,
                            help='Stop the VM.')
        parser.add_argument('--image-path',
                            type=str,
                            help='Path to VM image to launch with --start.')
        parser.add_argument('--image-format',
                            default=VM.IMAGE_FORMAT,
                            help='Format of the VM image (raw, qcow2, ...).')
        parser.add_argument('--qemu-path',
                            type=str,
                            help='Path of qemu binary to launch with --start.')
        parser.add_argument(
            '--qemu-m',
            type=str,
            default='8G',
            help='Memory argument that will be passed to qemu.')
        parser.add_argument(
            '--qemu-smp',
            type=int,
            default='0',
            help='SMP argument that will be passed to qemu. (0 '
            'means auto-detection.)')
        # TODO(pwang): replace SandyBridge to Haswell-noTSX once lab machine
        # running VMTest all migrate to GCE.
        parser.add_argument('--qemu-cpu',
                            type=str,
                            default='SandyBridge,-invpcid,-tsc-deadline',
                            help='CPU argument that will be passed to qemu.')
        parser.add_argument('--qemu-bios-path',
                            type=str,
                            help='Path of directory with qemu bios files.')
        parser.add_argument('--disable-kvm',
                            dest='enable_kvm',
                            action='store_false',
                            default=True,
                            help='Disable KVM, use software emulation.')
        parser.add_argument('--no-display',
                            dest='display',
                            action='store_false',
                            default=True,
                            help='Do not display video output.')
        parser.add_argument('--ssh-port',
                            type=int,
                            default=VM.SSH_PORT,
                            help='ssh port to communicate with VM.')
        sdk_board_env = os.environ.get(
            cros_chrome_sdk.SDKFetcher.SDK_BOARD_ENV)
        parser.add_argument('--board',
                            default=sdk_board_env,
                            help='Board to use.')
        parser.add_argument('--cache-dir',
                            type=str,
                            default=path_util.GetCacheDir(),
                            help='Cache directory to use.')
        parser.add_argument('--vm-dir',
                            type=str,
                            help='Temp VM directory to use.')
        parser.add_argument('--dry-run',
                            action='store_true',
                            default=False,
                            help='dry run for debugging.')
        parser.add_argument('--cmd',
                            action='store_true',
                            default=False,
                            help='Run a command in the VM.')
        parser.add_argument('args',
                            nargs=argparse.REMAINDER,
                            help='Command to run in the VM.')
        return parser
Exemplo n.º 2
0
 def setUp(self):
   self.parser = commandline.ArgumentParser()
   cros_bisect.BisectCommand.AddParser(self.parser)
Exemplo n.º 3
0
def main(argv):
    parser = commandline.ArgumentParser(description=__doc__)

    # TODO: Make sym_paths, breakpad_root, and root exclusive.

    parser.add_argument('sym_paths',
                        type='path_or_uri',
                        nargs='*',
                        default=None,
                        help='symbol file or directory or URL or tarball')
    parser.add_argument('--board',
                        default=None,
                        help='Used to find default breakpad_root.')
    parser.add_argument('--breakpad_root',
                        type='path',
                        default=None,
                        help='full path to the breakpad symbol directory')
    parser.add_argument('--root',
                        type='path',
                        default=None,
                        help='full path to the chroot dir')
    parser.add_argument('--official_build',
                        action='store_true',
                        default=False,
                        help='point to official symbol server')
    parser.add_argument('--server',
                        type=str,
                        default=None,
                        help='URI for custom symbol server')
    parser.add_argument('--regenerate',
                        action='store_true',
                        default=False,
                        help='regenerate all symbols')
    parser.add_argument('--upload-limit',
                        type=int,
                        help='only upload # number of symbols')
    parser.add_argument('--strip_cfi',
                        type=int,
                        default=DEFAULT_FILE_LIMIT,
                        help='strip CFI data for files above this size')
    parser.add_argument('--failed-list',
                        type='path',
                        help='where to save a list of failed symbols')
    parser.add_argument('--dedupe',
                        action='store_true',
                        default=False,
                        help='use the swarming service to avoid re-uploading')
    parser.add_argument('--yes',
                        action='store_true',
                        default=False,
                        help='answer yes to all prompts')
    parser.add_argument('--product_name',
                        type=str,
                        default='ChromeOS',
                        help='Produce Name for breakpad stats.')
    parser.add_argument('--api_key',
                        type=str,
                        default=None,
                        help='full path to the API key file')

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

    # Figure out the symbol files/directories to upload.
    if opts.sym_paths:
        sym_paths = opts.sym_paths
    elif opts.breakpad_root:
        sym_paths = [opts.breakpad_root]
    elif opts.root:
        if not opts.board:
            cros_build_lib.Die('--board must be set if --root is used.')
        breakpad_dir = cros_generate_breakpad_symbols.FindBreakpadDir(
            opts.board)
        sym_paths = [os.path.join(opts.root, breakpad_dir.lstrip('/'))]
    else:
        cros_build_lib.Die(
            '--sym_paths, --breakpad_root, or --root must be set.')

    if opts.sym_paths or opts.breakpad_root:
        if opts.regenerate:
            cros_build_lib.Die(
                '--regenerate may not be used with specific files, '
                'or breakpad_root')
    else:
        if opts.board is None:
            cros_build_lib.Die('--board is required')

    # Figure out which crash server to upload too.
    upload_url = opts.server
    if not upload_url:
        if opts.official_build:
            upload_url = OFFICIAL_UPLOAD_URL
        else:
            logging.warning('unofficial builds upload to the staging server')
            upload_url = STAGING_UPLOAD_URL

    # Set up the API key needed to authenticate to Crash server.
    # Allow for a local key file for testing purposes.
    if opts.api_key:
        api_key_file = opts.api_key
    else:
        api_key_file = constants.CRASH_API_KEY

    api_key = osutils.ReadFile(api_key_file)

    # Confirm we really want the long upload.
    if not opts.yes:
        prolog = '\n'.join(
            textwrap.wrap(
                textwrap.dedent("""
        Uploading symbols for an entire Chromium OS build is really only
        necessary for release builds and in a few cases for developers
        to debug problems.  It will take considerable time to run.  For
        developer debugging purposes, consider instead passing specific
        files to upload.
    """), 80)).strip()
        if not cros_build_lib.BooleanPrompt(
                prompt='Are you sure you want to upload all build symbols',
                default=False,
                prolog=prolog):
            cros_build_lib.Die('better safe than sorry')

    ret = 0

    # Regenerate symbols from binaries.
    if opts.regenerate:
        ret += cros_generate_breakpad_symbols.GenerateBreakpadSymbols(
            opts.board, breakpad_dir=opts.breakpad_root)

    # Do the upload.
    ret += UploadSymbols(sym_paths=sym_paths,
                         upload_url=upload_url,
                         failed_list=opts.failed_list,
                         upload_limit=opts.upload_limit,
                         strip_cfi=opts.strip_cfi,
                         api_key=api_key)

    if ret:
        logging.error('encountered %i problem(s)', ret)
        # Since exit(status) gets masked, clamp it to 1 so we don't inadvertently
        # return 0 in case we are a multiple of the mask.
        return 1
def main(argv):
    parser = commandline.ArgumentParser(description=__doc__)
    parser.add_argument('-u',
                        '--nousepkg',
                        action='store_false',
                        dest='usepkg',
                        default=True,
                        help='Use prebuilt packages if possible')
    parser.add_argument('-d',
                        '--deleteold',
                        action='store_true',
                        dest='deleteold',
                        default=False,
                        help='Unmerge deprecated packages')
    parser.add_argument(
        '-t',
        '--targets',
        dest='targets',
        default='sdk',
        help="Comma separated list of tuples. Special keywords "
        "'host', 'sdk', 'boards', and 'all' are "
        "allowed. Defaults to 'sdk'.")
    parser.add_argument(
        '--include-boards',
        default='',
        metavar='BOARDS',
        help='Comma separated list of boards whose toolchains we '
        'will always include. Default: none')
    parser.add_argument('--hostonly',
                        dest='hostonly',
                        default=False,
                        action='store_true',
                        help='Only setup the host toolchain. '
                        'Useful for bootstrapping chroot')
    parser.add_argument('--show-board-cfg',
                        '--show-cfg',
                        dest='cfg_name',
                        default=None,
                        help='Board  to list toolchains tuples for')
    parser.add_argument('--create-packages',
                        action='store_true',
                        default=False,
                        help='Build redistributable packages')
    parser.add_argument('--output-dir',
                        default=os.getcwd(),
                        type='path',
                        help='Output directory')
    parser.add_argument('--reconfig',
                        default=False,
                        action='store_true',
                        help='Reload crossdev config and reselect toolchains')
    parser.add_argument('--sysroot',
                        type='path',
                        help='The sysroot in which to install the toolchains')

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

    # Figure out what we're supposed to do and reject conflicting options.
    if options.cfg_name and options.create_packages:
        parser.error('conflicting options: create-packages & show-board-cfg')

    targets_wanted = set(options.targets.split(','))
    boards_wanted = (set(options.include_boards.split(','))
                     if options.include_boards else set())

    if options.cfg_name:
        ShowConfig(options.cfg_name)
    elif options.create_packages:
        cros_build_lib.AssertInsideChroot()
        Crossdev.Load(False)
        CreatePackages(targets_wanted, options.output_dir)
    else:
        cros_build_lib.AssertInsideChroot()
        # This has to be always run as root.
        if os.geteuid() != 0:
            cros_build_lib.Die('this script must be run as root')

        Crossdev.Load(options.reconfig)
        root = options.sysroot or '/'
        UpdateToolchains(options.usepkg,
                         options.deleteold,
                         options.hostonly,
                         options.reconfig,
                         targets_wanted,
                         boards_wanted,
                         root=root)
        Crossdev.Save()

    return 0
Exemplo n.º 5
0
def _CreateParser():
    """Create our custom parser."""
    parser = commandline.ArgumentParser(description=__doc__, caching=True)

    # TODO(rcui): Have this use the UI-V2 format of having source and target
    # device be specified as positional arguments.
    parser.add_argument(
        '--force',
        action='store_true',
        default=False,
        help='Skip all prompts (such as the prompt for disabling '
        'of rootfs verification).  This may result in the '
        'target machine being rebooted.')
    sdk_board_env = os.environ.get(cros_chrome_sdk.SDKFetcher.SDK_BOARD_ENV)
    parser.add_argument(
        '--board',
        default=sdk_board_env,
        help='The board the Chrome build is targeted for.  When '
        "in a 'cros chrome-sdk' shell, defaults to the SDK "
        'board.')
    parser.add_argument('--build-dir',
                        type='path',
                        help='The directory with Chrome build artifacts to '
                        'deploy from. Typically of format '
                        '<chrome_root>/out/Debug. When this option is used, '
                        'the GN_ARGS environment variable must be set.')
    parser.add_argument(
        '--target-dir',
        type='path',
        default=None,
        help='Target directory on device to deploy Chrome into.')
    parser.add_argument('-g',
                        '--gs-path',
                        type='gs_path',
                        help='GS path that contains the chrome to deploy.')
    parser.add_argument('--private-key',
                        type='path',
                        default=None,
                        help='An ssh private key to use when deploying to '
                        'a CrOS device.')
    parser.add_argument('--nostartui',
                        action='store_false',
                        dest='startui',
                        default=True,
                        help="Don't restart the ui daemon after deployment.")
    parser.add_argument(
        '--nostrip',
        action='store_false',
        dest='dostrip',
        default=True,
        help="Don't strip binaries during deployment.  Warning: "
        'the resulting binaries will be very large!')
    parser.add_argument('-p',
                        '--port',
                        type=int,
                        default=remote.DEFAULT_SSH_PORT,
                        help='This arg is deprecated. Please use --device '
                        'instead.')
    parser.add_argument('-t',
                        '--to',
                        deprecated='Use --device instead',
                        help='This arg is deprecated. Please use --device '
                        'instead.')
    parser.add_argument(
        '-d',
        '--device',
        type=commandline.DeviceParser(commandline.DEVICE_SCHEME_SSH),
        help='Device hostname or IP in the format hostname[:port].')
    parser.add_argument('--mount-dir',
                        type='path',
                        default=None,
                        help='Deploy Chrome in target directory and bind it '
                        'to the directory specified by this flag.'
                        'Any existing mount on this directory will be '
                        'umounted first.')
    parser.add_argument(
        '--mount',
        action='store_true',
        default=False,
        help='Deploy Chrome to default target directory and bind '
        'it to the default mount directory.'
        'Any existing mount on this directory will be '
        'umounted first.')
    parser.add_argument('--noremove-rootfs-verification',
                        action='store_true',
                        default=False,
                        help='Never remove rootfs verification.')
    parser.add_argument('--deploy-test-binaries',
                        action='store_true',
                        default=False,
                        help='Also deploy any test binaries to %s. Useful for '
                        'running any Tast tests that execute these '
                        'binaries.' % _CHROME_TEST_BIN_DIR)
    parser.add_argument('--lacros',
                        action='store_true',
                        default=False,
                        help='Deploys lacros-chrome rather than ash-chrome.')

    group = parser.add_argument_group('Advanced Options')
    group.add_argument('-l',
                       '--local-pkg-path',
                       type='path',
                       help='Path to local chrome prebuilt package to deploy.')
    group.add_argument('--sloppy',
                       action='store_true',
                       default=False,
                       help='Ignore when mandatory artifacts are missing.')
    group.add_argument(
        '--staging-flags',
        default=None,
        type=ValidateStagingFlags,
        help=('Extra flags to control staging.  Valid flags are - '
              '%s' % ', '.join(chrome_util.STAGING_FLAGS)))
    # TODO(stevenjb): Remove --strict entirely once removed from the ebuild.
    group.add_argument('--strict',
                       action='store_true',
                       default=False,
                       help='Deprecated. Default behavior is "strict". Use '
                       '--sloppy to omit warnings for missing optional '
                       'files.')
    group.add_argument('--strip-flags',
                       default=None,
                       help="Flags to call the 'strip' binutil tool with.  "
                       'Overrides the default arguments.')
    group.add_argument('--ping',
                       action='store_true',
                       default=False,
                       help='Ping the device before connection attempt.')
    group.add_argument('--process-timeout',
                       type=int,
                       default=KILL_PROC_MAX_WAIT,
                       help='Timeout for process shutdown.')

    group = parser.add_argument_group(
        'Metadata Overrides (Advanced)',
        description='Provide all of these overrides in order to remove '
        'dependencies on metadata.json existence.')
    group.add_argument('--target-tc',
                       action='store',
                       default=None,
                       help='Override target toolchain name, e.g. '
                       'x86_64-cros-linux-gnu')
    group.add_argument('--toolchain-url',
                       action='store',
                       default=None,
                       help='Override toolchain url format pattern, e.g. '
                       '2014/04/%%(target)s-2014.04.23.220740.tar.xz')

    # DEPRECATED: --gyp-defines is ignored, but retained for backwards
    # compatibility. TODO(stevenjb): Remove once eliminated from the ebuild.
    parser.add_argument('--gyp-defines',
                        default=None,
                        type=ValidateStagingFlags,
                        help=argparse.SUPPRESS)

    # GN_ARGS (args.gn) used to build Chrome. Influences which files are staged
    # when --build-dir is set. Defaults to reading from the GN_ARGS env variable.
    # CURRENLY IGNORED, ADDED FOR FORWARD COMPATABILITY.
    parser.add_argument('--gn-args',
                        default=None,
                        type=ValidateGnArgs,
                        help=argparse.SUPPRESS)

    # Path of an empty directory to stage chrome artifacts to.  Defaults to a
    # temporary directory that is removed when the script finishes. If the path
    # is specified, then it will not be removed.
    parser.add_argument('--staging-dir',
                        type='path',
                        default=None,
                        help=argparse.SUPPRESS)
    # Only prepare the staging directory, and skip deploying to the device.
    parser.add_argument('--staging-only',
                        action='store_true',
                        default=False,
                        help=argparse.SUPPRESS)
    # Path to a binutil 'strip' tool to strip binaries with.  The passed-in path
    # is used as-is, and not normalized.  Used by the Chrome ebuild to skip
    # fetching the SDK toolchain.
    parser.add_argument('--strip-bin', default=None, help=argparse.SUPPRESS)
    parser.add_argument('--compress',
                        action='store',
                        default='auto',
                        choices=('always', 'never', 'auto'),
                        help='Choose the data compression behavior. Default '
                        'is set to "auto", that disables compression if '
                        'the target device has a gigabit ethernet port.')
    return parser
Exemplo n.º 6
0
def main(argv):
    parser = commandline.ArgumentParser(description=__doc__)

    # The type of image_dir will strip off trailing slashes (makes later
    # processing simpler and the display prettier).
    parser.add_argument('image_dir',
                        default=None,
                        type='local_or_gs_path',
                        help='full path of source artifacts to upload')
    parser.add_argument('--board',
                        default=None,
                        required=True,
                        help='board to generate symbols for')
    parser.add_argument('--profile',
                        default=None,
                        help='board profile in use (e.g. "asan")')
    parser.add_argument(
        '--version',
        default=None,
        help='version info (normally extracted from image_dir)')
    parser.add_argument('-n',
                        '--dry-run',
                        default=False,
                        action='store_true',
                        help='show what would be done, but do not upload')
    parser.add_argument('-M',
                        '--mock',
                        default=False,
                        action='store_true',
                        help='upload things to a testing bucket (dev testing)')
    parser.add_argument('--test-sign',
                        default=[],
                        action='append',
                        choices=TEST_KEYSETS,
                        help='mung signing behavior to sign w/ test keys')
    parser.add_argument('--priority',
                        type=int,
                        default=50,
                        help='set signing priority (lower == higher prio)')
    parser.add_argument('--sign-types',
                        default=None,
                        nargs='+',
                        choices=_SUPPORTED_IMAGE_TYPES,
                        help='only sign specified image types')
    parser.add_argument('--yes',
                        action='store_true',
                        default=False,
                        help='answer yes to all prompts')

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

    force_keysets = set(
        ['%s-%s' % (TEST_KEYSET_PREFIX, x) for x in opts.test_sign])

    # If we aren't using mock or test or dry run mode, then let's prompt the user
    # to make sure they actually want to do this.  It's rare that people want to
    # run this directly and hit the release bucket.
    if not (opts.mock or force_keysets or opts.dry_run) and not opts.yes:
        prolog = '\n'.join(
            textwrap.wrap(
                textwrap.dedent(
                    'Uploading images for signing to the *release* bucket is not something '
                    'you generally should be doing yourself.'), 80)).strip()
        if not cros_build_lib.BooleanPrompt(
                prompt='Are you sure you want to sign these images',
                default=False,
                prolog=prolog):
            cros_build_lib.Die('better safe than sorry')

    PushImage(opts.image_dir,
              opts.board,
              versionrev=opts.version,
              profile=opts.profile,
              priority=opts.priority,
              sign_types=opts.sign_types,
              dry_run=opts.dry_run,
              mock=opts.mock,
              force_keysets=force_keysets)
Exemplo n.º 7
0
def ParseCmdline(argv):
    """Parse all command line options.

  Args:
    argv: Arguments to parse.

  Returns:
    The parsed options object
  """
    parser = commandline.ArgumentParser(description=__doc__)
    parser.add_argument('-a',
                        '--cbfargs',
                        action='append',
                        help='Pass extra arguments to cros_bundle_firmware')
    parser.add_argument('-b',
                        '--board',
                        type=str,
                        default=default_board,
                        help='Select board to build (daisy/peach_pit/link)')
    parser.add_argument('-B',
                        '--build',
                        action='store_false',
                        default=True,
                        help="Don't build U-Boot, just configure device tree")
    parser.add_argument('-C',
                        '--console',
                        action='store_false',
                        default=True,
                        help='Permit console output')
    parser.add_argument('-d',
                        '--dt',
                        default='seaboard',
                        help='Select name of device tree file to use')
    parser.add_argument(
        '-D',
        '--nodefaults',
        dest='use_defaults',
        action='store_false',
        default=True,
        help="Don't select default filenames for those not given")
    parser.add_argument('-F',
                        '--flash',
                        action='store_true',
                        default=False,
                        help='Create magic flasher for SPI flash')
    parser.add_argument('-M',
                        '--mmc',
                        action='store_true',
                        default=False,
                        help='Create magic flasher for eMMC')
    parser.add_argument('-i',
                        '--incremental',
                        action='store_true',
                        default=False,
                        help="Don't reconfigure and clean")
    parser.add_argument('-k',
                        '--kernel',
                        action='store_true',
                        default=False,
                        help='Send kernel to board also')
    parser.add_argument('-O',
                        '--objdump',
                        action='store_true',
                        default=False,
                        help='Write disassembly output')
    parser.add_argument('-r',
                        '--run',
                        action='store_false',
                        default=True,
                        help='Run the boot command')
    parser.add_argument('--ro',
                        action='store_true',
                        default=False,
                        help='Create Chrome OS read-only image')
    parser.add_argument('--rw',
                        action='store_true',
                        default=False,
                        help='Create Chrome OS read-write image')
    parser.add_argument(
        '-s',
        '--separate',
        action='store_false',
        default=True,
        help='Link device tree into U-Boot, instead of separate')
    parser.add_argument('-S',
                        '--secure',
                        action='store_true',
                        default=False,
                        help='Use vboot_twostop secure boot')
    parser.add_argument('--small',
                        action='store_true',
                        default=False,
                        help='Create Chrome OS small image')
    parser.add_argument('-t',
                        '--trace',
                        action='store_true',
                        default=False,
                        help='Enable trace support')
    parser.add_argument('-v',
                        '--verbose',
                        type=int,
                        default=0,
                        help='Make cros_bundle_firmware verbose')
    parser.add_argument('-V',
                        '--verified',
                        action='store_true',
                        default=False,
                        help='Include Chrome OS verified boot components')
    parser.add_argument('-w',
                        '--write',
                        action='store_false',
                        default=True,
                        help="Don't write image to board using usb/em100")
    parser.add_argument('-x',
                        '--sdcard',
                        action='store_true',
                        default=False,
                        help='Write to SD card instead of USB/em100')
    parser.add_argument('-z',
                        '--size',
                        action='store_true',
                        default=False,
                        help='Display U-Boot image size')
    parser.add_argument('target',
                        nargs='?',
                        default='all',
                        help='The target to work on')
    return parser.parse_args(argv)
Exemplo n.º 8
0
def ParallelEmergeArgParser():
  """Helper function to create command line argument parser for this wrapper.

  We need to be compatible with emerge arg format.  We scrape arguments that
  are specific to parallel_emerge, and pass through the rest directly to
  emerge.

  Returns:
    commandline.ArgumentParser that captures arguments specific to
    parallel_emerge
  """
  parser = commandline.ArgumentParser()

  board_group = parser.add_mutually_exclusive_group()
  board_group.add_argument(
      '--board',
      default=None,
      action=LookupBoardSysroot,
  )
  board_group.add_argument(
      '--sysroot',
      action='store',
      metavar='PATH',
  )

  parser.add_argument(
      '--root',
      action='store',
      metavar='PATH',
  )
  parser.add_argument(
      '--workon',
      action='append',
      metavar='PKGS',
  )
  parser.add_argument(
      '--rebuild',
      action='store_true',
      default=False,
  )
  parser.add_argument(
      '--force-remote-binary',
      action='append',
      help=argparse.SUPPRESS,
  )
  parser.add_argument(
      '--root-deps',
      action='store',
      nargs='?',
      default=None,
      dest='root_deps',
      help=argparse.SUPPRESS,
  )
  parser.add_argument(
      '-j',
      '--jobs',
      default=multiprocessing.cpu_count(),
      metavar='PARALLEL_JOBCOUNT',
  )

  parser.add_argument(
      '--retries',
      help=argparse.SUPPRESS,
      deprecated='Build retries are no longer supported.',
  )
  parser.add_argument(
      '--eventlogfile',
      help=argparse.SUPPRESS,
      deprecated=
      'parallel_emerge no longer records failed packages. Set CROS_METRICS_DIR '
      'in the system environment to get a log of failed packages and which '
      'phase they failed in.',
  )
  parser.add_argument(
      '--show-output',
      action='store_true',
      help=argparse.SUPPRESS,
      deprecated='This option is no longer supported.',
  )

  return parser
Exemplo n.º 9
0
 def testDefaultLogLevel(self):
   """Test that the default log level is set to notice."""
   arg_parser = self.PatchObject(commandline, 'ArgumentParser',
                                 return_value=commandline.ArgumentParser())
   cros.GetOptions({})
   arg_parser.assert_called_with(caching=True, default_log_level='notice')
Exemplo n.º 10
0
 def _ParseCommandLine(argv):
   parser = commandline.ArgumentParser()
   parser.add_argument('-g', '--gs-path', type='gs_path',
                       help='GS path that contains the chrome to deploy.')
   return parser.parse_args(argv)
Exemplo n.º 11
0
 def _ParseCommandLine(argv):
   parser = commandline.ArgumentParser()
   parser.add_argument('-e', '--enable', type='bool',
                       help='Boolean Argument.')
   return parser.parse_args(argv)
Exemplo n.º 12
0
def main(argv):
    """Checks if a project is correctly formatted with clang-format.

  Returns 1 if there are any clang-format-worthy changes in the project (or
  on a provided list of files/directories in the project), 0 otherwise.
  """

    parser = commandline.ArgumentParser(description=__doc__)
    parser.add_argument('--clang-format',
                        default=_GetDefaultClangFormatPath(),
                        help='The path of the clang-format executable.')
    parser.add_argument('--git-clang-format',
                        default=os.path.join(BUILDTOOLS_PATH, 'clang_format',
                                             'script', 'git-clang-format'),
                        help='The path of the git-clang-format executable.')
    parser.add_argument('--style',
                        metavar='STYLE',
                        type=str,
                        default='file',
                        help='The style that clang-format will use.')
    parser.add_argument('--extensions',
                        metavar='EXTENSIONS',
                        type=str,
                        help='Comma-separated list of file extensions to '
                        'format.')
    parser.add_argument('--fix',
                        action='store_true',
                        help='Fix any formatting errors automatically.')

    scope = parser.add_mutually_exclusive_group(required=True)
    scope.add_argument('--commit',
                       type=str,
                       default='HEAD',
                       help='Specify the commit to validate.')
    scope.add_argument('--working-tree',
                       action='store_true',
                       help='Validates the files that have changed from '
                       'HEAD in the working directory.')

    parser.add_argument('files',
                        type=str,
                        nargs='*',
                        help='If specified, only consider differences in '
                        'these files/directories.')

    opts = parser.parse_args(argv)

    cmd = [opts.git_clang_format, '--binary', opts.clang_format, '--diff']
    if opts.style:
        cmd.extend(['--style', opts.style])
    if opts.extensions:
        cmd.extend(['--extensions', opts.extensions])
    if not opts.working_tree:
        cmd.extend(['%s^' % opts.commit, opts.commit])
    cmd.extend(['--'] + opts.files)

    # Fail gracefully if clang-format itself aborts/fails.
    try:
        result = cros_build_lib.RunCommand(cmd=cmd,
                                           print_cmd=False,
                                           stdout_to_pipe=True)
    except cros_build_lib.RunCommandError as e:
        print('clang-format failed:\n' + str(e), file=sys.stderr)
        print('\nPlease report this to the clang team.', file=sys.stderr)
        return 1

    stdout = result.output
    if stdout.rstrip('\n') == 'no modified files to format':
        # This is always printed when only files that clang-format does not
        # understand were modified.
        return 0

    diff_filenames = []
    for line in stdout.splitlines():
        if line.startswith(DIFF_MARKER_PREFIX):
            diff_filenames.append(line[len(DIFF_MARKER_PREFIX):].rstrip())

    if diff_filenames:
        if opts.fix:
            cros_build_lib.RunCommand(cmd=['git', 'apply'],
                                      print_cmd=False,
                                      input=stdout)
        else:
            print('The following files have formatting errors:')
            for filename in diff_filenames:
                print('\t%s' % filename)
            print('You can run `%s --fix %s` to fix this' %
                  (sys.argv[0], ' '.join(
                      cros_build_lib.ShellQuote(arg) for arg in argv)))
            return 1
Exemplo n.º 13
0
def GetParser():
    """Creates the argparse parser."""
    class uint32(int):
        """Unsigned 32-bit int."""
        def __new__(cls, val):
            """Return a positive 32-bit value."""
            return int(val, 0) & 0xffffffff

    class Dev01Action(argparse.Action):
        """Convert --dev01 MMM NNN into an %08x-%08x device_id."""
        def __call__(self, parser, namespace, values, option_string=None):
            if not namespace.dev_ids:
                namespace.dev_ids = []
            namespace.dev_ids.append('%08x-%08x' % (values[0], values[1]))

    parser = commandline.ArgumentParser(description=__doc__,
                                        default_log_level='debug')

    parser.add_argument('--staging',
                        action='store_true',
                        dest='staging',
                        help='Use the staging instance to create the request.')

    parser.add_argument('--build-target',
                        default='unknown',
                        help='The build target.')

    parser.add_argument('--channel',
                        choices=_channels,
                        default='unspecified',
                        help='The (optional) channel for the artifact.')

    parser.add_argument('--archive',
                        required=True,
                        help='The gs://path of the archive to sign.')

    parser.add_argument('--dry-run',
                        action='store_true',
                        default=False,
                        help='This is a dryrun, nothing will be triggered.')

    parser.add_argument('--keyset',
                        default='cr50-accessory-mp',
                        help='The keyset to use.')

    parser.add_argument('--image-type',
                        choices=_image_types,
                        default='cr50_firmware',
                        help='The image type.')

    parser.add_argument('--signer-type',
                        choices=_signer_types,
                        default='production',
                        help='The image type.')

    parser.add_argument('--target',
                        choices=_target_types,
                        default='prepvt',
                        help='The image type.')

    node_locked = parser.add_argument_group(
        'Node_locked',
        description='Additional arguments for --target=node_locked')

    node_locked.add_argument('--device-id',
                             action='append',
                             dest='dev_ids',
                             help='The device_id ("%%08x-%%08x" format).')

    node_locked.add_argument('--dev01',
                             nargs=2,
                             type=uint32,
                             action=Dev01Action,
                             metavar='DEVx',
                             dest='dev_ids',
                             help='DEV0 and DEV1 for the device')

    return parser
Exemplo n.º 14
0
def main(argv):
    parser = commandline.ArgumentParser(description=__doc__)

    parser.add_argument('sym_paths',
                        type='path_or_uri',
                        nargs='*',
                        default=None,
                        help='symbol file or directory or URL or tarball')
    parser.add_argument('--board',
                        default=None,
                        help='Used to find default breakpad_root.')
    parser.add_argument('--breakpad_root',
                        type='path',
                        default=None,
                        help='full path to the breakpad symbol directory')
    parser.add_argument('--root',
                        type='path',
                        default=None,
                        help='full path to the chroot dir')
    parser.add_argument('--official_build',
                        action='store_true',
                        default=False,
                        help='point to official symbol server')
    parser.add_argument('--server',
                        type=str,
                        default=None,
                        help='URI for custom symbol server')
    parser.add_argument('--regenerate',
                        action='store_true',
                        default=False,
                        help='regenerate all symbols')
    parser.add_argument('--upload-limit',
                        type=int,
                        default=None,
                        help='only upload # number of symbols')
    parser.add_argument('--strip_cfi',
                        type=int,
                        default=CRASH_SERVER_FILE_LIMIT - (10 * 1024 * 1024),
                        help='strip CFI data for files above this size')
    parser.add_argument('--failed-list',
                        type='path',
                        help='where to save a list of failed symbols')
    parser.add_argument('--dedupe',
                        action='store_true',
                        default=False,
                        help='use the swarming service to avoid re-uploading')
    parser.add_argument('--testing',
                        action='store_true',
                        default=False,
                        help='run in testing mode')
    parser.add_argument('--yes',
                        action='store_true',
                        default=False,
                        help='answer yes to all prompts')
    parser.add_argument('--product_name',
                        type=str,
                        default='ChromeOS',
                        help='Produce Name for breakpad stats.')

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

    if opts.sym_paths or opts.breakpad_root:
        if opts.regenerate:
            cros_build_lib.Die(
                '--regenerate may not be used with specific files, '
                'or breakpad_root')
    else:
        if opts.board is None:
            cros_build_lib.Die('--board is required')

    if opts.testing:
        # TODO(build): Kill off --testing mode once unittests are up-to-snuff.
        logging.info('running in testing mode')
        # pylint: disable=W0601,W0603
        global INITIAL_RETRY_DELAY, SymUpload, DEFAULT_SLEEP_DELAY
        INITIAL_RETRY_DELAY = DEFAULT_SLEEP_DELAY = 0
        SymUpload = TestingSymUpload

    dedupe_namespace = None
    if opts.dedupe:
        if opts.official_build and not opts.testing:
            dedupe_namespace = OFFICIAL_DEDUPE_NAMESPACE_TMPL % opts.product_name
        else:
            dedupe_namespace = STAGING_DEDUPE_NAMESPACE_TMPL % opts.product_name

    if not opts.yes:
        prolog = '\n'.join(
            textwrap.wrap(
                textwrap.dedent("""
        Uploading symbols for an entire Chromium OS build is really only
        necessary for release builds and in a few cases for developers
        to debug problems.  It will take considerable time to run.  For
        developer debugging purposes, consider instead passing specific
        files to upload.
    """), 80)).strip()
        if not cros_build_lib.BooleanPrompt(
                prompt='Are you sure you want to upload all build symbols',
                default=False,
                prolog=prolog):
            cros_build_lib.Die('better safe than sorry')

    ret = 0
    if opts.regenerate:
        ret += cros_generate_breakpad_symbols.GenerateBreakpadSymbols(
            opts.board, breakpad_dir=opts.breakpad_root)

    ret += UploadSymbols(opts.board,
                         official=opts.official_build,
                         server=opts.server,
                         breakpad_dir=opts.breakpad_root,
                         file_limit=opts.strip_cfi,
                         sleep=DEFAULT_SLEEP_DELAY,
                         upload_limit=opts.upload_limit,
                         sym_paths=opts.sym_paths,
                         failed_list=opts.failed_list,
                         root=opts.root,
                         dedupe_namespace=dedupe_namespace,
                         product_name=opts.product_name)
    if ret:
        logging.error('encountered %i problem(s)', ret)
        # Since exit(status) gets masked, clamp it to 1 so we don't inadvertently
        # return 0 in case we are a multiple of the mask.
        ret = 1

    return ret
Exemplo n.º 15
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
Exemplo n.º 16
0
def _CreateParser(sdk_latest_version, bootstrap_latest_version):
    """Generate and return the parser with all the options."""
    usage = ('usage: %(prog)s [options] '
             '[VAR1=val1 ... VAR2=val2] [--] [command [args]]')
    parser = commandline.ArgumentParser(usage=usage,
                                        description=__doc__,
                                        caching=True)

    # Global options.
    default_chroot = os.path.join(constants.SOURCE_ROOT,
                                  constants.DEFAULT_CHROOT_DIR)
    parser.add_argument('--chroot',
                        dest='chroot',
                        default=default_chroot,
                        type='path',
                        help=('SDK chroot dir name [%s]' %
                              constants.DEFAULT_CHROOT_DIR))
    parser.add_argument('--nouse-image',
                        dest='use_image',
                        action='store_false',
                        default=True,
                        help='Do not mount the chroot on a loopback image; '
                        'instead, create it directly in a directory.')

    parser.add_argument('--chrome-root',
                        '--chrome_root',
                        type='path',
                        help='Mount this chrome root into the SDK chroot')
    parser.add_argument('--chrome_root_mount',
                        type='path',
                        help='Mount chrome into this path inside SDK chroot')
    parser.add_argument(
        '--nousepkg',
        action='store_true',
        default=False,
        help='Do not use binary packages when creating a chroot.')
    parser.add_argument(
        '-u',
        '--url',
        dest='sdk_url',
        help='Use sdk tarball located at this url. Use file:// '
        'for local files.')
    parser.add_argument(
        '--sdk-version',
        help=('Use this sdk version.  For prebuilt, current is %r'
              ', for bootstrapping it is %r.' %
              (sdk_latest_version, bootstrap_latest_version)))
    parser.add_argument(
        '--goma_dir',
        type='path',
        help='Goma installed directory to mount into the chroot.')
    parser.add_argument('--goma_client_json',
                        type='path',
                        help='Service account json file to use goma on bot. '
                        'Mounted into the chroot.')

    # Use type=str instead of type='path' to prevent the given path from being
    # transfered to absolute path automatically.
    parser.add_argument(
        '--working-dir',
        type=str,
        help='Run the command in specific working directory in '
        'chroot.  If the given directory is a relative '
        'path, this program will transfer the path to '
        'the corresponding one inside chroot.')

    parser.add_argument('commands', nargs=argparse.REMAINDER)

    # Commands.
    group = parser.add_argument_group('Commands')
    group.add_argument('--enter',
                       action='store_true',
                       default=False,
                       help='Enter the SDK chroot.  Implies --create.')
    group.add_argument(
        '--create',
        action='store_true',
        default=False,
        help='Create the chroot only if it does not already exist.  '
        'Implies --download.')
    group.add_argument(
        '--bootstrap',
        action='store_true',
        default=False,
        help='Build everything from scratch, including the sdk.  '
        'Use this only if you need to validate a change '
        'that affects SDK creation itself (toolchain and '
        'build are typically the only folk who need this).  '
        'Note this will quite heavily slow down the build.  '
        'This option implies --create --nousepkg.')
    group.add_argument(
        '-r',
        '--replace',
        action='store_true',
        default=False,
        help='Replace an existing SDK chroot.  Basically an alias '
        'for --delete --create.')
    group.add_argument('--delete',
                       action='store_true',
                       default=False,
                       help='Delete the current SDK chroot if it exists.')
    group.add_argument(
        '--force',
        action='store_true',
        default=False,
        help='Force unmount/delete of the current SDK chroot even if '
        'obtaining the write lock fails.')
    group.add_argument(
        '--unmount',
        action='store_true',
        default=False,
        help='Unmount and clean up devices associated with the '
        'SDK chroot if it exists.  This does not delete the '
        'backing image file, so the same chroot can be later '
        're-mounted for reuse.  To fully delete the chroot, use '
        '--delete.  This is primarily useful for working on '
        'cros_sdk or the chroot setup; you should not need it '
        'under normal circumstances.')
    group.add_argument('--download',
                       action='store_true',
                       default=False,
                       help='Download the sdk.')
    group.add_argument(
        '--snapshot-create',
        metavar='SNAPSHOT_NAME',
        help='Create a snapshot of the chroot.  Requires that the chroot was '
        'created without the --nouse-image option.')
    group.add_argument(
        '--snapshot-restore',
        metavar='SNAPSHOT_NAME',
        help='Restore the chroot to a previously created snapshot.')
    group.add_argument(
        '--snapshot-delete',
        metavar='SNAPSHOT_NAME',
        help='Delete a previously created snapshot.  Deleting a snapshot that '
        'does not exist is not an error.')
    group.add_argument('--snapshot-list',
                       action='store_true',
                       default=False,
                       help='List existing snapshots of the chroot and exit.')
    commands = group

    # Namespace options.
    group = parser.add_argument_group('Namespaces')
    group.add_argument(
        '--proxy-sim',
        action='store_true',
        default=False,
        help='Simulate a restrictive network requiring an outbound'
        ' proxy.')
    group.add_argument('--no-ns-pid',
                       dest='ns_pid',
                       default=True,
                       action='store_false',
                       help='Do not create a new PID namespace.')

    # Internal options.
    group = parser.add_argument_group(
        'Internal Chromium OS Build Team Options',
        'Caution: these are for meant for the Chromium OS build team only')
    group.add_argument('--buildbot-log-version',
                       default=False,
                       action='store_true',
                       help='Log SDK version for buildbot consumption')

    return parser, commands
def _ParseArguments(argv):
    parser = commandline.ArgumentParser(description=__doc__)

    opts = parser.parse_args(argv)
    opts.Freeze()
    return opts
Exemplo n.º 18
0
def _CreateParser(sdk_latest_version, bootstrap_latest_version):
    """Generate and return the parser with all the options."""
    usage = ('usage: %(prog)s [options] '
             '[VAR1=val1 ... VAR2=val2] [--] [command [args]]')
    parser = commandline.ArgumentParser(usage=usage,
                                        description=__doc__,
                                        caching=True)

    # Global options.
    default_chroot = os.path.join(constants.SOURCE_ROOT,
                                  constants.DEFAULT_CHROOT_DIR)
    parser.add_argument('--chroot',
                        dest='chroot',
                        default=default_chroot,
                        type='path',
                        help=('SDK chroot dir name [%s]' %
                              constants.DEFAULT_CHROOT_DIR))

    parser.add_argument('--chrome_root',
                        type='path',
                        help='Mount this chrome root into the SDK chroot')
    parser.add_argument('--chrome_root_mount',
                        type='path',
                        help='Mount chrome into this path inside SDK chroot')
    parser.add_argument(
        '--nousepkg',
        action='store_true',
        default=False,
        help='Do not use binary packages when creating a chroot.')
    parser.add_argument(
        '-u',
        '--url',
        dest='sdk_url',
        help='Use sdk tarball located at this url. Use file:// '
        'for local files.')
    parser.add_argument(
        '--sdk-version',
        help=('Use this sdk version.  For prebuilt, current is %r'
              ', for bootstrapping it is %r.' %
              (sdk_latest_version, bootstrap_latest_version)))
    parser.add_argument('--workspace',
                        help='Workspace directory to mount into the chroot.')
    parser.add_argument('commands', nargs=argparse.REMAINDER)

    # SDK overlay tarball options (mutually exclusive).
    group = parser.add_mutually_exclusive_group()
    group.add_argument(
        '--toolchains',
        help=('Comma-separated list of toolchains we expect to be '
              'using on the chroot. Used for downloading a '
              'corresponding SDK toolchains group (if one is '
              'found), which may speed up chroot initialization '
              'when building for the first time. Otherwise this '
              'has no effect and will not restrict the chroot in '
              'any way. Ignored if using --bootstrap.'))
    group.add_argument(
        '--board',
        help=('The board we intend to be building in the chroot. '
              'Used for deriving the list of required toolchains '
              '(see --toolchains).'))

    # Commands.
    group = parser.add_argument_group('Commands')
    group.add_argument('--enter',
                       action='store_true',
                       default=False,
                       help='Enter the SDK chroot.  Implies --create.')
    group.add_argument(
        '--create',
        action='store_true',
        default=False,
        help='Create the chroot only if it does not already exist.  '
        'Implies --download.')
    group.add_argument(
        '--bootstrap',
        action='store_true',
        default=False,
        help='Build everything from scratch, including the sdk.  '
        'Use this only if you need to validate a change '
        'that affects SDK creation itself (toolchain and '
        'build are typically the only folk who need this).  '
        'Note this will quite heavily slow down the build.  '
        'This option implies --create --nousepkg.')
    group.add_argument(
        '-r',
        '--replace',
        action='store_true',
        default=False,
        help='Replace an existing SDK chroot.  Basically an alias '
        'for --delete --create.')
    group.add_argument('--delete',
                       action='store_true',
                       default=False,
                       help='Delete the current SDK chroot if it exists.')
    group.add_argument('--download',
                       action='store_true',
                       default=False,
                       help='Download the sdk.')
    commands = group

    # Namespace options.
    group = parser.add_argument_group('Namespaces')
    group.add_argument(
        '--proxy-sim',
        action='store_true',
        default=False,
        help='Simulate a restrictive network requiring an outbound'
        ' proxy.')
    group.add_argument('--no-ns-pid',
                       dest='ns_pid',
                       default=True,
                       action='store_false',
                       help='Do not create a new PID namespace.')

    # Internal options.
    group = parser.add_argument_group(
        'Internal Chromium OS Build Team Options',
        'Caution: these are for meant for the Chromium OS build team only')
    group.add_argument('--buildbot-log-version',
                       default=False,
                       action='store_true',
                       help='Log SDK version for buildbot consumption')

    return parser, commands
Exemplo n.º 19
0
def GetParser():
    return commandline.ArgumentParser(description=__doc__)
Exemplo n.º 20
0
def _CreateParser():
    """Create our custom parser."""
    parser = commandline.ArgumentParser(description=__doc__, caching=True)

    # TODO(rcui): Have this use the UI-V2 format of having source and target
    # device be specified as positional arguments.
    parser.add_argument('--force',
                        action='store_true',
                        default=False,
                        help='Skip all prompts (i.e., for disabling of rootfs '
                        'verification).  This may result in the target '
                        'machine being rebooted.')
    sdk_board_env = os.environ.get(cros_chrome_sdk.SDKFetcher.SDK_BOARD_ENV)
    parser.add_argument(
        '--board',
        default=sdk_board_env,
        help="The board the Chrome build is targeted for.  When "
        "in a 'cros chrome-sdk' shell, defaults to the SDK "
        "board.")
    parser.add_argument('--build-dir',
                        type='path',
                        help='The directory with Chrome build artifacts to '
                        'deploy from. Typically of format '
                        '<chrome_root>/out/Debug. When this option is used, '
                        'the GN_ARGS environment variable must be set.')
    parser.add_argument(
        '--target-dir',
        type='path',
        default=None,
        help='Target directory on device to deploy Chrome into.')
    parser.add_argument('-g',
                        '--gs-path',
                        type='gs_path',
                        help='GS path that contains the chrome to deploy.')
    parser.add_argument('--nostartui',
                        action='store_false',
                        dest='startui',
                        default=True,
                        help="Don't restart the ui daemon after deployment.")
    parser.add_argument(
        '--nostrip',
        action='store_false',
        dest='dostrip',
        default=True,
        help="Don't strip binaries during deployment.  Warning: "
        'the resulting binaries will be very large!')
    parser.add_argument('-p',
                        '--port',
                        type=int,
                        default=remote.DEFAULT_SSH_PORT,
                        help='Port of the target device to connect to.')
    parser.add_argument('-t',
                        '--to',
                        help='The IP address of the CrOS device to deploy to.')
    parser.add_argument('-v',
                        '--verbose',
                        action='store_true',
                        default=False,
                        help='Show more debug output.')
    parser.add_argument('--mount-dir',
                        type='path',
                        default=None,
                        help='Deploy Chrome in target directory and bind it '
                        'to the directory specified by this flag.'
                        'Any existing mount on this directory will be '
                        'umounted first.')
    parser.add_argument(
        '--mount',
        action='store_true',
        default=False,
        help='Deploy Chrome to default target directory and bind '
        'it to the default mount directory.'
        'Any existing mount on this directory will be '
        'umounted first.')

    group = parser.add_argument_group('Advanced Options')
    group.add_argument('-l',
                       '--local-pkg-path',
                       type='path',
                       help='Path to local chrome prebuilt package to deploy.')
    group.add_argument('--sloppy',
                       action='store_true',
                       default=False,
                       help='Ignore when mandatory artifacts are missing.')
    group.add_argument(
        '--staging-flags',
        default=None,
        type=ValidateStagingFlags,
        help=('Extra flags to control staging.  Valid flags are - '
              '%s' % ', '.join(chrome_util.STAGING_FLAGS)))
    # TODO(stevenjb): Remove --strict entirely once removed from the ebuild.
    group.add_argument('--strict',
                       action='store_true',
                       default=False,
                       help='Deprecated. Default behavior is "strict". Use '
                       '--sloppy to omit warnings for missing optional '
                       'files.')
    group.add_argument('--strip-flags',
                       default=None,
                       help="Flags to call the 'strip' binutil tool with.  "
                       "Overrides the default arguments.")
    group.add_argument('--ping',
                       action='store_true',
                       default=False,
                       help='Ping the device before connection attempt.')
    group.add_argument(
        '--mash',
        action='store_true',
        default=False,
        help='Copy additional files for mus+ash. Will not fit in '
        'the default target-dir.')

    group = parser.add_argument_group(
        'Metadata Overrides (Advanced)',
        description='Provide all of these overrides in order to remove '
        'dependencies on metadata.json existence.')
    group.add_argument('--target-tc',
                       action='store',
                       default=None,
                       help='Override target toolchain name, e.g. '
                       'x86_64-cros-linux-gnu')
    group.add_argument('--toolchain-url',
                       action='store',
                       default=None,
                       help='Override toolchain url format pattern, e.g. '
                       '2014/04/%%(target)s-2014.04.23.220740.tar.xz')

    # DEPRECATED: --gyp-defines is ignored, but retained for backwards
    # compatibility. TODO(stevenjb): Remove once eliminated from the ebuild.
    parser.add_argument('--gyp-defines',
                        default=None,
                        type=ValidateStagingFlags,
                        help=argparse.SUPPRESS)

    # GN_ARGS (args.gn) used to build Chrome. Influences which files are staged
    # when --build-dir is set. Defaults to reading from the GN_ARGS env variable.
    # CURRENLY IGNORED, ADDED FOR FORWARD COMPATABILITY.
    parser.add_argument('--gn-args',
                        default=None,
                        type=ValidateGnArgs,
                        help=argparse.SUPPRESS)

    # Path of an empty directory to stage chrome artifacts to.  Defaults to a
    # temporary directory that is removed when the script finishes. If the path
    # is specified, then it will not be removed.
    parser.add_argument('--staging-dir',
                        type='path',
                        default=None,
                        help=argparse.SUPPRESS)
    # Only prepare the staging directory, and skip deploying to the device.
    parser.add_argument('--staging-only',
                        action='store_true',
                        default=False,
                        help=argparse.SUPPRESS)
    # Path to a binutil 'strip' tool to strip binaries with.  The passed-in path
    # is used as-is, and not normalized.  Used by the Chrome ebuild to skip
    # fetching the SDK toolchain.
    parser.add_argument('--strip-bin', default=None, help=argparse.SUPPRESS)
    return parser
Exemplo n.º 21
0
def main(argv):

    parser = commandline.ArgumentParser(description=__doc__)

    parser.add_argument('--board', default=None, help='board to debug for')
    parser.add_argument(
        '-g',
        '--gdb_args',
        action='append',
        default=[],
        help='Arguments to gdb itself.  If multiple arguments are'
        ' passed, each argument needs a separate \'-g\' flag.')
    parser.add_argument(
        '--remote',
        default=None,
        type=commandline.DeviceParser(commandline.DEVICE_SCHEME_SSH),
        help='Remote device on which to run the binary. Use'
        ' "--remote=localhost:9222" to debug in a ChromeOS image in an'
        ' already running local virtual machine.')
    parser.add_argument(
        '--pid',
        default='',
        help='Process ID of the (already) running process on the'
        ' remote device to which to attach.')
    parser.add_argument('--remote_pid',
                        dest='pid',
                        default='',
                        help='Deprecated alias for --pid.')
    parser.add_argument(
        '--no-ping',
        dest='ping',
        default=True,
        action='store_false',
        help='Do not ping remote before attempting to connect.')
    parser.add_argument('--attach',
                        dest='attach_name',
                        default='',
                        help='Name of existing process to which to attach, on'
                        ' remote device (remote debugging only). "--attach'
                        ' browser" will find the main chrome browser process;'
                        ' "--attach renderer" will find a chrome renderer'
                        ' process; "--attach gpu-process" will find the chrome'
                        ' gpu process.')
    parser.add_argument('--cgdb',
                        default=False,
                        action='store_true',
                        help='Use cgdb curses interface rather than plain gdb.'
                        'This option is only valid for remote debugging.')
    parser.add_argument(
        'inf_args',
        nargs=argparse.REMAINDER,
        help='Arguments for gdb to pass to the program being'
        ' debugged. These are positional and must come at the end'
        ' of the command line.  This will not work if attaching'
        ' to an already running program.')

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

    gdb_args = []
    inf_args = []
    inf_cmd = ''

    if options.inf_args:
        inf_cmd = options.inf_args[0]
        inf_args = options.inf_args[1:]

    if options.gdb_args:
        gdb_args = options.gdb_args

    if inf_cmd:
        fname = os.path.join(cros_build_lib.GetSysroot(options.board),
                             inf_cmd.lstrip('/'))
        if not os.path.exists(fname):
            cros_build_lib.Die('Cannot find program %s.' % fname)
    else:
        if inf_args:
            parser.error('Cannot specify arguments without a program.')

    if inf_args and (options.pid or options.attach_name):
        parser.error('Cannot pass arguments to an already'
                     ' running process (--remote-pid or --attach).')

    if options.remote:
        if not options.pid and not inf_cmd and not options.attach_name:
            parser.error('Must specify a program to start or a pid to attach '
                         'to on the remote device.')
        if options.attach_name and options.attach_name == 'browser':
            inf_cmd = '/opt/google/chrome/chrome'
    else:
        if options.cgdb:
            parser.error(
                '--cgdb option can only be used with remote debugging.')
        if options.pid:
            parser.error('Must specify a remote device (--remote) if you want '
                         'to attach to a remote pid.')
        if options.attach_name:
            parser.error('Must specify remote device (--remote) when using'
                         ' --attach option.')

    # Once we've finished sanity checking args, make sure we're root.
    if not options.remote:
        _ReExecuteIfNeeded([sys.argv[0]] + argv)

    gdb = BoardSpecificGdb(options.board, gdb_args, inf_cmd, inf_args,
                           options.remote, options.pid, options.attach_name,
                           options.cgdb, options.ping)

    try:
        if options.remote:
            gdb.RunRemote()
        else:
            gdb.Run()

    except GdbException as e:
        if options.debug:
            raise
        else:
            raise cros_build_lib.Die(str(e))
Exemplo n.º 22
0
def ParseOptions(argv):
    """Returns options given by the user and the target specified.

  Args:
    argv: The args to parse.

  Returns:
    A tuple containing a parsed options object and BuildTarget.
    The target instance is None if no board is specified.
  """
    parser = commandline.ArgumentParser()
    parser.add_argument(
        '-H',
        '--binhost-base-url',
        default=_BINHOST_BASE_URL,
        help='Base URL to use for binhost in make.conf updates')
    parser.add_argument('--previous-binhost-url',
                        action='append',
                        default=[],
                        help='Previous binhost URL')
    parser.add_argument('-b',
                        '--board',
                        help='Board type that was built on this machine')
    parser.add_argument('-B',
                        '--prepackaged-tarball',
                        type='path',
                        help='Board tarball prebuilt outside of this script.')
    parser.add_argument('--toolchains-overlay-tarball',
                        dest='toolchains_overlay_tarballs',
                        action='append',
                        default=[],
                        help='Toolchains overlay tarball specification to '
                        'upload. Takes the form '
                        '"toolchains_spec:/path/to/tarball".')
    parser.add_argument(
        '--toolchains-overlay-upload-path',
        default='',
        help='Path template for uploading toolchains overlays.')
    parser.add_argument('--toolchain-tarball',
                        dest='toolchain_tarballs',
                        action='append',
                        default=[],
                        help='Redistributable toolchain tarball.')
    parser.add_argument(
        '--toolchain-upload-path',
        default='',
        help='Path to place toolchain tarballs in the sdk tree.')
    parser.add_argument('--profile',
                        help='Profile that was built on this machine')
    parser.add_argument(
        '--slave-board',
        default=[],
        action=_AddSlaveBoardAction,
        dest='slave_targets',
        help='Board type that was built on a slave machine. To '
        'add a profile to this board, use --slave-profile.')
    parser.add_argument(
        '--slave-profile',
        action=_AddSlaveProfileAction,
        help='Board profile that was built on a slave machine. '
        'Applies to previous slave board.')
    parser.add_argument('-p',
                        '--build-path',
                        required=True,
                        help='Path to the directory containing the chroot')
    parser.add_argument('--packages',
                        action='append',
                        default=[],
                        help='Only include the specified packages. '
                        '(Default is to include all packages.)')
    parser.add_argument('-s',
                        '--sync-host',
                        default=False,
                        action='store_true',
                        help='Sync host prebuilts')
    parser.add_argument(
        '-g',
        '--git-sync',
        default=False,
        action='store_true',
        help='Enable git version sync (This commits to a repo.) '
        'This is used by full builders to commit directly '
        'to board overlays.')
    parser.add_argument('-u', '--upload', help='Upload location')
    parser.add_argument('-V',
                        '--prepend-version',
                        help='Add an identifier to the front of the version')
    parser.add_argument('-f',
                        '--filters',
                        action='store_true',
                        default=False,
                        help='Turn on filtering of private ebuild packages')
    parser.add_argument('-k',
                        '--key',
                        default='PORTAGE_BINHOST',
                        help='Key to update in make.conf / binhost.conf')
    parser.add_argument('--set-version', help='Specify the version string')
    parser.add_argument('--sync-binhost-conf',
                        default=False,
                        action='store_true',
                        help='Update binhost.conf in chromiumos-overlay or '
                        'chromeos-overlay. Commit the changes, but don\'t '
                        'push them. This is used for preflight binhosts.')
    parser.add_argument('--binhost-conf-dir',
                        help='Directory to commit binhost config with '
                        '--sync-binhost-conf.')
    parser.add_argument('-P',
                        '--private',
                        action='store_true',
                        default=False,
                        help='Mark gs:// uploads as private.')
    parser.add_argument('--skip-upload',
                        action='store_true',
                        default=False,
                        help='Skip upload step.')
    parser.add_argument('--upload-board-tarball',
                        action='store_true',
                        default=False,
                        help='Upload board tarball to Google Storage.')
    parser.add_argument('-n',
                        '--dry-run',
                        dest='dryrun',
                        action='store_true',
                        default=False,
                        help='Don\'t push or upload prebuilts.')

    options = parser.parse_args(argv)
    if not options.upload and not options.skip_upload:
        parser.error('you need to provide an upload location using -u')
    if not options.set_version and options.skip_upload:
        parser.error('If you are using --skip-upload, you must specify a '
                     'version number using --set-version.')

    target = None
    if options.board:
        target = BuildTarget(options.board, options.profile)

    if target in options.slave_targets:
        parser.error('--board/--profile must not also be a slave target.')

    if len(set(options.slave_targets)) != len(options.slave_targets):
        parser.error('--slave-boards must not have duplicates.')

    if options.slave_targets and options.git_sync:
        parser.error('--slave-boards is not compatible with --git-sync')

    if (options.upload_board_tarball and options.skip_upload
            and options.board == 'amd64-host'):
        parser.error('--skip-upload is not compatible with '
                     '--upload-board-tarball and --board=amd64-host')

    if (options.upload_board_tarball and not options.skip_upload
            and not options.upload.startswith('gs://')):
        parser.error('--upload-board-tarball only works with gs:// URLs.\n'
                     '--upload must be a gs:// URL.')

    if options.upload_board_tarball and options.prepackaged_tarball is None:
        parser.error('--upload-board-tarball requires --prepackaged-tarball')

    if options.private:
        if options.sync_host:
            parser.error('--private and --sync-host/-s cannot be specified '
                         'together; we do not support private host prebuilts')

        if not options.upload or not options.upload.startswith('gs://'):
            parser.error('--private is only valid for gs:// URLs; '
                         '--upload must be a gs:// URL.')

        if options.binhost_base_url != _BINHOST_BASE_URL:
            parser.error('when using --private the --binhost-base-url '
                         'is automatically derived.')

    if options.sync_binhost_conf and not options.binhost_conf_dir:
        parser.error('--sync-binhost-conf requires --binhost-conf-dir')

    if (options.toolchains_overlay_tarballs
            and not options.toolchains_overlay_upload_path):
        parser.error('--toolchains-overlay-tarball requires '
                     '--toolchains-overlay-upload-path')

    return options, target
Exemplo n.º 23
0
def GetParser():
    """Creates the argparse parser."""
    parser = commandline.ArgumentParser(description=__doc__)
    return parser
Exemplo n.º 24
0
def _ParseArguments(argv):
    parser = commandline.ArgumentParser(description=__doc__)

    parser.add_argument('--app_id',
                        default=None,
                        help='The APP_ID to install.')
    parser.add_argument('--board', help='The board name.', required=True)
    parser.add_argument(
        '--sysroot',
        required=True,
        type='path',
        help='The sysroot to install the lsb-release file into.')
    parser.add_argument('--version_string',
                        required=True,
                        help='The image\'s version string.')
    parser.add_argument('--auserver',
                        default=None,
                        help='The auserver url to use.')
    parser.add_argument('--devserver',
                        default=None,
                        help='The devserver url to use.')
    parser.add_argument('--official',
                        action='store_true',
                        help='Whether or not to populate with fields for an '
                        'official image.')
    parser.add_argument('--buildbot_build',
                        default='N/A',
                        help='The build number, for use with the continuous '
                        'builder.')
    parser.add_argument('--track',
                        default='developer-build',
                        help='The type of release track.')
    parser.add_argument('--branch_number',
                        default='0',
                        help='The branch number.')
    parser.add_argument('--build_number',
                        default='0',
                        help='The build number.')
    parser.add_argument('--chrome_milestone',
                        default='0',
                        help='The Chrome milestone.')
    parser.add_argument('--patch_number',
                        default='0',
                        help='The patch number for the given branch.')
    parser.add_argument('--arc_version', default=None, help='The ARC version.')

    opts = parser.parse_args(argv)

    # If the auserver or devserver isn't specified or is set to blank, set it
    # to the host's hostname.
    hostname = cros_build_lib.GetHostName(fully_qualified=True)

    if not opts.auserver:
        opts.auserver = 'http://%s:8080/update' % hostname

    if not opts.devserver:
        opts.devserver = 'http://%s:8080' % hostname

    opts.Freeze()

    if not os.path.isdir(opts.sysroot):
        cros_build_lib.Die('The target sysroot does not exist: %s' %
                           opts.sysroot)

    if not opts.version_string:
        cros_build_lib.Die(
            'version_string must not be empty.  Was '
            'chromeos_version.sh sourced correctly in the calling '
            'script?')

    return opts