def UpdateTargets(cls, targets, usepkg, config_only=False):
    """Calls crossdev to initialize a cross target.

    Args:
      targets: The list of targets to initialize using crossdev.
      usepkg: Copies the commandline opts.
      config_only: Just update.
    """
    configured_targets = cls._CACHE.setdefault('configured_targets', [])

    cmdbase = ['crossdev', '--show-fail-log']
    cmdbase.extend(['--env', 'FEATURES=splitdebug'])
    # Pick stable by default, and override as necessary.
    cmdbase.extend(['-P', '--oneshot'])
    if usepkg:
      cmdbase.extend(['-P', '--getbinpkg',
                      '-P', '--usepkgonly',
                      '--without-headers'])

    overlays = ' '.join((CHROMIUMOS_OVERLAY, ECLASS_OVERLAY, STABLE_OVERLAY))
    cmdbase.extend(['--overlays', overlays])
    cmdbase.extend(['--ov-output', CROSSDEV_OVERLAY])

    # Build target by the reversed alphabetical order to make sure
    # armv7a-cros-linux-gnueabihf builds before armv7a-cros-linux-gnueabi
    # because some dependency issue. This can be reverted once we
    # migrated to armv7a-cros-linux-gnueabihf. crbug.com/711369
    for target in sorted(targets, reverse=True):
      if config_only and target in configured_targets:
        continue

      cmd = cmdbase + ['-t', target]

      for pkg in GetTargetPackages(target):
        if pkg == 'gdb':
          # Gdb does not have selectable versions.
          cmd.append('--ex-gdb')
        elif pkg == 'ex_compiler-rt':
          cmd.extend(CROSSDEV_COMPILER_RT_ARGS)
        elif pkg == 'ex_go':
          # Go does not have selectable versions.
          cmd.extend(CROSSDEV_GO_ARGS)
        elif pkg in LLVM_PKGS_TABLE:
          cmd.extend(LLVM_PKGS_TABLE[pkg])
        elif pkg in cls.MANUAL_PKGS:
          pass
        else:
          # The first of the desired versions is the "primary" one.
          version = GetDesiredPackageVersions(target, pkg)[0]
          cmd.extend(['--%s' % pkg, version])

      cmd.extend(targets[target]['crossdev'].split())
      if config_only:
        # In this case we want to just quietly reinit
        cmd.append('--init-target')
        cros_build_lib.run(cmd, print_cmd=False, redirect_stdout=True)
      else:
        cros_build_lib.run(cmd)

      configured_targets.append(target)
    def PerformStage(self):
        new_chroot_dir = 'new-sdk-chroot'
        tarball_location = os.path.join(self._build_root, SDK_TARBALL_NAME)
        new_chroot_args = ['--chroot', new_chroot_dir]
        if self._run.options.chrome_root:
            new_chroot_args += ['--chrome_root', self._run.options.chrome_root]

        # Build a new SDK using the provided tarball.
        chroot_args = new_chroot_args + [
            '--download', '--replace', '--nousepkg', '--url',
            'file://' + tarball_location
        ]
        cros_build_lib.run(['true'],
                           cwd=self._build_root,
                           enter_chroot=True,
                           chroot_args=chroot_args,
                           extra_env=self._portage_extra_env)

        # Inject the toolchain binpkgs from the previous sdk build.  On end user
        # systems, they'd be fetched from the binpkg mirror, but we don't have one
        # set up for this local build.
        pkgdir = os.path.join('var', 'lib', 'portage', 'pkgs')
        old_pkgdir = os.path.join(self._build_root,
                                  constants.DEFAULT_CHROOT_DIR, pkgdir)
        new_pkgdir = os.path.join(self._build_root, new_chroot_dir, pkgdir)
        osutils.SafeMakedirs(new_pkgdir, sudo=True)
        cros_build_lib.sudo_run(['cp', '-r'] +
                                glob.glob(os.path.join(old_pkgdir, '*')) +
                                [new_pkgdir])

        # Now install those toolchains in the new chroot.  We skip the chroot
        # upgrade below which means we need to install the toolchain manually.
        cmd = [
            'cros_setup_toolchains', '--targets=boards',
            '--include-boards=%s' % ','.join(self._boards)
        ]
        commands.RunBuildScript(self._build_root,
                                cmd,
                                chromite_cmd=True,
                                enter_chroot=True,
                                sudo=True,
                                chroot_args=new_chroot_args,
                                extra_env=self._portage_extra_env)

        # Build all the boards with the new sdk.
        for board in self._boards:
            logging.PrintBuildbotStepText(board)
            commands.SetupBoard(self._build_root,
                                board,
                                usepkg=True,
                                chroot_upgrade=False,
                                extra_env=self._portage_extra_env,
                                chroot_args=new_chroot_args)
            commands.Build(self._build_root,
                           board,
                           build_autotest=True,
                           usepkg=False,
                           extra_env=self._portage_extra_env,
                           chroot_args=new_chroot_args,
                           disable_revdep_logic=True)
Exemple #3
0
def BuildPackage(package, board, build_type):
    """Builds a package on a specified board.

  Args:
    package: The package to build. Nothing is built if None.
    board: The board to build the package on.
    build_type: The type of the build to do (e.g. asan, msan, ubsan, coverage).
  """
    if package is None:
        return

    logging.info('Building %s using %s.', package, build_type)
    extra_env = GetBuildExtraEnv(build_type)
    build_packages_path = os.path.join(constants.SOURCE_ROOT, 'src', 'scripts',
                                       'build_packages')
    command = [
        build_packages_path,
        '--board',
        board,
        '--skip_chroot_upgrade',
        package,
    ]
    # For msan builds, always use "--nousepkg" since all package needs to be
    # instrumented with msan.
    if build_type == BuildType.MSAN:
        command += ['--nousepkg']

    # Print the output of the build command. Do this because it is familiar to
    # devs and we don't want to leave them not knowing about the build's progress
    # for a long time.
    cros_build_lib.run(command, extra_env=extra_env)
Exemple #4
0
def GenerateCoverageReport(fuzzer, shared_libraries):
    """Generates an HTML coverage report from a fuzzer run.

  Args:
    fuzzer: The fuzzer to generate the coverage report for.
    shared_libraries: Libraries loaded dynamically by |fuzzer|.

  Returns:
    The path of the coverage report.
  """
    fuzzer_path = GetFuzzerSysrootPath(fuzzer).chroot
    command = ['llvm-cov', 'show', '-object', fuzzer_path]
    for library in shared_libraries:
        command += ['-object', library]

    coverage_directory = GetCoverageDirectory(fuzzer)
    command += [
        '-format=html',
        '-instr-profile=%s' % GetProfdataPath(fuzzer).chroot,
        '-output-dir=%s' % coverage_directory.chroot,
    ]

    # TODO(metzman): Investigate error messages printed by this command.
    cros_build_lib.run(command,
                       redirect_stderr=True,
                       debug_level=logging.DEBUG)
    return coverage_directory
Exemple #5
0
def DeleteChrootSnapshot(snapshot_name, chroot_vg, chroot_lv):
    """Delete the named snapshot from the specified chroot VG.

  If the requested snapshot is not found, nothing happens.  The main chroot LV
  and internal thinpool LV cannot be deleted with this function.

  Args:
    snapshot_name: The name of the snapshot to delete.
    chroot_vg: The name of the VG containing the origin LV.
    chroot_lv: The name of the origin LV.

  Raises:
    SystemExit: The lvremove command failed.
  """
    if snapshot_name in (cros_sdk_lib.CHROOT_LV_NAME,
                         cros_sdk_lib.CHROOT_THINPOOL_NAME):
        logging.error(
            'Cannot remove LV %s as a snapshot.  Use cros_sdk --delete '
            'if you want to remove the whole chroot.', snapshot_name)
        return

    if snapshot_name not in ListChrootSnapshots(chroot_vg, chroot_lv):
        return

    cmd = ['lvremove', '-f', '%s/%s' % (chroot_vg, snapshot_name)]
    try:
        logging.notice('Deleting snapshot %s in VG %s.', snapshot_name,
                       chroot_vg)
        cros_build_lib.run(cmd, print_cmd=False, capture_output=True)
    except cros_build_lib.RunCommandError:
        raise SystemExit('Running %r failed!' % cmd)
def GetCurrentPackageVersion(current_version_path, platform):
  """Get package version of current component.

  Args:
    current_version_path: (str) path to current version component.
    platform: (str) platform name in omaha.

  Returns:
    str: package version of current component.
  """
  if current_version_path:
    ctx = gs.GSContext()
    src = os.path.join(current_version_path, platform, COMPONENT_ZIP)
    if ctx.Exists(src):
      with osutils.TempDir(prefix='component_') as tempdir:
        ctx.Copy(src, tempdir)
        cros_build_lib.run(
            ['unzip', '-o', '-d',
             tempdir, os.path.join(tempdir, COMPONENT_ZIP)],
            stdout=True, stderr=True)
        with open(os.path.join(tempdir, MANIFEST_FILE_NAME)) as f:
          manifest = json.load(f)
          if MANIFEST_PACKAGE_VERSION_FIELD in manifest:
            return manifest[MANIFEST_PACKAGE_VERSION_FIELD]
  return '0.0.0.0'
Exemple #7
0
def Clean(chroot, images=False, sysroots=False, tmp=False):
    """Clean the chroot.

  See:
    cros clean -h

  Args:
    chroot: The chroot to clean.
    images (bool): Remove all built images.
    sysroots (bool): Remove all of the sysroots.
    tmp (bool): Clean the tmp/ directory.
  """
    if not images and not sysroots and not tmp:
        return

    cmd = ['cros', 'clean']
    if chroot:
        cmd.extend(['--sdk-path', chroot.path])
    if images:
        cmd.append('--images')
    if sysroots:
        cmd.append('--sysroots')
    if tmp:
        cmd.append('--chroot-tmp')

    cros_build_lib.run(cmd)
 def PerformStage(self):
     cmd = [
         'debug_info_test',
         os.path.join(cros_build_lib.GetSysroot(board=self._current_board),
                      'usr/lib/debug')
     ]
     cros_build_lib.run(cmd, enter_chroot=True)
Exemple #9
0
    def setUp(self):
        # Create the chroot and sysroot instances.
        self.chroot_path = os.path.join(self.tempdir, 'chroot_dir')
        self.chroot = chroot_lib.Chroot(path=self.chroot_path)
        self.sysroot_path = os.path.join(self.chroot_path, 'sysroot_dir')
        self.sysroot = sysroot_lib.Sysroot(self.sysroot_path)

        # Create the output directory.
        self.output_dir = os.path.join(self.tempdir, 'output_dir')
        osutils.SafeMakedirs(self.output_dir)

        # The sysroot's /var/db/pkg prefix for the chrome package directories.
        var_db_pkg = os.path.join(self.sysroot_path, 'var', 'db', 'pkg')
        # Create the var/db/pkg dir so we have that much for no-chrome tests.
        osutils.SafeMakedirs(var_db_pkg)

        # Two versions of chrome to test the multiple version checks/handling.
        chrome_v1 = '%s-1.0.0-r1' % constants.CHROME_PN
        chrome_v2 = '%s-2.0.0-r1' % constants.CHROME_PN

        # Build the two chrome version paths.
        chrome_cat_dir = os.path.join(var_db_pkg, constants.CHROME_CN)
        self.chrome_v1_dir = os.path.join(chrome_cat_dir, chrome_v1)
        self.chrome_v2_dir = os.path.join(chrome_cat_dir, chrome_v2)

        # Directory tuple for verifying the result archive contents.
        self.expected_archive_contents = cros_test_lib.Directory(
            './', 'environment')

        # Create a environment.bz2 file to put into folders.
        env_file = os.path.join(self.tempdir, 'environment')
        osutils.Touch(env_file)
        cros_build_lib.run(['bzip2', env_file])
        self.env_bz2 = '%s.bz2' % env_file
    def Initialize(cls,
                   root,
                   manifest_url,
                   manifest_branch=None,
                   manifest_name=None,
                   mirror=False,
                   reference=None,
                   depth=None,
                   groups=None,
                   repo_url=None,
                   repo_branch=None):
        """Initialize and return a new Repository with `repo init`.

    Args:
      root: Path to the new repo root. Must not be within an existing
        repo repository.
      manifest_url: Manifest repository URL.
      manifest_branch: Manifest branch or revision.
      manifest_name: Initial manifest file from manifest repository.
      mirror: If True, create a repo mirror instead of a checkout.
      reference: Location of a mirror directory to reference.
      depth: Create shallow git clones with the given depth.
      groups: Restrict manifest projects to the given groups.
      repo_url: Repo command repository URL.
      repo_branch: Repo command repository branch or revision.

    Raises:
      Error: root already contained a .repo subdir.
      RunCommandError: `repo init` failed.
    """
        existing_root = git.FindRepoCheckoutRoot(root)
        if existing_root is not None:
            raise Error('cannot init in existing repo %r.' % existing_root)

        # TODO(lannm): Use 'chromite/bootstrap/repo'?
        cmd = ['repo', 'init', '--manifest-url', manifest_url]
        if manifest_branch is not None:
            cmd += ['--manifest-branch', manifest_branch]
        if manifest_name is not None:
            cmd += ['--manifest-name', manifest_name]
        if mirror:
            cmd += ['--mirror']
        if reference is not None:
            if isinstance(reference, Repository):
                reference = reference.root
            cmd += ['--reference', reference]
        if depth is not None:
            cmd += ['--depth', str(depth)]
        if groups is not None:
            cmd += ['--groups', groups]
        if repo_url is not None:
            cmd += ['--repo-url', repo_url]
        if repo_branch is not None:
            cmd += ['--repo-branch', repo_branch]

        repo_dir = os.path.join(root, '.repo')
        warning_msg = 'Removing %r due to `repo init` failures.' % repo_dir
        with _RmDirOnError(repo_dir, msg=warning_msg):
            cros_build_lib.run(cmd, cwd=root)
        return cls(root)
Exemple #11
0
 def _DeployChrome(self):
   """Deploy chrome."""
   deploy_cmd = [
       'deploy_chrome', '--force',
       '--build-dir', self.build_dir,
       '--process-timeout', '180',
       '--deploy-test-binaries',
   ]
   if self._device.ssh_port:
     deploy_cmd += [
         '--device',
         '%s:%d' % (self._device.device, self._device.ssh_port)
     ]
   else:
     deploy_cmd += ['--device', self._device.device]
   if self._device.board:
     deploy_cmd += ['--board', self._device.board]
   if self.cache_dir:
     deploy_cmd += ['--cache-dir', self.cache_dir]
   if self.nostrip:
     deploy_cmd += ['--nostrip']
   if self.mount:
     deploy_cmd += ['--mount']
   cros_build_lib.run(deploy_cmd, dryrun=self.dryrun)
   self._device.WaitForBoot()
Exemple #12
0
def VmTest(input_proto, _output_proto, _config):
    """Run VM tests."""
    build_target_name = input_proto.build_target.name
    vm_path = input_proto.vm_path.path

    test_harness = input_proto.test_harness

    vm_tests = input_proto.vm_tests

    cmd = [
        'cros_run_test', '--debug', '--no-display', '--copy-on-write',
        '--board', build_target_name, '--image-path', vm_path,
        '--%s' % test_pb2.VmTestRequest.TestHarness.Name(test_harness).lower()
    ]
    cmd.extend(vm_test.pattern for vm_test in vm_tests)

    if input_proto.ssh_options.port:
        cmd.extend(['--ssh-port', str(input_proto.ssh_options.port)])

    if input_proto.ssh_options.private_key_path:
        cmd.extend(
            ['--private-key', input_proto.ssh_options.private_key_path.path])

    # TODO(evanhernandez): Find a nice way to pass test_that-args through
    # the build API. Or obviate them.
    if test_harness == test_pb2.VmTestRequest.AUTOTEST:
        cmd.append('--test_that-args=--whitelist-chrome-crashes')

    with osutils.TempDir(prefix='vm-test-results.') as results_dir:
        cmd.extend(['--results-dir', results_dir])
        cros_build_lib.run(cmd, kill_timeout=10 * 60)
Exemple #13
0
def CreateChroot(chroot_path, sdk_tarball, cache_dir, nousepkg=False):
    """Creates a new chroot from a given SDK.

  Args:
    chroot_path: Path where the new chroot will be created.
    sdk_tarball: Path to a downloaded Gentoo Stage3 or Chromium OS SDK tarball.
    cache_dir: Path to a directory that will be used for caching portage files,
        etc.
    nousepkg: If True, pass --nousepkg to cros_setup_toolchains inside the
        chroot.
  """

    cmd = MAKE_CHROOT + [
        '--stage3_path', sdk_tarball, '--chroot', chroot_path, '--cache_dir',
        cache_dir
    ]

    if nousepkg:
        cmd.append('--nousepkg')

    logging.notice('Creating chroot. This may take a few minutes...')
    try:
        cros_build_lib.run(cmd, print_cmd=False)
    except cros_build_lib.RunCommandError:
        raise SystemExit('Running %r failed!' % cmd)
Exemple #14
0
 def test001SimpleQuery(self):
     """Create one independent and three dependent changes, then query them."""
     project = self.createProject('test001')
     clone_path = self.cloneProject(project)
     (head_sha1, head_changeid) = self.createCommit(clone_path)
     for idx in range(3):
         cros_build_lib.run(['git', 'checkout', head_sha1],
                            cwd=clone_path,
                            quiet=True)
         self.createCommit(clone_path, filename='test-file-%d.txt' % idx)
         self.uploadChange(clone_path)
     helper = self._GetHelper()
     changes = helper.Query(owner='self', project=project)
     self.assertEqual(len(changes), 4)
     changes = helper.Query(head_changeid, project=project, branch='master')
     self.assertEqual(len(changes), 1)
     self.assertEqual(changes[0].change_id, head_changeid)
     self.assertEqual(changes[0].sha1, head_sha1)
     change = helper.QuerySingleRecord(head_changeid,
                                       project=project,
                                       branch='master')
     self.assertTrue(change)
     self.assertEqual(change.change_id, head_changeid)
     self.assertEqual(change.sha1, head_sha1)
     change = helper.GrabPatchFromGerrit(project, head_changeid, head_sha1)
     self.assertTrue(change)
     self.assertEqual(change.change_id, head_changeid)
     self.assertEqual(change.sha1, head_sha1)
def BuildPackages(target, sysroot, run_configs):
  """Build and install packages into a sysroot.

  Args:
    target (build_target_lib.BuildTarget): The target whose packages are being
      installed.
    sysroot (sysroot_lib.Sysroot): The sysroot where the packages are being
      installed.
    run_configs (BuildPackagesRunConfig): The run configs.
  """
  cros_build_lib.AssertInsideChroot()

  cmd = [os.path.join(constants.CROSUTILS_DIR, 'build_packages'),
         '--board', target.name, '--board_root', sysroot.path]
  cmd += run_configs.GetBuildPackagesArgs()

  extra_env = run_configs.GetEnv()
  extra_env['USE_NEW_PARALLEL_EMERGE'] = '1'
  with osutils.TempDir() as tempdir:
    extra_env[constants.CROS_METRICS_DIR_ENVVAR] = tempdir

    try:
      # REVIEW: discuss which dimensions to flatten into the metric
      # name other than target.name...
      with metrics.timer('service.sysroot.BuildPackages.RunCommand'):
        cros_build_lib.run(cmd, extra_env=extra_env)
    except cros_build_lib.RunCommandError as e:
      failed_pkgs = portage_util.ParseDieHookStatusFile(tempdir)
      raise sysroot_lib.PackageInstallError(
          str(e), e.result, exception=e, packages=failed_pkgs)
    def _CreateArchive(self, archive_file, hashes, hash_names):
        """Take the hash strings and bundle them in the signer request format.

    Take the contents of an array of strings, and put them into a specified
    file in .tar.bz2 format. Each string is named with a specified name in
    the tar file.

    The number of hashes and number of hash_names must be equal. The
    archive_file will be created or overridden as needed. It's up to
    the caller to ensure it's cleaned up.

    Args:
      archive_file: Name of file to put the tar contents into.
      hashes: List of hashes to sign, stored in strings.
      hash_names: File names expected in the signer request.
    """
        try:
            tmp_dir = tempfile.mkdtemp(dir=self._work_dir)

            # Copy hash files into tmp_dir with standard hash names.
            for h, hash_name in zip(hashes, hash_names):
                osutils.WriteFile(os.path.join(tmp_dir, hash_name),
                                  h,
                                  mode='wb')

            cmd = ['tar', '-cjf', archive_file] + hash_names
            cros_build_lib.run(cmd,
                               redirect_stdout=True,
                               redirect_stderr=True,
                               cwd=tmp_dir)
        finally:
            # Cleanup.
            shutil.rmtree(tmp_dir)
Exemple #17
0
    def _CreateCommit(cls,
                      clone_path,
                      filename=None,
                      msg=None,
                      text=None,
                      amend=False):
        """Create a commit in the given git checkout.

    Args:
      clone_path: The directory on disk of the git clone.
      filename: The name of the file to write. Optional.
      msg: The commit message. Optional.
      text: The text to append to the file. Optional.
      amend: Whether to amend an existing patch. If set, we will amend the
        HEAD commit in the checkout and upload that patch.

    Returns:
      (sha1, changeid) of the new commit.
    """
        if not filename:
            filename = 'test-file.txt'
        if not msg:
            msg = 'Test Message'
        if not text:
            text = 'Another day, another dollar.'
        fpath = os.path.join(clone_path, filename)
        osutils.WriteFile(fpath, '%s\n' % text, mode='a')
        cros_build_lib.run(['git', 'add', filename],
                           cwd=clone_path,
                           quiet=True)
        cmd = ['git', 'commit']
        cmd += ['--amend', '-C', 'HEAD'] if amend else ['-m', msg]
        cros_build_lib.run(cmd, cwd=clone_path, quiet=True)
        return cls._GetCommit(clone_path)
def RemoveKnownHost(host, known_hosts_path=KNOWN_HOSTS_PATH):
  """Removes |host| from a known_hosts file.

  `ssh-keygen -R` doesn't work on bind mounted files as they can only
  be updated in place. Since we bind mount the default known_hosts file
  when entering the chroot, this function provides an alternate way
  to remove hosts from the file.

  Args:
    host: The host name to remove from the known_hosts file.
    known_hosts_path: Path to the known_hosts file to change. Defaults
                      to the standard SSH known_hosts file path.

  Raises:
    cros_build_lib.RunCommandError if ssh-keygen fails.
  """
  # `ssh-keygen -R` creates a backup file to retain the old 'known_hosts'
  # content and never deletes it. Using TempDir here to make sure both the temp
  # files created by us and `ssh-keygen -R` are deleted afterwards.
  with osutils.TempDir(prefix='remote-access-') as tempdir:
    temp_file = os.path.join(tempdir, 'temp_known_hosts')
    try:
      # Using shutil.copy2 to preserve the file ownership and permissions.
      shutil.copy2(known_hosts_path, temp_file)
    except IOError:
      # If |known_hosts_path| doesn't exist neither does |host| so we're done.
      return
    cros_build_lib.run(['ssh-keygen', '-R', host, '-f', temp_file], quiet=True)
    shutil.copy2(temp_file, known_hosts_path)
  def _CopyToDeviceInParallel(self, src, dest):
    """Chop source file in chunks, send them to destination in parallel.

    Transfer chunks of file in parallel and assemble in destination if the
    file size is larger than chunk size. Fall back to scp mode otherwise.

    Args:
      src: Local path as a string.
      dest: rsync/scp path of the form <host>:/<path> as a string.
    """
    src_filename = os.path.basename(src)
    chunk_prefix = src_filename + '_'
    with osutils.TempDir() as tempdir:
      chunk_path = os.path.join(tempdir, chunk_prefix)
      try:
        cmd = ['split', '-b', str(CHUNK_SIZE), src, chunk_path]
        cros_build_lib.run(cmd)
        input_list = [[chunk_file, dest, 'scp']
                      for chunk_file in glob.glob(chunk_path + '*')]
        parallel.RunTasksInProcessPool(self.CopyToDevice,
                                       input_list,
                                       processes=DEGREE_OF_PARALLELISM)
        logging.info('Assembling these chunks now.....')
        chunks = '%s/%s*' % (dest, chunk_prefix)
        final_dest = '%s/%s' % (dest, src_filename)
        assemble_cmd = ['cat', chunks, '>', final_dest]
        self.run(assemble_cmd)
        cleanup_cmd = ['rm', '-f', chunks]
        self.run(cleanup_cmd)
      except IOError:
        logging.err('Could not complete the payload transfer...')
        raise
    logging.info('Successfully copy %s to %s in chunks in parallel', src, dest)
Exemple #20
0
def SignAndroidImage(rootfs_dir, keyset, vboot_path=None):
    """If there is an android image, sign it."""
    system_img = os.path.join(rootfs_dir,
                              'opt/google/containers/android/system.raw.img')
    if not os.path.exists(system_img):
        logging.info('ARC image not found.  Not signing Android APKs.')
        return

    arc_version = key_value_store.LoadFile(
        os.path.join(rootfs_dir,
                     'etc/lsb-release')).get('CHROMEOS_ARC_VERSION', '')
    if not arc_version:
        logging.warning('CHROMEOS_ARC_VERSION not found in lsb-release. '
                        'Not signing Android APKs.')
        return

    extra_env = _PathForVbootSigningScripts(vboot_path)
    logging.info('Found ARC image version %s, resigning APKs', arc_version)
    # Sign the Android APKs using ${keyset.key_dir}/android keys.
    android_keydir = os.path.join(keyset.key_dir, 'android')
    logging.info('Using %s', android_keydir)

    # TODO(lamontjones) migrate sign_android_image.sh.
    cros_build_lib.run(['sign_android_image.sh', rootfs_dir, android_keydir],
                       extra_env=extra_env)
Exemple #21
0
    def _AddProjectsToPartialManifests(self, atoms):
        """Add projects corresponding to a list of atoms to the local manifest.

    If we mark projects as workon that we don't have in our local checkout,
    it is convenient to have them added to the manifest.  Note that users
    will need to `repo sync` to pull down repositories added in this way.

    Args:
      atoms: iterable of atoms to ensure are in the manifest.
    """
        if git.ManifestCheckout.IsFullManifest(self._src_root):
            # If we're a full manifest, there is nothing to do.
            return

        should_repo_sync = False
        for ebuild_path in self._AtomsToEbuilds(atoms):
            infos = portage_util.GetRepositoryForEbuild(
                ebuild_path, self._sysroot)
            for info in infos:
                if not info.project:
                    continue
                cmd = ['loman', 'add', '--workon', info.project]
                cros_build_lib.run(cmd, print_cmd=False)
                should_repo_sync = True

        if should_repo_sync:
            print('Please run "repo sync" now.')
Exemple #22
0
def CreateSnapshot(chroot=None, replace_if_needed=False):
    """Create a logical volume snapshot of a chroot.

  Args:
    chroot (chroot_lib.Chroot): The chroot to perform the operation on.
    replace_if_needed (bool): If true, will replace the existing chroot with
      a new one capable of being mounted as a loopback image if needed.

  Returns:
    str - The name of the snapshot created.
  """
    _EnsureSnapshottableState(chroot, replace=replace_if_needed)

    snapshot_token = str(uuid.uuid4())
    logging.info('Creating SDK snapshot with token ID: %s', snapshot_token)

    cmd = [
        os.path.join(constants.CHROMITE_BIN_DIR, 'cros_sdk'),
        '--snapshot-create',
        snapshot_token,
    ]
    if chroot:
        cmd.extend(['--chroot', chroot.path])

    cros_build_lib.run(cmd)

    return snapshot_token
Exemple #23
0
def CreateChrootSnapshot(snapshot_name, chroot_vg, chroot_lv):
    """Create a snapshot for the specified chroot VG/LV.

  Args:
    snapshot_name: The name of the new snapshot.
    chroot_vg: The name of the VG containing the origin LV.
    chroot_lv: The name of the origin LV.

  Returns:
    True if the snapshot was created, or False if a snapshot with the same
    name already exists.

  Raises:
    SystemExit: The lvcreate command failed.
  """
    if snapshot_name in ListChrootSnapshots(chroot_vg, chroot_lv):
        logging.error(
            'Cannot create snapshot %s: A volume with that name already '
            'exists.', snapshot_name)
        return False

    cmd = [
        'lvcreate', '-s', '--name', snapshot_name,
        '%s/%s' % (chroot_vg, chroot_lv)
    ]
    try:
        logging.notice('Creating snapshot %s from %s in VG %s.', snapshot_name,
                       chroot_lv, chroot_vg)
        cros_build_lib.run(cmd, print_cmd=False, capture_output=True)
        return True
    except cros_build_lib.RunCommandError:
        raise SystemExit('Running %r failed!' % cmd)
Exemple #24
0
def main(argv):
    # Parse arguments to respect log levels.
    commandline.ArgumentParser().parse_args(argv)

    # Regenerate `config_dump.json`.
    logging.info('Regenerating config_dump.json')
    site_config = chromeos_config.GetConfig()
    site_config.SaveConfigToFile(constants.CHROMEOS_CONFIG_FILE)

    # Regenerate `waterfall_layout_dump.txt`.
    logging.info('Regenerating waterfall_layout_dump.txt')
    cmd = os.path.join(constants.CHROMITE_BIN_DIR,
                       'cros_show_waterfall_layout')
    result = cros_build_lib.run([cmd],
                                capture_output=True,
                                encoding='utf-8',
                                debug_level=logging.DEBUG)
    osutils.WriteFile(constants.WATERFALL_CONFIG_FILE, result.stdout)

    # Regenerate `luci-scheduler.cfg`.
    logging.info('Regenerating luci-scheduler.cfg')
    cmd = os.path.join(constants.CHROMITE_SCRIPTS_DIR, 'gen_luci_scheduler')
    luci_result = cros_build_lib.run([cmd],
                                     capture_output=True,
                                     encoding='utf-8',
                                     debug_level=logging.DEBUG)
    osutils.WriteFile(constants.LUCI_SCHEDULER_CONFIG_FILE, luci_result.stdout)
Exemple #25
0
def RunMoblabVmTest(chroot, vms, builder, image_cache_dir, results_dir):
  """Run Moblab VM tests.

  Args:
    chroot (chroot_lib.Chroot): The chroot in which to run tests.
    builder (str): The builder path, used to find artifacts on GS.
    vms (MoblabVm): The Moblab VMs to test.
    image_cache_dir (str): Path to artifacts cache.
    results_dir (str): Path to output test results.
  """
  with vms.RunVmsContext():
    # TODO(evanhernandez): Move many of these arguments to test config.
    test_args = [
        # moblab in VM takes longer to bring up all upstart services on first
        # boot than on physical machines.
        'services_init_timeout_m=10',
        'target_build="%s"' % builder,
        'test_timeout_hint_m=90',
        'clear_devserver_cache=False',
        'image_storage_server="%s"' % (image_cache_dir.rstrip('/') + '/'),
    ]
    cros_build_lib.run(
        [
            'test_that',
            '--no-quickmerge',
            '--results_dir', results_dir,
            '-b', 'moblab-generic-vm',
            'localhost:%s' % vms.moblab_ssh_port,
            'moblab_DummyServerNoSspSuite',
            '--args', ' '.join(test_args),
        ],
        enter_chroot=True,
        chroot_args=chroot.get_enter_args(),
    )
Exemple #26
0
 def testPopenMockBinaryData(self):
     """Verify our automatic encoding in PopenMock works with bytes."""
     self.rc.AddCmdResult(['/x'], error=b'\xff')
     result = cros_build_lib.run(['/x'], capture_output=True)
     self.assertEqual(b'', result.stdout)
     self.assertEqual(b'\xff', result.stderr)
     with self.assertRaises(UnicodeDecodeError):
         cros_build_lib.run(['/x'], capture_output=True, encoding='utf-8')
Exemple #27
0
def Revert(gclient, cwd):
    """Revert all local changes.

  Args:
    gclient: Path to gclient.
    cwd: Directory to revert.
  """
    cros_build_lib.run([gclient, 'revert', '--nohooks'], cwd=cwd)
Exemple #28
0
  def _Build(self):
    """Build chrome."""
    if not self.build:
      return

    build_target = self.chrome_test_target or 'chromiumos_preflight'
    cros_build_lib.run(['autoninja', '-C', self.build_dir, build_target],
                       dryrun=self.dryrun)
Exemple #29
0
def RunChrootVersionHooks(version_file=None, hooks_dir=None):
    """Run the chroot version hooks to bring the chroot up to date."""
    if not cros_build_lib.IsInsideChroot():
        command = ['run_chroot_version_hooks']
        cros_build_lib.run(command, enter_chroot=True)
    else:
        chroot = ChrootUpdater(version_file=version_file, hooks_dir=hooks_dir)
        chroot.ApplyUpdates()
Exemple #30
0
 def testRunCommandCapture(self):
     """Check capturing run() subprocess output."""
     with self.OutputCapturer():
         cros_build_lib.run(['sh', '-c', 'echo foo; echo bar >&2'])
     self.AssertOutputContainsLine('foo')
     self.AssertOutputContainsLine('bar',
                                   check_stdout=False,
                                   check_stderr=True)