Skip to content

Commit db23970

Browse files
authored
Add regression test for compile data in alternate packages (#3193)
1 parent 9ea3a6f commit db23970

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

rust/private/utils.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,8 @@ def _symlink_for_non_generated_source(ctx, src_file, package_root):
865865
File: The created symlink if a non-generated file, or the file itself.
866866
"""
867867

868-
if src_file.is_source or src_file.root.path != ctx.bin_dir.path:
868+
src_short_path = paths.relativize(src_file.path, src_file.root.path)
869+
if (src_file.is_source or src_file.root.path != ctx.bin_dir.path) and paths.starts_with(src_short_path, package_root):
869870
src_short_path = paths.relativize(src_file.path, src_file.root.path)
870871
src_symlink = ctx.actions.declare_file(paths.relativize(src_short_path, package_root))
871872
ctx.actions.symlink(
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
alias(
2+
name = "data",
3+
actual = "data.txt",
4+
visibility = ["//test/unit/compile_data/src:__pkg__"],
5+
)

test/unit/compile_data/data/data.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello World
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
load("@bazel_skylib//rules:write_file.bzl", "write_file")
2+
load("//rust:defs.bzl", "rust_library", "rust_test")
3+
4+
write_file(
5+
name = "lib_rs",
6+
out = "lib.rs",
7+
content = """\
8+
pub const DATA: &str = include_str!(env!(\"COMPILE_DATA\"));
9+
10+
#[cfg(test)]
11+
mod test {
12+
#[test]
13+
fn test_data() {
14+
assert_eq!(super::DATA.trim(), "Hello World");
15+
}
16+
}
17+
""".splitlines(),
18+
newline = "unix",
19+
)
20+
21+
rust_library(
22+
name = "lib",
23+
srcs = [":lib.rs"],
24+
compile_data = ["//test/unit/compile_data/data"],
25+
edition = "2021",
26+
rustc_env = {
27+
"COMPILE_DATA": "$(execpath //test/unit/compile_data/data)",
28+
},
29+
)
30+
31+
rust_test(
32+
name = "test",
33+
crate = ":lib",
34+
edition = "2021",
35+
)

0 commit comments

Comments
 (0)