Skip to content

Commit

Permalink
Updated runfilees::rlocation! uses
Browse files Browse the repository at this point in the history
  • Loading branch information
UebelAndre committed Sep 8, 2024
1 parent afacd58 commit 309420b
Show file tree
Hide file tree
Showing 16 changed files with 51 additions and 36 deletions.
2 changes: 1 addition & 1 deletion crate_universe/src/api/lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion crate_universe/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
15 changes: 10 additions & 5 deletions crate_universe/src/splicing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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([
Expand Down
5 changes: 3 additions & 2 deletions crate_universe/src/splicing/crate_index_lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions crate_universe/src/splicing/splicer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
8 changes: 7 additions & 1 deletion crate_universe/tests/cargo_integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ fn run(repository_name: &str, manifests: HashMap<String, String>, 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"),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand All @@ -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(),
Expand All @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down
8 changes: 3 additions & 5 deletions examples/hello_runfiles/hello_runfiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions examples/proto/helloworld/helloworld_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion test/bzl_version/bzl_version_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};

Expand Down
4 changes: 2 additions & 2 deletions test/bzlmod_repo_mapping/module_b/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
std::fs::read_to_string(runfiles::rlocation!(r, "aliased_c/MODULE.bazel").unwrap()).unwrap()
}
6 changes: 4 additions & 2 deletions test/process_wrapper/rustc_quit_on_rmeta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ mod test {
]
.iter()
.collect::<PathBuf>()
);
)
.unwrap();

let process_wrapper = runfiles::rlocation!(
r,
Expand All @@ -45,7 +46,8 @@ mod test {
]
.iter()
.collect::<PathBuf>()
);
)
.unwrap();

let output = Command::new(process_wrapper)
.args(process_wrapper_args)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
10 changes: 5 additions & 5 deletions test/rust/src/greeter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ impl Greeter {
///
/// let greeter = Greeter::from_txt_file()?;
/// ```
pub fn from_txt_file() -> std::io::Result<Greeter> {
pub fn from_txt_file() -> runfiles::Result<Greeter> {
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)?,
})
}

Expand Down
3 changes: 2 additions & 1 deletion tools/rust_analyzer/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> =
serde_json::from_str(&std::fs::read_to_string(path)?)?;

Expand Down
8 changes: 4 additions & 4 deletions tools/rustfmt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}",
Expand Down Expand Up @@ -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(),
}
}
Expand All @@ -90,7 +90,7 @@ pub fn find_manifests() -> Vec<PathBuf> {
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()
Expand Down
2 changes: 1 addition & 1 deletion tools/upstream_wrapper/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}",
Expand Down

0 comments on commit 309420b

Please sign in to comment.