fork/rules_rust
git clone https://git.julia.blue/fork/rules_rust
69ddb09d
main
1# Copyright 2020 The Bazel Authors. All rights reserved. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15"""Process wrapper test.""" 16 17def _process_wrapper_tester_impl ( ctx ): 18args = ctx . actions . args () 19outputs = [] 20combined = ctx . attr . test_config == "combined" 21 22if combined or ctx . attr . test_config == "stdout" : 23stdout_output = ctx . actions . declare_file ( ctx . label . name + ".stdout" ) 24outputs . append ( stdout_output ) 25args . add ( "--stdout-file" , stdout_output ) 26 27if combined or ctx . attr . test_config == "stderr" : 28stderr_output = ctx . actions . declare_file ( ctx . label . name + ".stderr" ) 29outputs . append ( stderr_output ) 30args . add ( "--stderr-file" , stderr_output ) 31 32if combined or ( ctx . attr . test_config != "stdout" and ctx . attr . test_config != "stderr" ): 33touch_output = ctx . actions . declare_file ( ctx . label . name + ".touch" ) 34outputs . append ( touch_output ) 35args . add ( "--touch-file" , touch_output ) 36if ctx . attr . test_config == "copy-output" : 37copy_output = ctx . actions . declare_file ( ctx . label . name + ".touch.copy" ) 38outputs . append ( copy_output ) 39args . add_all ( "--copy-output" , [ touch_output , copy_output ]) 40 41if combined or ctx . attr . test_config == "env-files" : 42args . add_all ( ctx . files . env_files , before_each = "--env-file" ) 43 44if combined or ctx . attr . test_config == "arg-files" : 45args . add_all ( ctx . files . arg_files , before_each = "--arg-file" ) 46 47if combined or ctx . attr . test_config == "subst-pwd" : 48args . add ( "--subst" , "pwd=${pwd}" ) 49args . add ( "--subst" , "key=value" ) 50 51args . add ( "--" ) 52 53args . add ( ctx . executable . _process_wrapper_tester ) 54args . add ( ctx . attr . test_config ) 55args . add ( "--current-dir" , "${pwd}" ) 56args . add ( "--test-subst" , "subst key to ${key}" ) 57 58extra_args = ctx . actions . args () 59if combined or ctx . attr . test_config == "subst-pwd" : 60extra_args . set_param_file_format ( "multiline" ) 61extra_args . use_param_file ( "@%s" , use_always = True ) 62extra_args . add ( "${pwd}" ) 63 64env = { "CURRENT_DIR" : "${pwd}/test_path" } 65 66ctx . actions . run ( 67mnemonic = "RustcProcessWrapperTester" , 68executable = ctx . executable . _process_wrapper , 69inputs = ctx . files . env_files + ctx . files . arg_files , 70outputs = outputs , 71arguments = [ args , extra_args ], 72env = env , 73tools = [ ctx . executable . _process_wrapper_tester ], 74) 75 76return [ DefaultInfo ( files = depset ( outputs ))] 77 78process_wrapper_tester = rule ( 79implementation = _process_wrapper_tester_impl , 80doc = "This rule unit tests the different process_wrapper functionality." , 81attrs = { 82"arg_files" : attr . label_list ( 83doc = "Files containing newline delimited arguments." , 84), 85"env_files" : attr . label_list ( 86doc = "Files containing newline delimited environment key/value pairs." , 87), 88"test_config" : attr . string ( 89doc = "The desired test configuration." , 90mandatory = True , 91values = [ 92"arg-files" , 93"basic" , 94"combined" , 95"copy-output" , 96"env-files" , 97"stderr" , 98"stdout" , 99"subst-pwd" , 100], 101), 102"use_param_file" : attr . bool ( 103doc = "Whether or not to use a params file with the process wrapper." , 104default = False , 105), 106"_process_wrapper" : attr . label ( 107default = Label ( "//util/process_wrapper" ), 108executable = True , 109allow_single_file = True , 110cfg = "exec" , 111), 112"_process_wrapper_tester" : attr . label ( 113default = Label ( "//test/process_wrapper:process_wrapper_tester" ), 114executable = True , 115cfg = "exec" , 116), 117}, 118)