fork/rules_rust
git clone https://git.julia.blue/fork/rules_rust
5a9d999d
0.9.0
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 17This rule unit tests the different process_wrapper functionality. 18""" 19 20def _impl ( ctx ): 21args = ctx . actions . args () 22outputs = [] 23combined = ctx . attr . test_config == "combined" 24 25if combined or ctx . attr . test_config == "stdout" : 26stdout_output = ctx . actions . declare_file ( ctx . label . name + ".stdout" ) 27outputs . append ( stdout_output ) 28args . add ( "--stdout-file" , stdout_output . path ) 29 30if combined or ctx . attr . test_config == "stderr" : 31stderr_output = ctx . actions . declare_file ( ctx . label . name + ".stderr" ) 32outputs . append ( stderr_output ) 33args . add ( "--stderr-file" , stderr_output . path ) 34 35if combined or ( ctx . attr . test_config != "stdout" and ctx . attr . test_config != "stderr" ): 36touch_output = ctx . actions . declare_file ( ctx . label . name + ".touch" ) 37outputs . append ( touch_output ) 38args . add ( "--touch-file" , touch_output . path ) 39if ctx . attr . test_config == "copy-output" : 40copy_output = ctx . actions . declare_file ( ctx . label . name + ".touch.copy" ) 41outputs . append ( copy_output ) 42args . add_all ( "--copy-output" , [ touch_output . path , copy_output . path ]) 43 44if combined or ctx . attr . test_config == "env-files" : 45args . add_all ( ctx . files . env_files , before_each = "--env-file" ) 46 47if combined or ctx . attr . test_config == "arg-files" : 48args . add_all ( ctx . files . arg_files , before_each = "--arg-file" ) 49 50if combined or ctx . attr . test_config == "subst-pwd" : 51args . add ( "--subst" , "pwd=${pwd}" ) 52args . add ( "--subst" , "key=value" ) 53 54args . add ( "--" ) 55 56args . add ( ctx . executable . _process_wrapper_tester . path ) 57args . add ( ctx . attr . test_config ) 58args . add ( "--current-dir" , "${pwd}" ) 59args . add ( "--test-subst" , "subst key to ${key}" ) 60env = { "CURRENT_DIR" : "${pwd}/test_path" } 61 62ctx . actions . run ( 63executable = ctx . executable . _process_wrapper , 64inputs = ctx . files . env_files + ctx . files . arg_files , 65outputs = outputs , 66arguments = [ args ], 67env = env , 68tools = [ ctx . executable . _process_wrapper_tester ], 69) 70 71return [ DefaultInfo ( files = depset ( outputs ))] 72 73process_wrapper_tester = rule ( 74implementation = _impl , 75attrs = { 76"arg_files" : attr . label_list (), 77"env_files" : attr . label_list (), 78"test_config" : attr . string ( mandatory = True ), 79"_process_wrapper" : attr . label ( 80default = Label ( "//util/process_wrapper" ), 81executable = True , 82allow_single_file = True , 83cfg = "exec" , 84), 85"_process_wrapper_tester" : attr . label ( 86default = Label ( "//test/process_wrapper:process_wrapper_tester" ), 87executable = True , 88cfg = "exec" , 89), 90}, 91)