1# 2# Copyright (C) 2022 The Android Open Source Project 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16import subprocess 17import sys 18 19 20def run_ninja(context, config, targets): 21 """Run ninja.""" 22 23 nsjail = context.tools.nsjail 24 # Write the nsjail config 25 nsjail_config_file = context.out.nsjail_config_file() 26 config.generate_config(nsjail_config_file) 27 28 # Construct the command 29 cmd = [ 30 nsjail, "--config", nsjail_config_file, "--", 31 context.tools.ninja(), "--experimentalEnvvar", "-f", 32 context.out.outer_ninja_file() 33 ] + targets 34 35 # Run the command 36 process = subprocess.run(cmd, shell=False, check=False) 37 38 # TODO: Probably want better handling of inner tree failures 39 if process.returncode: 40 sys.stderr.write( 41 "Build error in outer tree.\nstopping multitree build.\n") 42 sys.exit(1) 43