def testGclientRoot(self):
     """Test when we are inside a gclient checkout."""
     self.cwd_mock.return_value = self.gclient_root
     self.assertEqual(
         path_util.FindCacheDir(),
         os.path.join(self.gclient_root, 'src', 'build',
                      path_util.CHROME_CACHE_DIR))
Esempio n. 2
0
def main(argv):
  options = ParseArgs(argv)

  if not cros_build_lib.IsInsideChroot():
    raise commandline.ChrootRequiredError()

  if os.geteuid() != 0:
    cros_build_lib.SudoRunCommand(sys.argv)
    return

  # sysroot must have a trailing / as the tree dictionary produced by
  # create_trees in indexed with a trailing /.
  sysroot = cros_build_lib.GetSysroot(options.board) + '/'
  trees = create_trees(target_root=sysroot, config_root=sysroot)

  vartree = trees[sysroot]['vartree']

  cache_dir = os.path.join(path_util.FindCacheDir(),
                           'cros_install_debug_syms-v' + CACHE_VERSION)

  if options.clearcache:
    osutils.RmDir(cache_dir, ignore_missing=True)

  binhost_cache = None
  if options.cachebinhost:
    binhost_cache = cache.DiskCache(cache_dir)

  boto_file = vartree.settings['BOTO_CONFIG']
  if boto_file:
    os.environ['BOTO_CONFIG'] = boto_file

  gs_context = gs.GSContext()
  symbols_mapping = RemoteSymbols(vartree, binhost_cache)

  if options.all:
    to_install = vartree.dbapi.cpv_all()
  else:
    to_install = [GetMatchingCPV(p, vartree.dbapi) for p in options.packages]

  to_install = [p for p in to_install
                if ShouldGetSymbols(p, vartree.dbapi, symbols_mapping)]

  if not to_install:
    logging.info('nothing to do, exit')
    return

  with DebugSymbolsInstaller(vartree, gs_context, sysroot,
                             not options.debug) as installer:
    args = [(p, symbols_mapping[p]) for p in to_install]
    parallel.RunTasksInProcessPool(installer.Install, args,
                                   processes=options.jobs)

  logging.debug('installation done, updating packages index file')
  packages_dir = os.path.join(sysroot, 'packages')
  packages_file = os.path.join(packages_dir, 'Packages')
  # binpkg will set DEBUG_SYMBOLS automatically if it detects the debug symbols
  # in the packages dir.
  pkgindex = binpkg.GrabLocalPackageIndex(packages_dir)
  with open(packages_file, 'w') as p:
    pkgindex.Write(p)
Esempio n. 3
0
def GetBinhostCache(options):
    """Get and optionally clear the binhost cache."""
    cache_dir = os.path.join(path_util.FindCacheDir(),
                             'cros_install_debug_syms-v' + CACHE_VERSION)
    if options.clearcache:
        osutils.RmDir(cache_dir, ignore_missing=True)

    binhost_cache = None
    if options.cachebinhost:
        binhost_cache = cache.DiskCache(cache_dir)

    return binhost_cache
 def testTempdir(self):
     """Test when we are not in any checkout."""
     self.cwd_mock.return_value = self.nocheckout_root
     self.assertStartsWith(path_util.FindCacheDir(),
                           os.path.join(tempfile.gettempdir(), ''))
 def testRepoRoot(self):
     """Test when we are inside a repo checkout."""
     self.cwd_mock.return_value = self.repo_root
     self.assertEqual(
         path_util.FindCacheDir(),
         os.path.join(self.repo_root, path_util.GENERAL_CACHE_DIR))
Esempio n. 6
0
 def FindCacheDir(cls, _parser, _opts):
     logging.debug('Cache dir lookup.')
     return path_util.FindCacheDir()
Esempio n. 7
0
    def VerifyAndFinishInitialization(self, device):
        """Verify files/processes exist and flags are correct."""
        if not self.board:
            if self.remote:
                self.board = cros_build_lib.GetBoard(device_board=device.board,
                                                     override_board=self.board,
                                                     strict=True)
            else:
                raise GdbCannotDetectBoardError(
                    'Cannot determine which board to use. '
                    'Please specify the with --board flag.')
        self.in_chroot = self.IsInChroot()
        self.prompt = '(%s-gdb) ' % self.board
        if self.in_chroot:
            self.sysroot = cros_build_lib.GetSysroot(board=self.board)
            self.inf_cmd = self.RemoveSysrootPrefix(self.inf_cmd)
            self.cross_gdb = self.GetCrossGdb()
        else:
            self.chrome_path = os.path.realpath(
                os.path.join(os.path.dirname(os.path.realpath(__file__)),
                             '../../../..'))
            self.sdk_path = os.path.join(path_util.FindCacheDir(),
                                         'chrome-sdk/tarballs/')
            self.sysroot = self.SimpleChromeSysroot()
            self.cross_gdb = self.SimpleChromeGdb()

        if self.remote:

            # If given remote process name, find pid & inf_cmd on remote device.
            if self.remote_process_name or self.pid:
                self._FindRemoteProcess(device)

            # Verify that sysroot is valid (exists).
            if not os.path.isdir(self.sysroot):
                raise GdbMissingSysrootError('Sysroot does not exist: %s' %
                                             self.sysroot)

        self.device = device
        if not self.in_chroot:
            return

        sysroot_inf_cmd = ''
        if self.inf_cmd:
            sysroot_inf_cmd = os.path.join(self.sysroot,
                                           self.inf_cmd.lstrip('/'))

        # Verify that inf_cmd, if given, exists.
        if sysroot_inf_cmd and not os.path.exists(sysroot_inf_cmd):
            raise GdbMissingInferiorError('Cannot find file %s (in sysroot).' %
                                          sysroot_inf_cmd)

        # Check to see if inf_cmd is stripped, and if so, check to see if debug file
        # exists.  If not, tell user and give them the option of quitting & getting
        # the debug info.
        if sysroot_inf_cmd:
            stripped_info = cros_build_lib.run(['file', sysroot_inf_cmd],
                                               capture_output=True).output
            if ' not stripped' not in stripped_info:
                debug_file = os.path.join(self.sysroot, 'usr/lib/debug',
                                          self.inf_cmd.lstrip('/'))
                debug_file += '.debug'
                if not os.path.exists(debug_file):
                    equery = 'equery-%s' % self.board
                    package = cros_build_lib.run(
                        [equery, '-q', 'b', self.inf_cmd],
                        capture_output=True).output
                    # pylint: disable=logging-not-lazy
                    logging.info(
                        self._MISSING_DEBUG_INFO_MSG % {
                            'board': self.board,
                            'inf_cmd': self.inf_cmd,
                            'package': package,
                            'debug_file': debug_file
                        })
                    answer = cros_build_lib.BooleanPrompt()
                    if not answer:
                        raise GdbEarlyExitError(
                            'Exiting early, at user request.')

        # Set up qemu, if appropriate.
        qemu_arch = qemu.Qemu.DetectArch(self._GDB, self.sysroot)
        if qemu_arch is None:
            self.framework = 'ldso'
        else:
            self.framework = 'qemu'
            self.qemu = qemu.Qemu(self.sysroot, arch=qemu_arch)

        if self.remote:
            # Verify cgdb flag info.
            if self.cgdb:
                if osutils.Which('cgdb') is None:
                    raise GdbMissingDebuggerError(
                        'Cannot find cgdb.  Please install '
                        'cgdb first.')