Exemplo n.º 1
0
async def hydrate_sources(
        sources_field: SourcesField,
        glob_match_error_behavior: GlobMatchErrorBehavior) -> HydratedField:
    """Given a SourcesField, request a Snapshot for its path_globs and create an EagerFilesetWithSpec.
  """
    # TODO(#5864): merge the target's selection of --glob-expansion-failure (which doesn't exist yet)
    # with the global default!
    path_globs = dataclasses.replace(
        sources_field.path_globs,
        glob_match_error_behavior=glob_match_error_behavior)
    snapshot = await Get(Snapshot, PathGlobs, path_globs)
    fileset_with_spec = _eager_fileset_with_spec(
        sources_field.address.spec_path, sources_field.filespecs, snapshot)
    sources_field.validate_fn(fileset_with_spec)
    return HydratedField(sources_field.arg, fileset_with_spec)
Exemplo n.º 2
0
 def sources_for(self, package_relative_path_globs, package_dir=''):
   sources_field = SourcesField(
     Address.parse('{}:_bogus_target_for_test'.format(package_dir)),
     'sources',
     {'globs': package_relative_path_globs},
     None,
     PathGlobs(tuple(os.path.join(package_dir, path) for path in package_relative_path_globs)),
     lambda _: True,
   )
   field = self.scheduler.product_request(HydratedField, [sources_field])[0]
   return field.value
Exemplo n.º 3
0
 def sources_for(
     self, package_relative_path_globs: List[str], package_dir: str = "",
 ) -> EagerFilesetWithSpec:
     sources_field = SourcesField(
         address=BuildFileAddress(
             rel_path=os.path.join(package_dir, "BUILD"), target_name="_bogus_target_for_test",
         ),
         arg="sources",
         source_globs=SourceGlobs(*package_relative_path_globs),
     )
     field = self.scheduler.product_request(HydratedField, [sources_field])[0]
     return cast(EagerFilesetWithSpec, field.value)
Exemplo n.º 4
0
async def hydrate_sources(
    sources_field: SourcesField,
    glob_match_error_behavior: GlobMatchErrorBehavior,
) -> HydratedField:
    """Given a SourcesField, request a Snapshot for its path_globs and create an EagerFilesetWithSpec.
  """
    address = sources_field.address
    path_globs = dataclasses.replace(
        sources_field.path_globs,
        glob_match_error_behavior=glob_match_error_behavior,
        # TODO(#9012): add line number referring to the sources field.
        description_of_origin=
        (f"{address.rel_path} for target {address.relative_spec}'s `{sources_field.arg}` field"
         ),
    )
    snapshot = await Get[Snapshot](PathGlobs, path_globs)
    fileset_with_spec = _eager_fileset_with_spec(
        spec_path=address.spec_path,
        filespec=sources_field.filespecs,
        snapshot=snapshot,
    )
    sources_field.validate_fn(fileset_with_spec)
    return HydratedField(sources_field.arg, fileset_with_spec)
Exemplo n.º 5
0
async def hydrate_sources(
    sources_field: SourcesField,
    glob_match_error_behavior: GlobMatchErrorBehavior,
) -> HydratedField:
    """Given a SourcesField, request a Snapshot for its path_globs and create an
    EagerFilesetWithSpec."""
    address = sources_field.address
    path_globs = dataclasses.replace(
        sources_field.path_globs,
        glob_match_error_behavior=glob_match_error_behavior,
        # TODO(#9012): add line number referring to the sources field. When doing this, we'll likely
        # need to `await Get[BuildFileAddress](Address)`.
        description_of_origin=(f"{address}'s `{sources_field.arg}` field"
                               if glob_match_error_behavior !=
                               GlobMatchErrorBehavior.ignore else None),
    )
    snapshot = await Get[Snapshot](PathGlobs, path_globs)
    fileset_with_spec = _eager_fileset_with_spec(
        spec_path=address.spec_path,
        filespec=sources_field.source_globs.filespecs,
        snapshot=snapshot,
    )
    sources_field.validate_fn(fileset_with_spec)
    return HydratedField(sources_field.arg, fileset_with_spec)
Exemplo n.º 6
0
 def sources_for(
   self, package_relative_path_globs: List[str], package_dir: str = '',
 ) -> EagerFilesetWithSpec:
   sources_field = SourcesField(
     address=Address.parse(f'{package_dir}:_bogus_target_for_test'),
     arg='sources',
     filespecs={'globs': package_relative_path_globs},
     base_globs=None,
     path_globs=PathGlobs(
       tuple(os.path.join(package_dir, path) for path in package_relative_path_globs),
     ),
     validate_fn=lambda _: True,
   )
   field = self.scheduler.product_request(HydratedField, [sources_field])[0]
   return cast(EagerFilesetWithSpec, field.value)
Exemplo n.º 7
0
 def sources_for(
     self,
     package_relative_path_globs: List[str],
     package_dir: str = '',
 ) -> EagerFilesetWithSpec:
     sources_field = SourcesField(
         address=BuildFileAddress(
             rel_path=os.path.join(package_dir, "BUILD"),
             target_name="_bogus_target_for_test",
         ),
         arg='sources',
         filespecs={'globs': package_relative_path_globs},
         base_globs=Files(spec_path=package_dir),
         path_globs=PathGlobs(
             tuple(
                 os.path.join(package_dir, path)
                 for path in package_relative_path_globs), ),
         validate_fn=lambda _: True,
     )
     field = self.scheduler.product_request(HydratedField,
                                            [sources_field])[0]
     return cast(EagerFilesetWithSpec, field.value)