-
Notifications
You must be signed in to change notification settings - Fork 491
The compile_data
attribute can now be gathered from dependencies
#814
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f2f0234
The `compile_data` attribute can now be gathered from dependencies
UebelAndre 420ee0a
Don't transitively include compile_data from other targets
UebelAndre 672f3ce
Fixed clippy defect
UebelAndre 4cd5498
Added a wrapper test module
UebelAndre 850dc91
Added unittests
UebelAndre 6f04dd6
Merge branch 'main' into data
UebelAndre 231a4c3
Fixed typo
UebelAndre 0b611f0
Merge branch 'main' into data
UebelAndre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
load(":compile_data_test.bzl", "compile_data_test_suite") | ||
|
||
compile_data_test_suite( | ||
name = "compile_data_test_suite", | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/// Data loaded from compile data | ||
pub const COMPILE_DATA: &str = include_str!("compile_data.txt"); | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
|
||
/// A test that is expected to be compiled from a target that does not | ||
/// directly populate the `compile_data` attribute | ||
#[test] | ||
fn test_compile_data_contents() { | ||
assert_eq!(COMPILE_DATA, "compile data contents\n"); | ||
} | ||
|
||
/// An extra module that tests the `rust_test` rule wrapping the | ||
/// `rust_library` is able to provide it's own compile data. | ||
#[cfg(test_compile_data)] | ||
mod test_compile_data { | ||
const TEST_COMPILE_DATA: &str = include_str!("test_compile_data.txt"); | ||
|
||
#[test] | ||
fn test_compile_data_contents() { | ||
assert_eq!(TEST_COMPILE_DATA, "test compile data contents\n"); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
compile data contents |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
"""Unittest to verify compile_data (attribute) propagation""" | ||
|
||
load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts") | ||
load("//rust:defs.bzl", "rust_common", "rust_library", "rust_test") | ||
|
||
def _target_has_compile_data(ctx, expected): | ||
env = analysistest.begin(ctx) | ||
target = analysistest.target_under_test(env) | ||
|
||
# Extract compile_data from a target expected to have a `CrateInfo` provider | ||
crate_info = target[rust_common.crate_info] | ||
compile_data = crate_info.compile_data.to_list() | ||
|
||
# Ensure compile data was correctly propagated to the provider | ||
asserts.equals( | ||
env, | ||
sorted([data.short_path for data in compile_data]), | ||
expected, | ||
) | ||
|
||
return analysistest.end(env) | ||
|
||
def _compile_data_propagates_to_crate_info_test_impl(ctx): | ||
return _target_has_compile_data( | ||
ctx, | ||
["test/unit/compile_data/compile_data.txt"], | ||
) | ||
|
||
def _wrapper_rule_propagates_to_crate_info_test_impl(ctx): | ||
return _target_has_compile_data( | ||
ctx, | ||
["test/unit/compile_data/compile_data.txt"], | ||
) | ||
|
||
def _wrapper_rule_propagates_and_joins_compile_data_test_impl(ctx): | ||
return _target_has_compile_data( | ||
ctx, | ||
[ | ||
"test/unit/compile_data/compile_data.txt", | ||
"test/unit/compile_data/test_compile_data.txt", | ||
], | ||
) | ||
|
||
compile_data_propagates_to_crate_info_test = analysistest.make(_compile_data_propagates_to_crate_info_test_impl) | ||
wrapper_rule_propagates_to_crate_info_test = analysistest.make(_wrapper_rule_propagates_to_crate_info_test_impl) | ||
wrapper_rule_propagates_and_joins_compile_data_test = analysistest.make(_wrapper_rule_propagates_and_joins_compile_data_test_impl) | ||
|
||
def _define_test_targets(): | ||
rust_library( | ||
name = "compile_data", | ||
srcs = ["compile_data.rs"], | ||
compile_data = ["compile_data.txt"], | ||
edition = "2018", | ||
) | ||
|
||
rust_test( | ||
name = "compile_data_unit_test", | ||
crate = ":compile_data", | ||
) | ||
|
||
rust_test( | ||
name = "test_compile_data_unit_test", | ||
compile_data = ["test_compile_data.txt"], | ||
crate = ":compile_data", | ||
rustc_flags = ["--cfg=test_compile_data"], | ||
) | ||
|
||
def compile_data_test_suite(name): | ||
"""Entry-point macro called from the BUILD file. | ||
|
||
Args: | ||
name (str): Name of the macro. | ||
""" | ||
|
||
_define_test_targets() | ||
|
||
compile_data_propagates_to_crate_info_test( | ||
name = "compile_data_propagates_to_crate_info_test", | ||
target_under_test = ":compile_data", | ||
) | ||
|
||
wrapper_rule_propagates_to_crate_info_test( | ||
name = "wrapper_rule_propagates_to_crate_info_test", | ||
target_under_test = ":compile_data_unit_test", | ||
) | ||
|
||
wrapper_rule_propagates_and_joins_compile_data_test( | ||
name = "wrapper_rule_propagates_and_joins_compile_data_test", | ||
target_under_test = ":test_compile_data_unit_test", | ||
) | ||
|
||
native.test_suite( | ||
name = name, | ||
tests = [ | ||
":compile_data_propagates_to_crate_info_test", | ||
":wrapper_rule_propagates_to_crate_info_test", | ||
":wrapper_rule_propagates_and_joins_compile_data_test", | ||
], | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
test compile data contents |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.