fork/rules_rust
git clone https://git.julia.blue/fork/rules_rust
b04aa053
rust-analyzer
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}" ) 60 61extra_args = ctx . actions . args () 62if combined or ctx . attr . test_config == "subst-pwd" : 63extra_args . set_param_file_format ( "multiline" ) 64extra_args . use_param_file ( "@%s" , use_always = True ) 65extra_args . add ( "${pwd}" ) 66 67env = { "CURRENT_DIR" : "${pwd}/test_path" } 68 69ctx . actions . run ( 70executable = ctx . executable . _process_wrapper , 71inputs = ctx . files . env_files + ctx . files . arg_files , 72outputs = outputs , 73arguments = [ args , extra_args ], 74env = env , 75tools = [ ctx . executable . _process_wrapper_tester ], 76) 77 78return [ DefaultInfo ( files = depset ( outputs ))] 79 80process_wrapper_tester = rule ( 81implementation = _impl , 82attrs = { 83"arg_files" : attr . label_list (), 84"env_files" : attr . label_list (), 85"test_config" : attr . string ( mandatory = True ), 86"use_param_file" : attr . bool ( default = False ), 87"_process_wrapper" : attr . label ( 88default = Label ( "//util/process_wrapper" ), 89executable = True , 90allow_single_file = True , 91cfg = "exec" , 92), 93"_process_wrapper_tester" : attr . label ( 94default = Label ( "//test/process_wrapper:process_wrapper_tester" ), 95executable = True , 96cfg = "exec" , 97), 98}, 99)