fork/rules_rust
git clone https://git.julia.blue/fork/rules_rust
03a70796
rust-analyzer
1"""Unittest to verify location expansion in rustc flags""" 2 3load ( "@bazel_skylib//lib:unittest.bzl" , "analysistest" ) 4load ( "//rust:defs.bzl" , "rust_library" ) 5load ( "//test/unit:common.bzl" , "assert_action_mnemonic" , "assert_argv_contains" ) 6 7def _location_expansion_rustc_flags_test ( ctx ): 8env = analysistest . begin ( ctx ) 9tut = analysistest . target_under_test ( env ) 10action = tut . actions [ 0 ] 11assert_action_mnemonic ( env , action , "Rustc" ) 12assert_argv_contains ( env , action , "test/unit/location_expansion/mylibrary.rs" ) 13expected = "@${pwd}/" + ctx . bin_dir . path + "/test/unit/location_expansion/generated_flag.data" 14assert_argv_contains ( env , action , expected ) 15return analysistest . end ( env ) 16 17location_expansion_rustc_flags_test = analysistest . make ( _location_expansion_rustc_flags_test ) 18 19def _location_expansion_test (): 20native . genrule ( 21name = "flag_generator" , 22outs = [ "generated_flag.data" ], 23cmd = "echo --cfg=test_flag > $@" , 24) 25 26rust_library ( 27name = "mylibrary" , 28srcs = [ "mylibrary.rs" ], 29edition = "2018" , 30rustc_flags = [ 31"@$(location :flag_generator)" , 32], 33compile_data = [ ":flag_generator" ], 34) 35 36location_expansion_rustc_flags_test ( 37name = "location_expansion_rustc_flags_test" , 38target_under_test = ":mylibrary" , 39) 40 41def location_expansion_test_suite ( name ): 42"""Entry-point macro called from the BUILD file. 43 44Args: 45name: Name of the macro. 46""" 47_location_expansion_test () 48 49native . test_suite ( 50name = name , 51tests = [ 52":location_expansion_rustc_flags_test" , 53], 54)