-
Notifications
You must be signed in to change notification settings - Fork 402
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expand arg location in rustc_flags attribute (#809)
Expand locations in rustc_flags. Fixes #801.
- Loading branch information
Showing
12 changed files
with
155 additions
and
27 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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)", | ||
], | ||
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 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 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