コード例 #1
0
def Untar(path, cwd, sudo=False):
  """Untar a tarball."""
  functor = cros_build_lib.sudo_run if sudo else cros_build_lib.run
  comp = cros_build_lib.CompressionExtToType(path)
  cmd = ['tar']
  if comp != cros_build_lib.COMP_NONE:
    extra_comp_args = [cros_build_lib.FindCompressor(comp)]
    if os.path.basename(extra_comp_args[0]) == 'pbzip2':
      extra_comp_args.append('--ignore-trailing-garbage=1')
    cmd += ['-I', ' '.join(extra_comp_args)]
  functor(cmd + ['-xpf', path], cwd=cwd, debug_level=logging.DEBUG, quiet=True)
コード例 #2
0
    def _ExtractLibc(self, sysroot, board_chost, libc_path):
        """Extract the libc archive to the sysroot.

    Args:
      sysroot: sysroot_lib.Sysroot - The sysroot where it's being installed.
      board_chost: str - The board's CHOST value.
      libc_path: str - The location of the libc archive.
    """
        compressor = cros_build_lib.FindCompressor(cros_build_lib.COMP_BZIP2)
        if compressor.endswith('pbzip2'):
            compressor = '%s --ignore-trailing-garbage=1' % compressor

        with osutils.TempDir(sudo_rm=True) as tempdir:
            # Extract to the temporary directory.
            cmd = ['tar', '-I', compressor, '-xpf', libc_path, '-C', tempdir]
            result = cros_build_lib.sudo_run(cmd,
                                             check=False,
                                             capture_output=True,
                                             stderr=subprocess.STDOUT)
            if result.returncode:
                raise ToolchainInstallError(
                    'Error extracting libc: %s' % result.stdout, result)

            # Sync the files to the sysroot to install.
            # Trailing / on source to sync contents instead of the directory itself.
            source = os.path.join(tempdir, 'usr', board_chost)
            cmd = ['rsync', '--archive', '%s/' % source, '%s/' % sysroot.path]
            result = cros_build_lib.sudo_run(cmd,
                                             check=False,
                                             capture_output=True,
                                             stderr=subprocess.STDOUT)
            if result.returncode:
                raise ToolchainInstallError(
                    'Error installing libc: %s' % result.stdout, result)

            # Make the debug directory.
            debug_dir = os.path.join(sysroot.path, 'usr/lib/debug')
            osutils.SafeMakedirs(debug_dir, sudo=True)
            # Sync the debug files to the debug directory.
            source = os.path.join(tempdir, 'usr/lib/debug/usr', board_chost)
            cmd = ['rsync', '--archive', '%s/' % source, '%s/' % debug_dir]
            result = cros_build_lib.sudo_run(cmd,
                                             check=False,
                                             capture_output=True,
                                             stderr=subprocess.STDOUT)
            if result.returncode:
                logging.warning('libc debug info not copied: %s',
                                result.stdout)
コード例 #3
0
  def _ArchiveChromeEbuildEnv(self):
    """Generate and upload Chrome ebuild environment."""
    files = glob.glob(os.path.join(self._pkg_dir, constants.CHROME_CP) + '-*')
    if not files:
      raise artifact_stages.NothingToArchiveException(
          'Failed to find package %s' % constants.CHROME_CP)
    if len(files) > 1:
      logging.PrintBuildbotStepWarnings()
      logging.warning('Expected one package for %s, found %d',
                      constants.CHROME_CP, len(files))

    chrome_dir = sorted(files)[-1]
    env_bzip = os.path.join(chrome_dir, 'environment.bz2')
    with osutils.TempDir(prefix='chrome-sdk-stage') as tempdir:
      # Convert from bzip2 to tar format.
      bzip2 = cros_build_lib.FindCompressor(cros_build_lib.COMP_BZIP2)
      cros_build_lib.RunCommand(
          [bzip2, '-d', env_bzip, '-c'],
          log_stdout_to_file=os.path.join(tempdir, constants.CHROME_ENV_FILE))
      env_tar = os.path.join(self.archive_path, constants.CHROME_ENV_TAR)
      cros_build_lib.CreateTarball(env_tar, tempdir)
      self._upload_queue.put([os.path.basename(env_tar)])
コード例 #4
0
def ArchiveChromeEbuildEnv(sysroot, output_dir):
    """Generate Chrome ebuild environment.

  Args:
    sysroot (sysroot_lib.Sysroot): The sysroot where the original environment
      archive can be found.
    output_dir (str): Where the result should be stored.

  Returns:
    str: The path to the archive.

  Raises:
    NoFilesException: When the package cannot be found.
  """
    pkg_dir = os.path.join(sysroot.path, portage_util.VDB_PATH)
    files = glob.glob(os.path.join(pkg_dir, constants.CHROME_CP) + '-*')
    if not files:
        raise NoFilesError('Failed to find package %s' % constants.CHROME_CP)

    if len(files) > 1:
        logging.warning('Expected one package for %s, found %d',
                        constants.CHROME_CP, len(files))

    chrome_dir = sorted(files)[-1]
    env_bzip = os.path.join(chrome_dir, 'environment.bz2')
    result_path = os.path.join(output_dir, constants.CHROME_ENV_TAR)
    with osutils.TempDir() as tempdir:
        # Convert from bzip2 to tar format.
        bzip2 = cros_build_lib.FindCompressor(cros_build_lib.COMP_BZIP2)
        tempdir_tar_path = os.path.join(tempdir, constants.CHROME_ENV_FILE)
        cros_build_lib.run([bzip2, '-d', env_bzip, '-c'],
                           stdout=tempdir_tar_path)

        cros_build_lib.CreateTarball(result_path, tempdir)

    return result_path