From 309420b5467eba740f86d973d0fef6fea8c3f5c1 Mon Sep 17 00:00:00 2001 From: UebelAndre Date: Sat, 7 Sep 2024 21:01:01 -0700 Subject: [PATCH] Updated `runfilees::rlocation!` uses --- crate_universe/src/api/lockfile.rs | 2 +- crate_universe/src/config.rs | 3 ++- crate_universe/src/splicing.rs | 15 ++++++++++----- crate_universe/src/splicing/crate_index_lookup.rs | 5 +++-- crate_universe/src/splicing/splicer.rs | 4 ++-- crate_universe/tests/cargo_integration_test.rs | 8 +++++++- examples/hello_runfiles/hello_runfiles.rs | 8 +++----- examples/proto/helloworld/helloworld_test.rs | 4 ++-- test/bzl_version/bzl_version_test.rs | 2 +- test/bzlmod_repo_mapping/module_b/lib.rs | 4 ++-- test/process_wrapper/rustc_quit_on_rmeta.rs | 6 ++++-- .../bootstrap_process_wrapper_test.rs | 3 ++- test/rust/src/greeter.rs | 10 +++++----- tools/rust_analyzer/lib.rs | 3 ++- tools/rustfmt/src/lib.rs | 8 ++++---- tools/upstream_wrapper/src/main.rs | 2 +- 16 files changed, 51 insertions(+), 36 deletions(-) diff --git a/crate_universe/src/api/lockfile.rs b/crate_universe/src/api/lockfile.rs index fdb4502d28..83bec82a02 100644 --- a/crate_universe/src/api/lockfile.rs +++ b/crate_universe/src/api/lockfile.rs @@ -144,7 +144,7 @@ mod test { let runfiles = runfiles::Runfiles::create().unwrap(); let path = runfiles::rlocation!( - runfiles, "rules_rust/crate_universe/test_data/cargo_bazel_lockfile/multi_package-cargo-bazel-lock.json"); + runfiles, "rules_rust/crate_universe/test_data/cargo_bazel_lockfile/multi_package-cargo-bazel-lock.json").unwrap(); let parsed = parse(&path).unwrap(); assert_eq!(parsed.workspace_members(), want_workspace_member_names); diff --git a/crate_universe/src/config.rs b/crate_universe/src/config.rs index 25598771b1..8236ee9952 100644 --- a/crate_universe/src/config.rs +++ b/crate_universe/src/config.rs @@ -922,7 +922,8 @@ mod test { let path = runfiles::rlocation!( runfiles, "rules_rust/crate_universe/test_data/serialized_configs/config.json" - ); + ) + .unwrap(); let content = std::fs::read_to_string(path).unwrap(); diff --git a/crate_universe/src/splicing.rs b/crate_universe/src/splicing.rs index eb5e31420b..7f0560f47d 100644 --- a/crate_universe/src/splicing.rs +++ b/crate_universe/src/splicing.rs @@ -487,7 +487,8 @@ mod test { let path = runfiles::rlocation!( runfiles, "rules_rust/crate_universe/test_data/serialized_configs/splicing_manifest.json" - ); + ) + .unwrap(); let content = std::fs::read_to_string(path).unwrap(); @@ -571,7 +572,8 @@ mod test { let path = runfiles::rlocation!( runfiles, "rules_rust/crate_universe/test_data/serialized_configs/splicing_manifest.json" - ); + ) + .unwrap(); let content = std::fs::read_to_string(path).unwrap(); @@ -616,16 +618,19 @@ mod test { let workspace_manifest_path = runfiles::rlocation!( runfiles, "rules_rust/crate_universe/test_data/metadata/workspace_path/Cargo.toml" - ); + ) + .unwrap(); let workspace_path = workspace_manifest_path.parent().unwrap().to_path_buf(); let child_a_manifest_path = runfiles::rlocation!( runfiles, "rules_rust/crate_universe/test_data/metadata/workspace_path/child_a/Cargo.toml" - ); + ) + .unwrap(); let child_b_manifest_path = runfiles::rlocation!( runfiles, "rules_rust/crate_universe/test_data/metadata/workspace_path/child_b/Cargo.toml" - ); + ) + .unwrap(); let manifest = SplicingManifest { direct_packages: BTreeMap::new(), manifests: BTreeMap::from([ diff --git a/crate_universe/src/splicing/crate_index_lookup.rs b/crate_universe/src/splicing/crate_index_lookup.rs index 72f404b78b..05bd34f79f 100644 --- a/crate_universe/src/splicing/crate_index_lookup.rs +++ b/crate_universe/src/splicing/crate_index_lookup.rs @@ -69,7 +69,8 @@ mod test { runfiles::rlocation!( runfiles, "rules_rust/crate_universe/test_data/crate_indexes/lazy_static/cargo_home" - ), + ) + .unwrap(), ); let index = CrateIndexLookup::Http( @@ -97,7 +98,7 @@ mod test { } { let _e = EnvVarResetter::set("CARGO_HOME", - runfiles::rlocation!(runfiles, "rules_rust/crate_universe/test_data/crate_indexes/rewritten_lazy_static/cargo_home")); + runfiles::rlocation!(runfiles, "rules_rust/crate_universe/test_data/crate_indexes/rewritten_lazy_static/cargo_home").unwrap()); let index = CrateIndexLookup::Http( crates_index::SparseIndex::from_url("sparse+https://index.crates.io/").unwrap(), diff --git a/crate_universe/src/splicing/splicer.rs b/crate_universe/src/splicing/splicer.rs index bd6cbcae54..8b4b7ea84f 100644 --- a/crate_universe/src/splicing/splicer.rs +++ b/crate_universe/src/splicing/splicer.rs @@ -765,8 +765,8 @@ mod test { #[cfg(not(feature = "cargo"))] fn get_cargo_and_rustc_paths() -> (PathBuf, PathBuf) { let r = runfiles::Runfiles::create().unwrap(); - let cargo_path = runfiles::rlocation!(r, concat!("rules_rust/", env!("CARGO"))); - let rustc_path = runfiles::rlocation!(r, concat!("rules_rust/", env!("RUSTC"))); + let cargo_path = runfiles::rlocation!(r, concat!("rules_rust/", env!("CARGO"))).unwrap(); + let rustc_path = runfiles::rlocation!(r, concat!("rules_rust/", env!("RUSTC"))).unwrap(); (cargo_path, rustc_path) } diff --git a/crate_universe/tests/cargo_integration_test.rs b/crate_universe/tests/cargo_integration_test.rs index 879d6f8547..2070c80fa6 100644 --- a/crate_universe/tests/cargo_integration_test.rs +++ b/crate_universe/tests/cargo_integration_test.rs @@ -103,7 +103,7 @@ fn run(repository_name: &str, manifests: HashMap, lockfile: &str splice(SpliceOptions { splicing_manifest, - cargo_lockfile: Some(runfiles::rlocation!(runfiles, lockfile)), + cargo_lockfile: Some(runfiles::rlocation!(runfiles, lockfile).unwrap()), repin: None, workspace_dir: None, output_dir: scratch.path().join("out"), @@ -139,6 +139,7 @@ fn feature_generator() { r, "rules_rust/crate_universe/test_data/metadata/target_features/Cargo.toml" ) + .unwrap() .to_string_lossy() .to_string(), "//:test_input".to_string(), @@ -256,6 +257,7 @@ fn feature_generator_cfg_features() { r, "rules_rust/crate_universe/test_data/metadata/target_cfg_features/Cargo.toml" ) + .unwrap() .to_string_lossy() .to_string(), "//:test_input".to_string(), @@ -325,6 +327,7 @@ fn feature_generator_workspace() { r, "rules_rust/crate_universe/test_data/metadata/workspace/Cargo.toml" ) + .unwrap() .to_string_lossy() .to_string(), "//:test_input".to_string(), @@ -334,6 +337,7 @@ fn feature_generator_workspace() { r, "rules_rust/crate_universe/test_data/metadata/workspace/child/Cargo.toml" ) + .unwrap() .to_string_lossy() .to_string(), "//crate_universe:test_data/metadata/workspace/child/Cargo.toml".to_string(), @@ -360,6 +364,7 @@ fn feature_generator_crate_combined_features() { r, "rules_rust/crate_universe/test_data/metadata/crate_combined_features/Cargo.toml" ) + .unwrap() .to_string_lossy() .to_string(), "//:test_input".to_string(), @@ -400,6 +405,7 @@ fn resolver_2_deps() { r, "rules_rust/crate_universe/test_data/metadata/resolver_2_deps/Cargo.toml" ) + .unwrap() .to_string_lossy() .to_string(), "//:test_input".to_string(), diff --git a/examples/hello_runfiles/hello_runfiles.rs b/examples/hello_runfiles/hello_runfiles.rs index 93604a38f4..376c074e7a 100644 --- a/examples/hello_runfiles/hello_runfiles.rs +++ b/examples/hello_runfiles/hello_runfiles.rs @@ -6,11 +6,9 @@ use runfiles::Runfiles; fn main() { let r = Runfiles::create().unwrap(); - let mut f = File::open(runfiles::rlocation!( - r, - "examples/hello_runfiles/hello_runfiles.rs" - )) - .unwrap(); + let mut f = + File::open(runfiles::rlocation!(r, "examples/hello_runfiles/hello_runfiles.rs").unwrap()) + .unwrap(); let mut buffer = String::new(); f.read_to_string(&mut buffer).unwrap(); diff --git a/examples/proto/helloworld/helloworld_test.rs b/examples/proto/helloworld/helloworld_test.rs index 827a0a942e..186b487b4f 100644 --- a/examples/proto/helloworld/helloworld_test.rs +++ b/examples/proto/helloworld/helloworld_test.rs @@ -39,7 +39,7 @@ impl ServerInfo { let mut c = Command::new(runfiles::rlocation!( r, "examples/proto/helloworld/greeter_server/greeter_server" - )) + ).unwrap()) .arg("0") .stdout(Stdio::piped()) .spawn() @@ -70,7 +70,7 @@ impl ServerInfo { let mut cmd0 = Command::new(runfiles::rlocation!( r, "examples/proto/helloworld/greeter_client/greeter_client" - )); + ).unwrap()); let cmd = cmd0.arg(format!("-p={}", self.port)); let output = if let Some(s) = arg { cmd.arg(s) } else { cmd } diff --git a/test/bzl_version/bzl_version_test.rs b/test/bzl_version/bzl_version_test.rs index b551afc21d..85b296b0df 100644 --- a/test/bzl_version/bzl_version_test.rs +++ b/test/bzl_version/bzl_version_test.rs @@ -27,7 +27,7 @@ fn module_bzl_has_correct_version() { let version = std::env::var("VERSION").unwrap(); let module_bazel_text = { let r = Runfiles::create().unwrap(); - let path = runfiles::rlocation!(r, std::env::var("MODULE_BAZEL").unwrap()); + let path = runfiles::rlocation!(r, std::env::var("MODULE_BAZEL").unwrap()).unwrap(); std::fs::read_to_string(path).unwrap() }; diff --git a/test/bzlmod_repo_mapping/module_b/lib.rs b/test/bzlmod_repo_mapping/module_b/lib.rs index 3a555115d9..16400130ee 100644 --- a/test/bzlmod_repo_mapping/module_b/lib.rs +++ b/test/bzlmod_repo_mapping/module_b/lib.rs @@ -2,5 +2,5 @@ use runfiles::Runfiles; pub fn read_file_from_module_c() -> String { let r = Runfiles::create().unwrap(); - std::fs::read_to_string(runfiles::rlocation!(r, "aliased_c/MODULE.bazel")).unwrap() -} \ No newline at end of file + std::fs::read_to_string(runfiles::rlocation!(r, "aliased_c/MODULE.bazel").unwrap()).unwrap() +} diff --git a/test/process_wrapper/rustc_quit_on_rmeta.rs b/test/process_wrapper/rustc_quit_on_rmeta.rs index 9d7b38c5d5..5ea3e2e9d2 100644 --- a/test/process_wrapper/rustc_quit_on_rmeta.rs +++ b/test/process_wrapper/rustc_quit_on_rmeta.rs @@ -29,7 +29,8 @@ mod test { ] .iter() .collect::() - ); + ) + .unwrap(); let process_wrapper = runfiles::rlocation!( r, @@ -45,7 +46,8 @@ mod test { ] .iter() .collect::() - ); + ) + .unwrap(); let output = Command::new(process_wrapper) .args(process_wrapper_args) diff --git a/test/process_wrapper_bootstrap/bootstrap_process_wrapper_test.rs b/test/process_wrapper_bootstrap/bootstrap_process_wrapper_test.rs index 4e5230f14b..c2924b5de0 100644 --- a/test/process_wrapper_bootstrap/bootstrap_process_wrapper_test.rs +++ b/test/process_wrapper_bootstrap/bootstrap_process_wrapper_test.rs @@ -13,7 +13,8 @@ fn test_shebang() { let script = runfiles::rlocation!( rfiles, "rules_rust/util/process_wrapper/private/process_wrapper.sh" - ); + ) + .unwrap(); let content = read_to_string(script).unwrap(); assert!( diff --git a/test/rust/src/greeter.rs b/test/rust/src/greeter.rs index 1bc99ed5c4..886a2bf888 100644 --- a/test/rust/src/greeter.rs +++ b/test/rust/src/greeter.rs @@ -43,13 +43,13 @@ impl Greeter { /// /// let greeter = Greeter::from_txt_file()?; /// ``` - pub fn from_txt_file() -> std::io::Result { + pub fn from_txt_file() -> runfiles::Result { let r = runfiles::Runfiles::create()?; Ok(Greeter { - greeting: std::fs::read_to_string(runfiles::rlocation!( - r, - "rules_rust/test/rust/greeting.txt" - ))?, + greeting: std::fs::read_to_string( + runfiles::rlocation!(r, "rules_rust/test/rust/greeting.txt").unwrap(), + ) + .map_err(runfiles::RunfilesError::RunfileIoError)?, }) } diff --git a/tools/rust_analyzer/lib.rs b/tools/rust_analyzer/lib.rs index 874f85566d..55f1946071 100644 --- a/tools/rust_analyzer/lib.rs +++ b/tools/rust_analyzer/lib.rs @@ -62,7 +62,8 @@ pub fn write_rust_project( let path = runfiles::rlocation!( Runfiles::create()?, "rules_rust/rust/private/rust_analyzer_detect_sysroot.rust_analyzer_toolchain.json" - ); + ) + .unwrap(); let toolchain_info: HashMap = serde_json::from_str(&std::fs::read_to_string(path)?)?; diff --git a/tools/rustfmt/src/lib.rs b/tools/rustfmt/src/lib.rs index eb51bbd1bb..840aa39dfc 100644 --- a/tools/rustfmt/src/lib.rs +++ b/tools/rustfmt/src/lib.rs @@ -21,12 +21,12 @@ pub struct RustfmtConfig { pub fn parse_rustfmt_config() -> RustfmtConfig { let runfiles = runfiles::Runfiles::create().unwrap(); - let rustfmt = runfiles::rlocation!(runfiles, env!("RUSTFMT")); + let rustfmt = runfiles::rlocation!(runfiles, env!("RUSTFMT")).unwrap(); if !rustfmt.exists() { panic!("rustfmt does not exist at: {}", rustfmt.display()); } - let config = runfiles::rlocation!(runfiles, env!("RUSTFMT_CONFIG")); + let config = runfiles::rlocation!(runfiles, env!("RUSTFMT_CONFIG")).unwrap(); if !config.exists() { panic!( "rustfmt config file does not exist at: {}", @@ -71,7 +71,7 @@ pub fn parse_rustfmt_manifest(manifest: &Path) -> RustfmtManifest { edition, sources: lines .into_iter() - .map(|src| runfiles::rlocation!(runfiles, src)) + .map(|src| runfiles::rlocation!(runfiles, src).unwrap()) .collect(), } } @@ -90,7 +90,7 @@ pub fn find_manifests() -> Vec { std::env::var("RUSTFMT_MANIFESTS") .map(|var| { var.split(PATH_ENV_SEP) - .map(|path| runfiles::rlocation!(runfiles, path)) + .map(|path| runfiles::rlocation!(runfiles, path).unwrap()) .collect() }) .unwrap_or_default() diff --git a/tools/upstream_wrapper/src/main.rs b/tools/upstream_wrapper/src/main.rs index 6d6e167c26..d57492dff4 100644 --- a/tools/upstream_wrapper/src/main.rs +++ b/tools/upstream_wrapper/src/main.rs @@ -13,7 +13,7 @@ const PATH_SEPARATOR: &str = ";"; fn main() { let runfiles = runfiles::Runfiles::create().unwrap(); - let wrapped_tool_path = runfiles::rlocation!(runfiles, WRAPPED_TOOL_TARGET); + let wrapped_tool_path = runfiles::rlocation!(runfiles, WRAPPED_TOOL_TARGET).unwrap(); if !wrapped_tool_path.exists() { panic!( "{WRAPPED_TOOL_NAME} does not exist at: {}",