def set_mapper(self, fast=False): self.mapper = LazySourceMapper(self.address_mapper, self.build_graph, stop_after_match=fast)
def _mapper(self): if self._mapper_cache is None: self._mapper_cache = LazySourceMapper(self._address_mapper, self._build_graph, self._fast) return self._mapper_cache
class LazySourceMapperTest(BaseTest): @property def alias_groups(self): return BuildFileAliases.create(targets={ 'java_library': JavaLibrary, }, ) def setUp(self): super(LazySourceMapperTest, self).setUp() self.set_mapper() def set_mapper(self, fast=False): self.mapper = LazySourceMapper(self.address_mapper, self.build_graph, stop_after_match=fast) def owner(self, owner, f): self.assertEqual( set(owner), set(i.spec for i in self.mapper.target_addresses_for_source(f))) def test_joint_ownership(self): # A simple target with two sources. self.create_library('lib/rpc', 'java_library', 'rpc', ['err.py', 'http.py']) # Another target with sources but also claims one already owned from above. self.create_library('lib', 'java_library', 'lib', ['a.py', 'b.py', 'rpc/net.py', 'rpc/err.py']) # Sole ownership of new files. self.owner(['lib:lib'], 'lib/a.py') self.owner(['lib:lib'], 'lib/rpc/net.py') self.owner(['lib/rpc:rpc'], 'lib/rpc/http.py') # Joint ownership of overlap file self.owner(['lib/rpc:rpc', 'lib:lib'], 'lib/rpc/err.py') # An unclaimed file in same dir is not claimed. self.create_file('lib/rpc/json.py') self.owner([], 'lib/rpc/json.py') def test_nested(self): # A root-level BUILD file's sources are found or not correctly. self.create_library('date', 'java_library', 'date', ['day.py', 'time/unit/hour.py']) self.create_file('date/time/unit/minute.py') # Shallow, simple source still works. self.owner(['date:date'], 'date/day.py') # Nested claimed source works. self.owner(['date:date'], 'date/time/unit/hour.py') # Unclaimed nested sibling correctly unclaimed. self.owner([], 'date/time/unit/minute.py') def test_with_root_level_build(self): self.create_library('', 'java_library', 'top', ['foo.py', 'text/common/const/emoji.py']) self.create_library('text', 'java_library', 'text', ['localize.py']) self.create_library('text/common/const', 'java_library', 'const', ['emoji.py', 'ascii.py']) self.create_library('text/common/helper', 'java_library', 'helper', ['trunc.py']) self.create_file('bar.py') self.owner(['text/common/helper:helper'], 'text/common/helper/trunc.py') self.owner([':top', 'text/common/const:const'], 'text/common/const/emoji.py') self.owner([':top'], 'foo.py') self.owner([], 'bar.py') def test_fast_vs_correct(self): self.create_library('', 'java_library', 'top', ['foo.py', 'a/b/bar.py']) self.create_library('a/b', 'java_library', 'b', ['bar.py', 'baz.py']) # With fast=False, order doesn't matter. self.set_mapper(fast=False) self.owner([':top', 'a/b:b'], 'a/b/bar.py') self.owner([':top'], 'foo.py') self.set_mapper(fast=False) self.owner([':top'], 'foo.py') self.owner([':top', 'a/b:b'], 'a/b/bar.py') # With fast=False, loading a parent first vs after now affects results. self.set_mapper(fast=True) self.owner(['a/b:b'], 'a/b/bar.py') self.owner([':top'], 'foo.py') self.owner([':top', 'a/b:b'], 'a/b/bar.py')
def set_mapper(self, fast=False): self.mapper = LazySourceMapper(self.context(), stop_after_match=fast)
def _mapper(self): if self._mapper_cache is None: self._mapper_cache = LazySourceMapper(self.context, self.get_options().fast) return self._mapper_cache
class LazySourceMapperTest(BaseTest): @property def alias_groups(self): return BuildFileAliases.create( targets={ 'java_library': JavaLibrary, }, ) def setUp(self): super(LazySourceMapperTest, self).setUp() self.set_mapper() def set_mapper(self, fast=False): self.mapper = LazySourceMapper(self.address_mapper, self.build_graph, stop_after_match=fast) def owner(self, owner, f): self.assertEqual(set(owner), set(i.spec for i in self.mapper.target_addresses_for_source(f))) def test_joint_ownership(self): # A simple target with two sources. self.create_library('lib/rpc', 'java_library', 'rpc', ['err.py', 'http.py']) # Another target with sources but also claims one already owned from above. self.create_library('lib', 'java_library', 'lib', ['a.py', 'b.py', 'rpc/net.py', 'rpc/err.py']) # Sole ownership of new files. self.owner(['lib:lib'], 'lib/a.py') self.owner(['lib:lib'], 'lib/rpc/net.py') self.owner(['lib/rpc:rpc'], 'lib/rpc/http.py') # Joint ownership of overlap file self.owner(['lib/rpc:rpc', 'lib:lib'], 'lib/rpc/err.py') # An unclaimed file in same dir is not claimed. self.create_file('lib/rpc/json.py') self.owner([], 'lib/rpc/json.py') def test_nested(self): # A root-level BUILD file's sources are found or not correctly. self.create_library('date', 'java_library', 'date', ['day.py','time/unit/hour.py']) self.create_file('date/time/unit/minute.py') # Shallow, simple source still works. self.owner(['date:date'], 'date/day.py') # Nested claimed source works. self.owner(['date:date'], 'date/time/unit/hour.py') # Unclaimed nested sibling correctly unclaimed. self.owner([], 'date/time/unit/minute.py') def test_with_root_level_build(self): self.create_library('', 'java_library', 'top', ['foo.py', 'text/common/const/emoji.py']) self.create_library('text', 'java_library', 'text', ['localize.py']) self.create_library('text/common/const', 'java_library', 'const', ['emoji.py', 'ascii.py']) self.create_library('text/common/helper', 'java_library', 'helper', ['trunc.py']) self.create_file('bar.py') self.owner(['text/common/helper:helper'], 'text/common/helper/trunc.py') self.owner([':top', 'text/common/const:const'], 'text/common/const/emoji.py') self.owner([':top'], 'foo.py') self.owner([], 'bar.py') def test_fast_vs_correct(self): self.create_library('', 'java_library', 'top', ['foo.py', 'a/b/bar.py']) self.create_library('a/b', 'java_library', 'b', ['bar.py', 'baz.py']) # With fast=False, order doesn't matter. self.set_mapper(fast=False) self.owner([':top', 'a/b:b'], 'a/b/bar.py') self.owner([':top'], 'foo.py') self.set_mapper(fast=False) self.owner([':top'], 'foo.py') self.owner([':top', 'a/b:b'], 'a/b/bar.py') # With fast=False, loading a parent first vs after now affects results. self.set_mapper(fast=True) self.owner(['a/b:b'], 'a/b/bar.py') self.owner([':top'], 'foo.py') self.owner([':top', 'a/b:b'], 'a/b/bar.py')