Fix runfiles creation for directory based runfiles. (#2883)
closes https://github.com/bazelbuild/rules_rust/issues/2868
diff --git a/tools/runfiles/runfiles.rs b/tools/runfiles/runfiles.rs
index 94d8f2a..5c85762 100644
--- a/tools/runfiles/runfiles.rs
+++ b/tools/runfiles/runfiles.rs
@@ -162,6 +162,10 @@
};
let repo_mapping = raw_rlocation(&mode, "_repo_mapping")
+ // This is the only place directory based runfiles might do file IO for a runfile. In the
+ // event that a `_repo_mapping` file does not exist, a default map should be created. Otherwise
+ // if the file is known to exist, parse it and raise errors for users should parsing fail.
+ .filter(|f| f.exists())
.map(parse_repo_mapping)
.transpose()?
.unwrap_or_default();