예제 #1
0
def BundleAFDOGenerationArtifacts(is_orderfile, chroot, chrome_root,
                                  build_target, output_dir):
    """Generate artifacts for toolchain-related AFDO artifacts.

  Args:
    is_orderfile (boolean): The generation is for orderfile (True) or
    for AFDO (False).
    chroot (chroot_lib.Chroot): The chroot in which the sysroot should be built.
    chrome_root (str): Path to Chrome root.
    build_target (build_target_lib.BuildTarget): The build target.
    output_dir (str): The location outside the chroot where the files should be
      stored.

  Returns:
    list[str]: The list of tarballs of artifacts.
  """
    chroot_args = chroot.get_enter_args()
    with chroot.tempdir() as tempdir:
        if is_orderfile:
            generate_orderfile = toolchain_util.GenerateChromeOrderfile(
                board=build_target.name,
                output_dir=tempdir,
                chrome_root=chrome_root,
                chroot_path=chroot.path,
                chroot_args=chroot_args)

            generate_orderfile.Perform()
        else:
            generate_afdo = toolchain_util.GenerateBenchmarkAFDOProfile(
                board=build_target.name,
                output_dir=tempdir,
                chroot_path=chroot.path,
                chroot_args=chroot_args)

            generate_afdo.Perform()

        files = []
        for path in osutils.DirectoryIterator(tempdir):
            if os.path.isfile(path):
                rel_path = os.path.relpath(path, tempdir)
                files.append(os.path.join(output_dir, rel_path))
        osutils.CopyDirContents(tempdir, output_dir, allow_nonempty=True)

        return files
예제 #2
0
def CreateChromeRoot(chroot, build_target, output_dir):
    """Create the chrome sysroot.

  Args:
    chroot (chroot_lib.Chroot): The chroot in which the sysroot should be built.
    build_target (build_target_lib.BuildTarget): The build target.
    output_dir (str): The location outside the chroot where the files should be
      stored.

  Returns:
    list[str]: The list of created files.

  Raises:
    CrosGenerateSysrootError: When cros_generate_sysroot does not complete
      successfully.
  """
    chroot_args = chroot.get_enter_args()

    extra_env = {'USE': 'chrome_internal'}
    with chroot.tempdir() as tempdir:
        in_chroot_path = os.path.relpath(tempdir, chroot.path)
        cmd = [
            'cros_generate_sysroot', '--out-dir', in_chroot_path, '--board',
            build_target.name, '--deps-only', '--package', constants.CHROME_CP
        ]

        try:
            cros_build_lib.run(cmd,
                               enter_chroot=True,
                               extra_env=extra_env,
                               chroot_args=chroot_args)
        except cros_build_lib.RunCommandError as e:
            raise CrosGenerateSysrootError(
                'Error encountered when running cros_generate_sysroot: %s' % e,
                e)

        files = []
        for path in osutils.DirectoryIterator(tempdir):
            if os.path.isfile(path):
                rel_path = os.path.relpath(path, tempdir)
                files.append(os.path.join(output_dir, rel_path))
        osutils.CopyDirContents(tempdir, output_dir, allow_nonempty=True)

        return files
예제 #3
0
    def Copy(self, src_base, dest_base, path, sloppy=False):
        """Copy artifact(s) from source directory to destination.

    Args:
      src_base: The directory to apply the src glob pattern match in.
      dest_base: The directory to copy matched files to.  |Path.dest|.
      path: A Path instance that specifies what is to be copied.
      sloppy: If set, ignore when mandatory artifacts are missing.

    Returns:
      A list of the artifacts copied.
    """
        copied_paths = []
        src = os.path.join(src_base, path.src)
        if not src.endswith('/') and os.path.isdir(src):
            raise MustNotBeDirError('%s must not be a directory\n'
                                    'Aborting copy...' % (src, ))
        paths = glob.glob(src)
        if not paths:
            if path.optional:
                logging.debug('%s does not exist and is optional.  Skipping.',
                              src)
            elif sloppy:
                logging.warning(
                    '%s does not exist and is required.  Skipping anyway.',
                    src)
            else:
                msg = ('%s does not exist and is required.\n'
                       'You can bypass this error with --sloppy.\n'
                       'Aborting copy...' % src)
                raise MissingPathError(msg)
        elif len(paths) > 1 and path.dest and not path.dest.endswith('/'):
            raise MultipleMatchError(
                'Glob pattern %r has multiple matches, but dest %s '
                'is not a directory.\n'
                'Aborting copy...' % (path.src, path.dest))
        else:
            for p in paths:
                rel_src = os.path.relpath(p, src_base)
                if path.IsBlacklisted(rel_src):
                    continue
                if path.dest is None:
                    rel_dest = rel_src
                elif path.dest.endswith('/'):
                    rel_dest = os.path.join(path.dest, os.path.basename(p))
                else:
                    rel_dest = path.dest
                assert not rel_dest.endswith('/')
                dest = os.path.join(dest_base, rel_dest)

                copied_paths.append(p)
                self.Log(p, dest, os.path.isdir(p))
                if os.path.isdir(p):
                    for sub_path in osutils.DirectoryIterator(p):
                        rel_path = os.path.relpath(sub_path, p)
                        sub_dest = os.path.join(dest, rel_path)
                        if path.IsBlacklisted(rel_path):
                            continue
                        if sub_path.endswith('/'):
                            osutils.SafeMakedirs(sub_dest, mode=self.dir_mode)
                        else:
                            self._CopyFile(sub_path, sub_dest, path)
                else:
                    self._CopyFile(p, dest, path)

        return copied_paths