Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge runfiles from transitive dependencies of rust_test crate attr #1487

Merged
merged 8 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,9 @@ def rustc_compile_action(
files = getattr(ctx.files, "data", []) + coverage_runfiles,
collect_data = True,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to attempt to remove it in this change? Or an isolated change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really sure I understand the implications of using "collect_data" here, so I left it alone.

)
if getattr(ctx.attr, "crate", None):
runfiles = runfiles.merge(ctx.attr.crate[DefaultInfo].default_runfiles)
runfiles = runfiles.merge(ctx.attr.crate[DefaultInfo].data_runfiles)

# TODO: Remove after some resolution to
# https://github.com/bazelbuild/rules_rust/issues/771
Expand Down
2 changes: 2 additions & 0 deletions test/rust/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ rust_library(
"src/greeter.rs",
"src/lib.rs",
],
data = ["greeting.txt"],
edition = "2018",
deps = ["//tools/runfiles"],
)

rust_binary(
Expand Down
1 change: 1 addition & 0 deletions test/rust/greeting.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Welcome
23 changes: 23 additions & 0 deletions test/rust/src/greeter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@ impl Greeter {
}
}

/// Constructs a new `Greeter` with greeting defined in txt file
///
/// # Examples
///
/// ```
/// use hello_lib::greeter::Greeter;
///
/// let greeter = Greeter::from_txt_file()?;
/// ```
pub fn from_txt_file() -> std::io::Result<Greeter> {
Ok(Greeter {
greeting: std::fs::read_to_string(
runfiles::Runfiles::create()?.rlocation("rules_rust/test/rust/greeting.txt"),
)?,
})
}

/// Returns the greeting as a string.
///
/// # Examples
Expand Down Expand Up @@ -72,4 +89,10 @@ mod test {
let hello = Greeter::new("Hi");
assert_eq!("Hi Rust", hello.greeting("Rust"));
}

#[test]
fn test_greeting_from_txt_file() {
let welcome = Greeter::from_txt_file().unwrap();
assert_eq!("Welcome Rust", welcome.greeting("Rust"));
Copy link
Contributor Author

@neilisaac neilisaac Aug 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

backporting this commit (with the test only) to main, I see:

thread 'greeter::test::test_greeting_from_txt_file' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', test/rust/src/greeter.rs:93:48

}
}