Introduce artifact_path() for rust
This makes it so that rust tests inside of AOS do not have to care about
whether the repository is named "aos", "org_frc971", etc. This also
takes the opportunity to fix up the C++ equivalent to not even have the
repo name hard-coded in the library.
Change-Id: Ie3114c6a420fa46c1cc0f7acfe8115232b10eae3
Signed-off-by: James Kuszmaul <james.kuszmaul@bluerivertech.com>
diff --git a/aos/testing/BUILD b/aos/testing/BUILD
index eb9e2b2..729c978 100644
--- a/aos/testing/BUILD
+++ b/aos/testing/BUILD
@@ -1,3 +1,4 @@
+load("//tools/build_rules:clean_dep.bzl", "aos_repo_name")
load("//tools/rust:defs.bzl", "rust_library")
cc_library(
@@ -127,6 +128,7 @@
name = "path",
srcs = ["path.cc"],
hdrs = ["path.h"],
+ local_defines = ["AOS_REPO_NAME=\\\"" + aos_repo_name() + "\\\""],
target_compatible_with = ["@platforms//os:linux"],
visibility = ["//visibility:public"],
deps = [
@@ -135,6 +137,14 @@
)
rust_library(
+ name = "path_rs",
+ srcs = ["path.rs"],
+ crate_name = "aos_testing_path",
+ rustc_env = {"AOS_REPO_NAME": aos_repo_name()},
+ visibility = ["//visibility:public"],
+)
+
+rust_library(
name = "aos_rs",
testonly = True,
srcs = ["aos.rs"],
@@ -143,6 +153,7 @@
gen_doctests = False,
visibility = ["//visibility:public"],
deps = [
+ ":path_rs",
"//aos:aos_rs",
"//aos:test_init_rs",
],
diff --git a/aos/testing/aos.rs b/aos/testing/aos.rs
index 6c7795d..b9e4264 100644
--- a/aos/testing/aos.rs
+++ b/aos/testing/aos.rs
@@ -4,4 +4,5 @@
/// Utilities for testing an AOS application.
pub mod testing {
pub use aos_test_init as init;
+ pub use aos_testing_path as path;
}
diff --git a/aos/testing/path.cc b/aos/testing/path.cc
index cb17c73..b8c4336 100644
--- a/aos/testing/path.cc
+++ b/aos/testing/path.cc
@@ -7,9 +7,7 @@
// Returns the path to the provided artifact which works when built both as an
// external target and in the repo.
std::string ArtifactPath(std::string_view path) {
- // TODO(austin): Don't hard-code the repo name here since it likely will
- // change.
- return absl::StrCat("../org_frc971/", path);
+ return absl::StrCat("../" AOS_REPO_NAME "/", path);
}
} // namespace aos::testing
diff --git a/aos/testing/path.rs b/aos/testing/path.rs
new file mode 100644
index 0000000..c8da1e9
--- /dev/null
+++ b/aos/testing/path.rs
@@ -0,0 +1,9 @@
+use std::path::{Path, PathBuf};
+
+/// Returns the correct path for a data file within AOS, accounting for whether AOS is
+/// imported as an external repository.
+pub fn artifact_path(path: &Path) -> PathBuf {
+ Path::new("..")
+ .join(Path::new(env!("AOS_REPO_NAME")))
+ .join(path)
+}