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

rustdoc_test: substitute the root of the current crate #1777

Merged
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/rustdoc_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ def _construct_writer_arguments(ctx, test_runner, opt_test_params, action, crate
# Collect and dedupe all of the file roots in a list before appending
# them to args to prevent generating a large amount of identical args
roots = []
root = crate_info.output.root.path
if not root in roots:
roots.append(root)
for dep in crate_info.deps.to_list():
dep_crate_info = getattr(dep, "crate_info", None)
dep_dep_info = getattr(dep, "dep_info", None)
Expand Down
3 changes: 3 additions & 0 deletions test/unit/rustdoc/rustdoc_build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("cargo:rustc-env=CONST=xyz");
}
3 changes: 3 additions & 0 deletions test/unit/rustdoc/rustdoc_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ use rustdoc_proc_macro::make_answer;
#[cfg(feature = "with_proc_macro")]
make_answer!();

#[cfg(feature = "with_build_script")]
pub const CONST: &str = env!("CONST");

/// The answer to the ultimate question
/// ```
/// fn answer() -> u32 { 42 }
Expand Down
28 changes: 28 additions & 0 deletions test/unit/rustdoc/rustdoc_nodep_lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#[cfg(feature = "with_proc_macro")]
use rustdoc_proc_macro::make_answer;

#[cfg(feature = "with_proc_macro")]
make_answer!();

#[cfg(feature = "with_build_script")]
pub const CONST: &str = env!("CONST");

/// The answer to the ultimate question
/// ```
/// fn answer() -> u32 { 42 }
/// assert_eq!(answer(), 42);
/// ```
#[cfg(not(feature = "with_proc_macro"))]
pub fn answer() -> u32 {
42
}

#[cfg(test)]
mod test {
use super::*;

#[test]
fn test_answer() {
assert_eq!(answer(), 42);
}
}
46 changes: 46 additions & 0 deletions test/unit/rustdoc/rustdoc_unit_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

load("@bazel_skylib//lib:unittest.bzl", "analysistest")
load("@rules_cc//cc:defs.bzl", "cc_library")
load("//cargo:defs.bzl", "cargo_build_script")
load("//rust:defs.bzl", "rust_binary", "rust_doc", "rust_doc_test", "rust_library", "rust_proc_macro", "rust_test")
load(
"//test/unit:common.bzl",
Expand Down Expand Up @@ -118,6 +119,12 @@ def _define_targets():
rustdoc_deps = [":adder"],
)

_target_maker(
rust_library,
name = "nodep_lib",
srcs = ["rustdoc_nodep_lib.rs"],
)

_target_maker(
rust_proc_macro,
name = "rustdoc_proc_macro",
Expand All @@ -133,6 +140,14 @@ def _define_targets():
crate_features = ["with_proc_macro"],
)

_target_maker(
rust_library,
name = "lib_nodep_with_proc_macro",
srcs = ["rustdoc_nodep_lib.rs"],
proc_macro_deps = [":rustdoc_proc_macro"],
crate_features = ["with_proc_macro"],
)

_target_maker(
rust_binary,
name = "bin_with_transitive_proc_macro",
Expand All @@ -157,6 +172,37 @@ def _define_targets():
deps = [":cc_lib"],
)

_target_maker(
rust_library,
name = "lib_nodep_with_cc",
srcs = ["rustdoc_nodep_lib.rs"],
crate_features = ["with_cc"],
deps = [":cc_lib"],
)

cargo_build_script(
name = "lib_build_script",
srcs = ["rustdoc_build.rs"],
edition = "2018",
)

_target_maker(
rust_library,
name = "lib_with_build_script",
srcs = ["rustdoc_lib.rs"],
rustdoc_deps = [":adder"],
crate_features = ["with_build_script"],
deps = [":lib_build_script"],
)

_target_maker(
rust_library,
name = "lib_nodep_with_build_script",
srcs = ["rustdoc_nodep_lib.rs"],
crate_features = ["with_build_script"],
deps = [":lib_build_script"],
)

def rustdoc_test_suite(name):
"""Entry-point macro called from the BUILD file.

Expand Down