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