1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3# Copyright (c) 2024 Huawei Device Co., Ltd. 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 argparse 17import os 18import subprocess 19import sys 20 21if __name__ == '__main__': 22 parser = argparse.ArgumentParser( 23 description='A script to execute a command via xcrun.') 24 parser.add_argument('--stamp', action='store', type=str, 25 help='Write a stamp file to this path on success.') 26 parser.add_argument('--developer_dir', required=False, 27 help='Path to Xcode.') 28 args, unknown_args = parser.parse_known_args() 29 30 if args.developer_dir: 31 os.environ['DEVELOPER_DIR'] = args.developer_dir 32 33 rv = subprocess.check_call(['xcrun'] + unknown_args) 34 flags = os.O_RDWR | os.O_CREAT | os.O_EXCL 35 modes = stat.S_IWUSR | stat.S_IRUSR 36 if rv == 0 and args.stamp: 37 if os.path.exists(args.stamp): 38 os.unlink(args.stamp) 39 with os.fdopen(os.open(args.stamp, flags, modes), 'w+') as fp: 40 sys.exit(rv) 41