@@ -129,6 +129,14 @@ def lookup(self, source_repo: str, target_apparent: str) -> Optional[str]:
129129 # No mapping found
130130 return None
131131
132+ def is_empty (self ) -> bool :
133+ """Check if this repository mapping is empty (no exact or prefixed mappings).
134+
135+ Returns:
136+ True if there are no mappings, False otherwise
137+ """
138+ return len (self ._exact_mappings ) == 0 and len (self ._prefixed_mappings ) == 0
139+
132140
133141class _ManifestBased :
134142 """`Runfiles` strategy that parses a runfiles-manifest to look up runfiles."""
@@ -286,7 +294,7 @@ def Rlocation(self, path: str, source_repo: Optional[str] = None) -> Optional[st
286294 if os .path .isabs (path ):
287295 return path
288296
289- if source_repo is None and self ._repo_mapping is not None :
297+ if source_repo is None and not self ._repo_mapping . is_empty () :
290298 # Look up runfiles using the repository mapping of the caller of the
291299 # current method. If the repo mapping is empty, determining this
292300 # name is not necessary.
@@ -295,11 +303,20 @@ def Rlocation(self, path: str, source_repo: Optional[str] = None) -> Optional[st
295303 # Split off the first path component, which contains the repository
296304 # name (apparent or canonical).
297305 target_repo , _ , remainder = path .partition ("/" )
298- if not remainder :
299- # path did not contain a slash and referred to a root symlink,
300- # which should not be mapped.
306+ if not remainder or self ._repo_mapping .lookup (source_repo , target_repo ) is None :
307+ # One of the following is the case:
308+ # - not using Bzlmod, so the repository mapping is empty and
309+ # apparent and canonical repository names are the same
310+ # - target_repo is already a canonical repository name and does not
311+ # have to be mapped.
312+ # - path did not contain a slash and referred to a root symlink,
313+ # which also should not be mapped.
301314 return self ._strategy .RlocationChecked (path )
302315
316+ assert (
317+ source_repo is not None
318+ ), "BUG: if the `source_repo` is None, we should never go past the `if` statement above"
319+
303320 # Look up the target repository using the repository mapping
304321 if source_repo is not None :
305322 target_canonical = self ._repo_mapping .lookup (source_repo , target_repo )
0 commit comments