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): 8 env = analysistest.begin(ctx) 9 tut = analysistest.target_under_test(env) 10 action = tut.actions[0] 11 assert_action_mnemonic(env, action, "Rustc") 12 assert_argv_contains(env, action, "test/unit/location_expansion/mylibrary.rs") 13 expected = "@${pwd}/" + ctx.bin_dir.path + "/test/unit/location_expansion/generated_flag.data" 14 assert_argv_contains(env, action, expected) 15 return analysistest.end(env) 16 17location_expansion_rustc_flags_test = analysistest.make(_location_expansion_rustc_flags_test) 18 19def _location_expansion_test(): 20 native.genrule( 21 name = "flag_generator", 22 outs = ["generated_flag.data"], 23 cmd = "echo --cfg=test_flag > $@", 24 ) 25 26 rust_library( 27 name = "mylibrary", 28 srcs = ["mylibrary.rs"], 29 edition = "2018", 30 rustc_flags = [ 31 "@$(location :flag_generator)", 32 ], 33 compile_data = [":flag_generator"], 34 ) 35 36 location_expansion_rustc_flags_test( 37 name = "location_expansion_rustc_flags_test", 38 target_under_test = ":mylibrary", 39 ) 40 41def location_expansion_test_suite(name): 42 """Entry-point macro called from the BUILD file. 43 44 Args: 45 name: Name of the macro. 46 """ 47 _location_expansion_test() 48 49 native.test_suite( 50 name = name, 51 tests = [ 52 ":location_expansion_rustc_flags_test", 53 ], 54 ) 55