Ejemplo n.º 1
0
    def Run(self):
        """Run cros buildresult."""
        self.options.Freeze()

        commandline.RunInsideChroot(self)

        buildstore = BuildStore(_write_to_cidb=False)
        build_statuses = FetchBuildStatuses(buildstore, self.options)

        if build_statuses:
            # Filter out builds that don't exist in Buildbucket,
            # or which aren't finished.
            build_statuses = [
                b for b in build_statuses if IsBuildStatusFinished(b)
            ]

        # If we found no builds at all, return a different exit code to help
        # automated scripts know they should try waiting longer.
        if not build_statuses:
            logging.error('No build found. Perhaps not started?')
            return 2

        # Fixup all of the builds we have.
        build_statuses = [
            FixUpBuildStatus(buildstore, b) for b in build_statuses
        ]

        # Produce our final result.
        if self.options.report == 'json':
            report = ReportJson(build_statuses)
        else:
            report = Report(build_statuses)

        print(report)
Ejemplo n.º 2
0
    def _VerifyRunInsideChroot(self,
                               expected_cmd,
                               expected_chroot_args=None,
                               log_level_args=None,
                               **kwargs):
        """Run RunInsideChroot, and verify it raises with expected values.

    Args:
      expected_cmd: Command that should be executed inside the chroot.
      expected_chroot_args: Args that should be passed as chroot args.
      log_level_args: Args that set the log level of cros_sdk.
      kwargs: Additional args to pass to RunInsideChroot().
    """
        with self.assertRaises(commandline.ChrootRequiredError) as cm:
            commandline.RunInsideChroot(self.cmd, **kwargs)

        if log_level_args is None:
            log_level_args = ['--log-level', self.cmd.options.log_level]

        if expected_chroot_args is not None:
            log_level_args.extend(expected_chroot_args)
            expected_chroot_args = log_level_args
        else:
            expected_chroot_args = log_level_args

        self.assertEqual(expected_cmd, cm.exception.cmd)
        self.assertEqual(expected_chroot_args, cm.exception.chroot_args)
Ejemplo n.º 3
0
  def Run(self):
    """Run cros debug."""
    commandline.RunInsideChroot(self)
    self.options.Freeze()
    self._ReadOptions()
    with remote_access.ChromiumOSDeviceHandler(
        self.ssh_hostname, port=self.ssh_port, username=self.ssh_username,
        private_key=self.ssh_private_key) as device:
      self.board = cros_build_lib.GetBoard(device_board=device.board,
                                           override_board=self.options.board,
                                           strict=True)
      logging.info('Board is %s', self.board)

      self.gdb_cmd = [
          'gdb_remote', '--ssh',
          '--board', self.board,
          '--remote', self.ssh_hostname,
      ]
      if self.ssh_port:
        self.gdb_cmd.extend(['--ssh_port', str(self.ssh_port)])

      if not (self.pid or self.exe):
        cros_build_lib.Die(
            'Must use --exe or --pid to specify the process to debug.')

      if self.pid:
        if self.list or self.exe:
          cros_build_lib.Die(
              '--list and --exe are disallowed when --pid is used.')
        self._DebugRunningProcess(self.pid)
        return

      if not self.exe.startswith('/'):
        cros_build_lib.Die('--exe must have a full pathname.')
      logging.debug('Executable path is %s', self.exe)
      if not device.IsFileExecutable(self.exe):
        cros_build_lib.Die(
            'File path "%s" does not exist or is not executable on device %s',
            self.exe, self.ssh_hostname)

      pids = device.GetRunningPids(self.exe)
      self._ListProcesses(device, pids)

      if self.list:
        # If '--list' flag is on, do not launch GDB.
        return

      if pids:
        choices = ['Start a new process under GDB']
        choices.extend(pids)
        idx = cros_build_lib.GetChoice(
            'Please select the process pid to debug (select [0] to start a '
            'new process):', choices)
        if idx == 0:
          self._DebugNewProcess()
        else:
          self._DebugRunningProcess(pids[idx - 1])
      else:
        self._DebugNewProcess()
Ejemplo n.º 4
0
    def Run(self):
        """Run cros build-ap."""
        self.options.Freeze()

        commandline.RunInsideChroot(self)

        try:
            ap_firmware.build(self.build_target,
                              fw_name=self.options.fw_name,
                              dry_run=self.options.dry_run)
        except ap_firmware.Error as e:
            cros_build_lib.Die(e)
Ejemplo n.º 5
0
  def Run(self):
    """Run cros build."""
    self.options.Freeze()

    if not self.host:
      if not (self.board or self.brick):
        cros_build_lib.Die('You did not specify a board/brick to build for. '
                           'You need to be in a brick directory or set '
                           '--board/--brick/--host')

      if self.brick and self.brick.legacy:
        cros_build_lib.Die('--brick should not be used with board names. Use '
                           '--board=%s instead.' % self.brick.config['name'])

    if self.board:
      chroot_args = ['--board', self.board]
    else:
      chroot_args = None

    commandline.RunInsideChroot(self, chroot_args=chroot_args)

    if not (self.build_pkgs or self.options.init_only):
      cros_build_lib.Die('No packages found, nothing to build.')

    # Set up the sysroots if not building for host.
    if self.brick or self.board:
      chroot_util.SetupBoard(
          brick=self.brick, board=self.board,
          update_chroot=self.chroot_update,
          update_host_packages=self.options.host_packages_update,
          use_binary=self.options.binary)

    if not self.options.init_only:
      # Preliminary: enable all packages that only have a live ebuild.
      if self.options.enable_only_latest:
        workon = workon_helper.WorkonHelper(self.sysroot)
        workon.StartWorkingOnPackages([], use_workon_only=True)

      if command.UseProgressBar():
        op = BrilloBuildOperation()
        op.Run(
            parallel.RunParallelSteps, [self._CheckDependencies, self._Build],
            log_level=logging.DEBUG)
        if self.options.test:
          self._Test()
      else:
        parallel.RunParallelSteps([self._CheckDependencies, self._Build])
        if self.options.test:
          self._Test()
      logging.notice('Build completed successfully.')
    def Run(self):
        """Perform the cros flash-ap command."""
        commandline.RunInsideChroot(self)
        self.validate_options()

        build_target = build_target_lib.BuildTarget(self.options.build_target)
        try:
            ap_firmware.deploy(build_target,
                               self.options.image,
                               self.options.device,
                               flashrom=self.options.flashrom,
                               fast=self.options.fast,
                               verbose=self.options.verbose,
                               dryrun=self.options.dry_run)
        except ap_firmware.Error as e:
            cros_build_lib.Die(e)
Ejemplo n.º 7
0
 def Run(self):
     """Run cros deploy."""
     commandline.RunInsideChroot(self)
     self.options.Freeze()
     deploy.Deploy(self.options.device,
                   self.options.packages,
                   board=self.options.board,
                   emerge=self.options.emerge,
                   update=self.options.update,
                   deep=self.options.deep,
                   deep_rev=self.options.deep_rev,
                   clean_binpkg=self.options.clean_binpkg,
                   root=self.options.root,
                   strip=self.options.strip,
                   emerge_args=self.options.emerge_args,
                   ssh_private_key=self.options.private_key,
                   ping=self.options.ping,
                   force=self.options.force,
                   dry_run=self.options.dry_run)
     logging.info('cros deploy completed successfully.')
Ejemplo n.º 8
0
def main(argv):
    """Find and report approximate size info for a particular built package."""
    commandline.RunInsideChroot()

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

    db = portage_util.PortageDB(root=opts.root)

    if opts.packages:
        installed_packages = portage_util.GenerateInstalledPackages(
            db, opts.root, opts.packages)
    else:
        installed_packages = db.InstalledPackages()

    results = generate_package_size_report(db, opts.root, opts.image_type,
                                           opts.partition_name,
                                           installed_packages)
    print(json.dumps(results))
Ejemplo n.º 9
0
    def Run(self):
        """Run cros buildresult."""
        self.options.Freeze()

        commandline.RunInsideChroot(self)

        credentials = self.options.cred_dir
        if not credentials:
            credentials = cros_cidbcreds.CheckAndGetCIDBCreds(
                force_update=self.options.force_update)

        # Delay import so sqlalchemy isn't pulled in until we need it.
        from chromite.lib import cidb

        db = cidb.CIDBConnection(credentials)

        build_statuses = FetchBuildStatuses(db, self.options)

        if build_statuses:
            # Filter out builds that don't exist in CIDB, or which aren't finished.
            build_statuses = [
                b for b in build_statuses if IsBuildStatusFinished(b)
            ]

        # If we found no builds at all, return a different exit code to help
        # automated scripts know they should try waiting longer.
        if not build_statuses:
            logging.error('No build found. Perhaps not started?')
            return 2

        # Fixup all of the builds we have.
        build_statuses = [FixUpBuildStatus(db, b) for b in build_statuses]

        # Produce our final result.
        if self.options.report == 'json':
            report = ReportJson(build_statuses)
        else:
            report = Report(build_statuses)

        print(report)
Ejemplo n.º 10
0
    def testRunInsideChrootAlreadyInside(self):
        """Test we don't restart inside the chroot if we are already there."""
        self.mock_inside_chroot.return_value = True

        # Since we are in the chroot, it should return, doing nothing.
        commandline.RunInsideChroot(self.cmd)
Ejemplo n.º 11
0
    def Run(self):
        """Run cros build."""
        self.options.Freeze()

        commandline.RunInsideChroot(self)

        credentials = self.options.cred_dir
        if not credentials:
            credentials = cros_cidbcreds.CheckAndGetCIDBCreds()

        # Delay import so sqlalchemy isn't pulled in until we need it.
        from chromite.lib import cidb

        db = cidb.CIDBConnection(credentials)

        # Timeframe for discovering builds, if options.build_id not used.
        start_date, end_date = self.OptionsToStartEndDates(self.options)

        # Trending is sufficiently different to be handled on it's own.
        if not self.options.trending and self.options.report != 'success':
            assert not self.options.csv, (
                '--csv can only be used with --trending or --report success.')

        # Data about a single build (optional).
        focus_build = None

        if self.options.build_id:
            logging.info('Gathering data for %s', self.options.build_id)
            focus_status = build_time_stats.BuildIdToBuildStatus(
                db, self.options.build_id)
            focus_build = build_time_stats.GetBuildTimings(focus_status)

            build_config = focus_status['build_config']
            builds_statuses = build_time_stats.BuildConfigToStatuses(
                db, build_config, start_date, end_date)
            description = 'Focus %d - %s' % (self.options.build_id,
                                             build_config)

        elif self.options.build_config:
            builds_statuses = build_time_stats.BuildConfigToStatuses(
                db, self.options.build_config, start_date, end_date)
            description = 'Config %s' % self.options.build_config

        elif self.options.build_type:
            builds_statuses = build_time_stats.MasterConfigToStatuses(
                db, BUILD_TYPE_MAP[self.options.build_type], start_date,
                end_date)
            description = 'Type %s' % self.options.build_type

        if not builds_statuses:
            logging.critical('No Builds Found For: %s', description)
            return 1

        if self.options.report == 'success':
            # Calculate per-build success rates and per-stage success rates.
            build_success_rates = build_time_stats.GetBuildSuccessRates(
                builds_statuses)
            stage_success_rates = (
                build_time_stats.GetStageSuccessRates(builds_statuses)
                if self.options.stages else {})
            if self.options.csv:
                build_time_stats.SuccessReportCsv(sys.stdout,
                                                  build_success_rates,
                                                  stage_success_rates)
            else:
                build_time_stats.SuccessReport(sys.stdout, description,
                                               build_success_rates,
                                               stage_success_rates)
            return 0

        # Compute per-build timing.
        builds_timings = [
            build_time_stats.GetBuildTimings(status)
            for status in builds_statuses
        ]

        if not builds_timings:
            logging.critical('No timing results For: %s', description)
            return 1

        # Report results.
        if self.options.report == 'standard':
            build_time_stats.Report(sys.stdout, description, focus_build,
                                    builds_timings, self.options.stages,
                                    self.options.trending, self.options.csv)
        elif self.options.report == 'stability':
            build_time_stats.StabilityReport(sys.stdout, description,
                                             builds_timings)
Ejemplo n.º 12
0
    def Run(self):
        if self.options.build_target_name:
            self.options.build_target = build_target_lib.BuildTarget(
                self.options.build_target_name)
        else:
            self.options.build_target = None

        self.options.Freeze()

        has_target = self.options.host or self.options.build_target
        needs_target = self.options.action != 'list-all'
        if needs_target and not has_target:
            cros_build_lib.Die(
                f'{self.options.action} requires a build target or '
                'specifying the host.')

        commandline.RunInsideChroot(self)

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

        if self.options.build_target:
            target = self.options.build_target.name
            sysroot = self.options.build_target.root
        else:
            target = 'host'
            sysroot = '/'

        helper = workon_helper.WorkonHelper(sysroot, target)
        try:
            if self.options.action == 'start':
                helper.StartWorkingOnPackages(
                    self.options.packages,
                    use_all=self.options.all,
                    use_workon_only=self.options.workon_only)
            elif self.options.action == 'stop':
                helper.StopWorkingOnPackages(
                    self.options.packages,
                    use_all=self.options.all,
                    use_workon_only=self.options.workon_only)
            elif self.options.action == 'info':
                triples = helper.GetPackageInfo(
                    self.options.packages,
                    use_all=self.options.all,
                    use_workon_only=self.options.workon_only)
                for package, repos, paths in triples:
                    print(package, ','.join(repos), ','.join(paths))
            elif self.options.action == 'list':
                packages = helper.ListAtoms(
                    use_all=self.options.all,
                    use_workon_only=self.options.workon_only)
                if packages:
                    print('\n'.join(packages))
            elif self.options.action == 'iterate':
                helper.RunCommandInPackages(
                    self.options.packages,
                    self.options.iterate_command,
                    use_all=self.options.all,
                    use_workon_only=self.options.workon_only)
            else:
                cros_build_lib.Die(
                    f'No implementation for {self.options.action}')
        except workon_helper.WorkonError as e:
            cros_build_lib.Die(e)
        return 0