def __init__(self, script=None, sources=None, address=None, payload=None, **kwargs): if sources is not None: raise TargetDefinitionException( self, "sources must be None: was {!r}.".format(sources)) elif script and script.endswith(self.script_file_ext): script_relpath_buildroot = os.path.join(address.spec_path, script) base_globs = BaseGlobs.from_sources_field( [script_relpath_buildroot], address.spec_path) fileset_with_spec = LazyFilesetWithSpec(address.spec_path, base_globs.filespecs, lambda: [script]) else: raise TargetDefinitionException( self, "script argument '{}' to {}() must end in '{}'.".format( script, self.alias(), self.script_file_ext)) payload = payload or Payload() payload.add_fields({ 'sources': SourcesField(fileset_with_spec, address), }) super(Perl6Binary, self).__init__(address=address, payload=payload, **kwargs)
def test_passes_lazy_fileset_with_spec_through(self): self.create_file('foo/a.txt', 'a_contents') fileset = LazyFilesetWithSpec('foo', {'globs':['foo/a.txt']}, lambda: ['foo/a.txt']) sf = SourcesField(sources=fileset) self.assertIs(fileset, sf.sources) self.assertEqual(['foo/a.txt'], list(sf.source_paths))
def test_lazy_fileset_with_spec_fails_if_exclude_filespec_not_prefixed_by_relroot( self): with self.assertRaises(ValueError): LazyFilesetWithSpec('foo', { 'globs': [], 'exclude': [{ 'globs': ['notfoo/a.txt'] }] }, lambda: ['foo/a.txt'])
def test_passes_lazy_fileset_with_spec_through(self) -> None: self.create_file("foo/a.txt", "a_contents") fileset = LazyFilesetWithSpec("foo", {"globs": ["foo/a.txt"]}, lambda: ["foo/a.txt"]) sf = SourcesField(sources=fileset) self.assertIs(fileset, sf.sources) self.assertEqual(["foo/a.txt"], list(sf.source_paths))
def test_lazy_fileset_with_spec_fails_if_exclude_filespec_not_prefixed_by_relroot( self) -> None: with self.assertRaises(ValueError): LazyFilesetWithSpec( "foo", { "globs": [], "exclude": [{ "globs": ["notfoo/a.txt"] }] }, lambda: ["foo/a.txt"], )