Skip to content

Commit e6f947e

Browse files
committed
Consider compile_data when deciding if sources are generated
This fixes issue where generated compile_data didn't work in some cases.
1 parent 749a0ec commit e6f947e

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

rust/private/utils.bzl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,11 @@ def transform_sources(ctx, srcs, compile_data, crate_root):
811811
Tuple(List[File], List[File], File): The transformed srcs, compile_data
812812
and crate_root
813813
"""
814-
has_generated_sources = len([src for src in srcs if not src.is_source]) > 0
814+
has_generated_sources = (
815+
len([src for src in srcs if not src.is_source]) +
816+
len([src for src in compile_data if not src.is_source]) >
817+
0
818+
)
815819

816820
if not has_generated_sources:
817821
return srcs, compile_data, crate_root
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/// Data loaded from generated compile data
2+
pub const COMPILE_DATA: &str = include_str!("generated.txt");
3+
4+
#[cfg(test)]
5+
mod test {
6+
use super::*;
7+
8+
#[test]
9+
fn test_compile_data_contents() {
10+
assert_eq!(COMPILE_DATA.trim_end(), "generated compile data contents");
11+
}
12+
}

test/unit/compile_data/compile_data_test.bzl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,24 @@ def _define_test_targets():
9595
crate = ":compile_data_env",
9696
)
9797

98+
native.genrule(
99+
name = "generated_compile_data",
100+
outs = ["generated.txt"],
101+
cmd = "echo 'generated compile data contents' > $@",
102+
)
103+
104+
rust_library(
105+
name = "compile_data_gen",
106+
srcs = ["compile_data_gen.rs"],
107+
compile_data = [":generated.txt"],
108+
edition = "2021",
109+
)
110+
111+
rust_test(
112+
name = "compile_data_gen_unit_test",
113+
crate = ":compile_data_gen",
114+
)
115+
98116
native.genrule(
99117
name = "generated_src",
100118
outs = ["generated.rs"],

test/unit/location_expansion/location_expansion_test.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ load("//test/unit:common.bzl", "assert_action_mnemonic", "assert_argv_contains")
88
def _location_expansion_rustc_flags_test(ctx):
99
env = analysistest.begin(ctx)
1010
tut = analysistest.target_under_test(env)
11-
action = tut.actions[0]
11+
action = tut.actions[1]
1212
assert_action_mnemonic(env, action, "Rustc")
13-
assert_argv_contains(env, action, "test/unit/location_expansion/mylibrary.rs")
13+
assert_argv_contains(env, action, ctx.bin_dir.path + "/test/unit/location_expansion/mylibrary.rs")
1414
expected = "@${pwd}/" + ctx.bin_dir.path + "/test/unit/location_expansion/generated_flag.data"
1515
assert_argv_contains(env, action, expected)
1616
return analysistest.end(env)

0 commit comments

Comments
 (0)