-
Notifications
You must be signed in to change notification settings - Fork 489
Expand arg locations #809
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
Expand arg locations #809
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
74e3b8a
Expand locations in rustc_flags.
sayrer 20eb0fb
Merge branch 'expand_arg_locations' of https://github.com/grafica/rul…
sayrer 1625b23
Address comments.
sayrer 8993cb3
Fix buildifier.
sayrer ae38ad9
Merge branch 'main' into expand_arg_locations
sayrer cd0077e
Rename expand_location to expand_env_locations.
sayrer 28b80f9
Merge branch 'expand_arg_locations' of https://github.com/grafica/rul…
sayrer bd00e63
Separate test.
sayrer f34f71f
Whitespace.
sayrer 16418c0
Try to fix Clippy warning.
sayrer c92bbb8
Rewrite to satisfy clippy.
sayrer 0ce9dad
Remove clippy annotation.
sayrer eddbd6f
Remove unnecessary comment.
sayrer 7bf37a5
Rename location expansion functions.
sayrer 1405620
Add a brief note about expansions.
sayrer f0da18d
Fix import order.
sayrer e3b17e8
Document location expansion.
sayrer 5c1cd61
Regenerate documentation
sayrer cee8af9
Unit test for location expansion.
sayrer d9f2db3
Make this file pass rustfmt.
sayrer 609a8bc
Whitespace.
sayrer b3baa9c
Merge branch 'main' into expand_arg_locations
sayrer ab82e9c
Merge branch 'main' into expand_arg_locations
sayrer 9e6bb39
Address review comments.
sayrer a0666c5
Merge branch 'expand_arg_locations' of https://github.com/grafica/rul…
sayrer afee0a2
Merge branch 'main' into expand_arg_locations
sayrer 5ad52d3
Regenerate documentation
sayrer 93cd938
Merge branch 'expand_arg_locations' of https://github.com/grafica/rul…
sayrer 53b981c
Add two empty lines.
sayrer c9e4cd5
A single newline
sayrer 844d523
Merge branch 'main' into expand_arg_locations
sayrer 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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,23 @@ | ||
load( | ||
"@rules_rust//rust:rust.bzl", | ||
"rust_test", | ||
) | ||
|
||
# generate a file containing cfg flags | ||
genrule( | ||
name = "flag_generator", | ||
outs = ["generated_flag.data"], | ||
cmd = "echo --cfg=test_flag > $@", | ||
) | ||
|
||
rust_test( | ||
name = "test", | ||
srcs = [ | ||
"main.rs", | ||
], | ||
data = [":flag_generator"], | ||
edition = "2018", | ||
rustc_flags = [ | ||
"@$(location :flag_generator)", | ||
], | ||
) |
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,9 @@ | ||
#[test] | ||
fn test() { | ||
// we should be able to read rustc args from a generated file | ||
if cfg!(test_flag) { | ||
return; | ||
} | ||
|
||
unreachable!(); | ||
} |
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,4 @@ | ||
load(":location_expansion_test.bzl", "location_expansion_test_suite") | ||
|
||
############################ UNIT TESTS ############################# | ||
location_expansion_test_suite(name = "location_expansion_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,54 @@ | ||
"""Unittest to verify location expansion in rustc flags""" | ||
|
||
load("@bazel_skylib//lib:unittest.bzl", "analysistest") | ||
load("//rust:defs.bzl", "rust_library") | ||
load("//test/unit:common.bzl", "assert_action_mnemonic", "assert_argv_contains") | ||
|
||
def _location_expansion_rustc_flags_test(ctx): | ||
env = analysistest.begin(ctx) | ||
tut = analysistest.target_under_test(env) | ||
action = tut.actions[0] | ||
argv = action.argv | ||
assert_action_mnemonic(env, action, "Rustc") | ||
assert_argv_contains(env, action, "test/unit/location_expansion/mylibrary.rs") | ||
expected = "@${pwd}/" + ctx.bin_dir.path + "/test/unit/location_expansion/generated_flag.data" | ||
assert_argv_contains(env, action, expected) | ||
return analysistest.end(env) | ||
|
||
location_expansion_rustc_flags_test = analysistest.make(_location_expansion_rustc_flags_test) | ||
|
||
def _location_expansion_test(): | ||
native.genrule( | ||
name = "flag_generator", | ||
outs = ["generated_flag.data"], | ||
cmd = "echo --cfg=test_flag > $@", | ||
) | ||
|
||
rust_library( | ||
name = "mylibrary", | ||
srcs = ["mylibrary.rs"], | ||
rustc_flags = [ | ||
"@$(location :flag_generator)", | ||
sayrer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
], | ||
compile_data = [":flag_generator"], | ||
) | ||
|
||
location_expansion_rustc_flags_test( | ||
name = "location_expansion_rustc_flags_test", | ||
target_under_test = ":mylibrary", | ||
) | ||
|
||
def location_expansion_test_suite(name): | ||
"""Entry-point macro called from the BUILD file. | ||
|
||
Args: | ||
name: Name of the macro. | ||
""" | ||
_location_expansion_test() | ||
|
||
native.test_suite( | ||
name = name, | ||
tests = [ | ||
":location_expansion_rustc_flags_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 @@ | ||
|
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
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.