Exemplo n.º 1
0
def _eager_fileset_with_spec(spec_path, filespec, snapshot, include_dirs=False):
  rel_include_globs = filespec['globs']

  relpath_adjusted_filespec = FilesetRelPathWrapper.to_filespec(rel_include_globs, spec_path)
  if 'exclude' in filespec:
    relpath_adjusted_filespec['exclude'] = [FilesetRelPathWrapper.to_filespec(e['globs'], spec_path)
                                            for e in filespec['exclude']]

  return EagerFilesetWithSpec(spec_path,
                              relpath_adjusted_filespec,
                              snapshot,
                              include_dirs=include_dirs)
Exemplo n.º 2
0
def _eager_fileset_with_spec(spec_path, filespec, snapshot, include_dirs=False):
  rel_include_globs = filespec['globs']

  relpath_adjusted_filespec = FilesetRelPathWrapper.to_filespec(rel_include_globs, spec_path)
  if 'exclude' in filespec:
    relpath_adjusted_filespec['exclude'] = [FilesetRelPathWrapper.to_filespec(e['globs'], spec_path)
                                            for e in filespec['exclude']]

  return EagerFilesetWithSpec(spec_path,
                              relpath_adjusted_filespec,
                              snapshot,
                              include_dirs=include_dirs)
Exemplo n.º 3
0
def _eager_fileset_with_spec(spec_path, filespec, snapshot, include_dirs=False):
  fds = snapshot.path_stats if include_dirs else snapshot.files
  files = tuple(fast_relpath(fd.path, spec_path) for fd in fds)

  relpath_adjusted_filespec = FilesetRelPathWrapper.to_filespec(filespec['globs'], spec_path)
  if filespec.has_key('exclude'):
    relpath_adjusted_filespec['exclude'] = [FilesetRelPathWrapper.to_filespec(e['globs'], spec_path)
                                            for e in filespec['exclude']]

  return EagerFilesetWithSpec(spec_path,
                              relpath_adjusted_filespec,
                              files=files,
                              files_hash=snapshot.fingerprint)
Exemplo n.º 4
0
def _eager_fileset_with_spec(spec_path, filespec, snapshot, include_dirs=False):
  fds = snapshot.path_stats if include_dirs else snapshot.files
  files = tuple(fast_relpath(fd.path, spec_path) for fd in fds)

  relpath_adjusted_filespec = FilesetRelPathWrapper.to_filespec(filespec['globs'], spec_path)
  if filespec.has_key('exclude'):
    relpath_adjusted_filespec['exclude'] = [FilesetRelPathWrapper.to_filespec(e['globs'], spec_path)
                                            for e in filespec['exclude']]

  return EagerFilesetWithSpec(spec_path,
                              relpath_adjusted_filespec,
                              files=files,
                              files_hash=snapshot.fingerprint)
Exemplo n.º 5
0
def _eager_fileset_with_spec(spec_path, filespec, snapshot):
  files = tuple(fast_relpath(fd.path, spec_path) for fd in snapshot.files)

  relpath_adjusted_filespec = FilesetRelPathWrapper.to_filespec(filespec['globs'], spec_path)
  if filespec.has_key('exclude'):
    relpath_adjusted_filespec['exclude'] = [FilesetRelPathWrapper.to_filespec(e['globs'], spec_path)
                                            for e in filespec['exclude']]

  # NB: In order to preserve declared ordering, we record a list of matched files
  # independent of the file hash dict.
  return EagerFilesetWithSpec(spec_path,
                              relpath_adjusted_filespec,
                              files=files,
                              files_hash=snapshot.fingerprint)
Exemplo n.º 6
0
  def _capture_sources(self, targets_and_dirs):
    to_capture = []
    results_dirs = []
    filespecs = []

    for target, synthetic_target_dir in targets_and_dirs:
      if self.sources_globs is None:
        files = list(self.find_sources(target, synthetic_target_dir))
      else:
        files = self.sources_globs

      results_dir_relpath = os.path.relpath(synthetic_target_dir, get_buildroot())
      buildroot_relative_globs = tuple(os.path.join(results_dir_relpath, file) for file in files)
      buildroot_relative_excludes = tuple(
        os.path.join(results_dir_relpath, file)
          for file in self.sources_exclude_globs
      )
      to_capture.append(
        PathGlobsAndRoot(
          PathGlobs(buildroot_relative_globs, buildroot_relative_excludes),
          text_type(get_buildroot()),
        )
      )
      results_dirs.append(results_dir_relpath)
      filespecs.append(FilesetRelPathWrapper.to_filespec(buildroot_relative_globs))

    snapshots = self.context._scheduler.capture_snapshots(tuple(to_capture))

    return tuple(EagerFilesetWithSpec(
      results_dir_relpath,
      filespec,
      snapshot,
    ) for (results_dir_relpath, filespec, snapshot) in zip(results_dirs, filespecs, snapshots))
Exemplo n.º 7
0
  def _capture_sources(self, targets_and_dirs):
    to_capture = []
    results_dirs = []
    filespecs = []

    for target, synthetic_target_dir in targets_and_dirs:
      files = self.sources_globs

      results_dir_relpath = os.path.relpath(synthetic_target_dir, get_buildroot())
      buildroot_relative_globs = tuple(os.path.join(results_dir_relpath, file) for file in files)
      buildroot_relative_excludes = tuple(
        os.path.join(results_dir_relpath, file)
          for file in self.sources_exclude_globs
      )
      to_capture.append(
        PathGlobsAndRoot(
          PathGlobs(buildroot_relative_globs, buildroot_relative_excludes),
          text_type(get_buildroot()),
        )
      )
      results_dirs.append(results_dir_relpath)
      filespecs.append(FilesetRelPathWrapper.to_filespec(buildroot_relative_globs))

    snapshots = self.context._scheduler.capture_snapshots(tuple(to_capture))

    return tuple(EagerFilesetWithSpec(
      results_dir_relpath,
      filespec,
      snapshot,
    ) for (results_dir_relpath, filespec, snapshot) in zip(results_dirs, filespecs, snapshots))
Exemplo n.º 8
0
def _eager_fileset_with_spec(spec_path, filespec, source_files_digest, excluded_source_files):
  excluded = {f.path for f in excluded_source_files.dependencies}
  file_tuples = [(fast_relpath(fd.path, spec_path), fd.digest)
                 for fd in source_files_digest.dependencies
                 if fd.path not in excluded]

  relpath_adjusted_filespec = FilesetRelPathWrapper.to_filespec(filespec['globs'], spec_path)
  if filespec.has_key('exclude'):
    relpath_adjusted_filespec['exclude'] = [FilesetRelPathWrapper.to_filespec(e['globs'], spec_path)
                                            for e in filespec['exclude']]

  # NB: In order to preserve declared ordering, we record a list of matched files
  # independent of the file hash dict.
  return EagerFilesetWithSpec(spec_path,
                              relpath_adjusted_filespec,
                              files=tuple(f for f, _ in file_tuples),
                              file_hashes=dict(file_tuples))
Exemplo n.º 9
0
def _eager_fileset_with_spec(spec_path, filespec, source_files_digest, excluded_source_files):
  excluded = {f.path for f in excluded_source_files.dependencies}
  file_tuples = [(fast_relpath(fd.path, spec_path), fd.digest)
                 for fd in source_files_digest.dependencies
                 if fd.path not in excluded]

  relpath_adjusted_filespec = FilesetRelPathWrapper.to_filespec(filespec['globs'], spec_path)
  if filespec.has_key('exclude'):
    relpath_adjusted_filespec['exclude'] = [FilesetRelPathWrapper.to_filespec(e['globs'], spec_path)
                                            for e in filespec['exclude']]

  # NB: In order to preserve declared ordering, we record a list of matched files
  # independent of the file hash dict.
  return EagerFilesetWithSpec(spec_path,
                              relpath_adjusted_filespec,
                              files=tuple(f for f, _ in file_tuples),
                              file_hashes=dict(file_tuples))
Exemplo n.º 10
0
def _eager_fileset_with_spec(
    spec_path: str,
    filespec: Filespec,
    snapshot: Snapshot,
    include_dirs: bool = False,
) -> EagerFilesetWithSpec:
    rel_include_globs = filespec["globs"]

    relpath_adjusted_filespec = FilesetRelPathWrapper.to_filespec(
        rel_include_globs, spec_path)
    if "exclude" in filespec:
        relpath_adjusted_filespec["exclude"] = [
            FilesetRelPathWrapper.to_filespec(e["globs"], spec_path)
            for e in filespec["exclude"]
        ]

    return EagerFilesetWithSpec(spec_path,
                                relpath_adjusted_filespec,
                                snapshot,
                                include_dirs=include_dirs)
Exemplo n.º 11
0
    def filespec(self) -> Filespec:
        """The original globs, returned in the Filespec dict format.

        The globs will be relativized to the build root.
        """
        includes = []
        excludes = []
        for glob in self.sanitized_raw_value or ():
            if glob.startswith("!"):
                excludes.append(glob[1:])
            else:
                includes.append(glob)
        return FilesetRelPathWrapper.to_filespec(args=includes,
                                                 exclude=[excludes],
                                                 root=self.address.spec_path)
Exemplo n.º 12
0
  def _create_sources_with_fingerprint(self, target_workdir, fingerprint, files):
    """Create an EagerFilesetWithSpec to pass to the sources argument for synthetic target injection.

    We are creating and passing an EagerFilesetWithSpec to the synthetic target injection in the
    hopes that it will save the time of having to refingerprint the sources.

    :param target_workdir: The directory containing the generated code for the target.
    :param fingerprint: the fingerprint of the VersionedTarget with which the EagerFilesetWithSpec
           will be created.
    :param files: a list of exact paths to generated sources.
    """
    results_dir_relpath = os.path.relpath(target_workdir, get_buildroot())
    filespec = FilesetRelPathWrapper.to_filespec(
      [os.path.join(results_dir_relpath, file) for file in files])
    return EagerFilesetWithSpec(results_dir_relpath, filespec=filespec,
      files=files, files_hash='{}.{}'.format(fingerprint.id, fingerprint.hash))
Exemplo n.º 13
0
  def _create_sources_with_fingerprint(self, target_workdir, fingerprint, files):
    """Create an EagerFilesetWithSpec to pass to the sources argument for synthetic target injection.

    We are creating and passing an EagerFilesetWithSpec to the synthetic target injection in the
    hopes that it will save the time of having to refingerprint the sources.

    :param target_workdir: The directory containing the generated code for the target.
    :param fingerprint: the fingerprint of the VersionedTarget with which the EagerFilesetWithSpec
           will be created.
    :param files: a list of exact paths to generated sources.
    """
    results_dir_relpath = os.path.relpath(target_workdir, get_buildroot())
    filespec = FilesetRelPathWrapper.to_filespec(
      [os.path.join(results_dir_relpath, file) for file in files])
    return EagerFilesetWithSpec(results_dir_relpath, filespec=filespec,
      files=files, files_hash='{}.{}'.format(fingerprint.id, fingerprint.hash))
Exemplo n.º 14
0
    def _capture_sources(self, vts):
        to_capture = []
        results_dirs = []
        filespecs = []

        for vt in vts:
            target = vt.target
            # Compute the (optional) subdirectory of the results_dir to generate code to. This
            # path will end up in the generated FilesetWithSpec and target, and thus needs to be
            # located below the stable/symlinked `vt.results_dir`.
            synthetic_target_dir = self.synthetic_target_dir(
                target, vt.results_dir)

            files = self.sources_globs

            results_dir_relpath = fast_relpath(synthetic_target_dir,
                                               get_buildroot())
            buildroot_relative_globs = tuple(
                os.path.join(results_dir_relpath, file) for file in files)
            buildroot_relative_excludes = tuple(
                os.path.join(results_dir_relpath, file)
                for file in self.sources_exclude_globs)
            to_capture.append(
                PathGlobsAndRoot(
                    PathGlobs(buildroot_relative_globs,
                              buildroot_relative_excludes),
                    text_type(get_buildroot()),
                    # The digest is stored adjacent to the hash-versioned `vt.current_results_dir`.
                    Digest.load(vt.current_results_dir),
                ))
            results_dirs.append(results_dir_relpath)
            filespecs.append(
                FilesetRelPathWrapper.to_filespec(buildroot_relative_globs))

        snapshots = self.context._scheduler.capture_snapshots(
            tuple(to_capture))

        for snapshot, vt in zip(snapshots, vts):
            snapshot.directory_digest.dump(vt.current_results_dir)

        return tuple(
            EagerFilesetWithSpec(
                results_dir_relpath,
                filespec,
                snapshot,
            ) for (results_dir_relpath, filespec,
                   snapshot) in zip(results_dirs, filespecs, snapshots))
Exemplo n.º 15
0
  def _capture_sources(self, vts):
    to_capture = []
    results_dirs = []
    filespecs = []

    for vt in vts:
      target = vt.target
      # Compute the (optional) subdirectory of the results_dir to generate code to. This
      # path will end up in the generated FilesetWithSpec and target, and thus needs to be
      # located below the stable/symlinked `vt.results_dir`.
      synthetic_target_dir = self.synthetic_target_dir(target, vt.results_dir)

      files = self.sources_globs

      results_dir_relpath = fast_relpath(synthetic_target_dir, get_buildroot())
      buildroot_relative_globs = tuple(os.path.join(results_dir_relpath, file) for file in files)
      buildroot_relative_excludes = tuple(
        os.path.join(results_dir_relpath, file)
          for file in self.sources_exclude_globs
      )
      to_capture.append(
        PathGlobsAndRoot(
          PathGlobs(buildroot_relative_globs, buildroot_relative_excludes),
          text_type(get_buildroot()),
          # The digest is stored adjacent to the hash-versioned `vt.current_results_dir`.
          Digest.load(vt.current_results_dir),
        )
      )
      results_dirs.append(results_dir_relpath)
      filespecs.append(FilesetRelPathWrapper.to_filespec(buildroot_relative_globs))

    snapshots = self.context._scheduler.capture_snapshots(tuple(to_capture))

    for snapshot, vt in zip(snapshots, vts):
      snapshot.directory_digest.dump(vt.current_results_dir)

    return tuple(EagerFilesetWithSpec(
      results_dir_relpath,
      filespec,
      snapshot,
    ) for (results_dir_relpath, filespec, snapshot) in zip(results_dirs, filespecs, snapshots))