1#!/usr/bin/env python 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 tarfile 17import argparse 18import os 19import subprocess 20import sys 21import shutil 22 23 24def apply_patch(source_dir): 25 patch_list = [ 26 'modifying_driver_search_path.patch', 27 'dll.c.patch', 28 ] 29 30 for patch in patch_list: 31 patch_dir = os.path.join(source_dir, 'patches', patch) 32 patch_dir = os.path.abspath(patch_dir) 33 source_dir = os.path.abspath(source_dir) 34 patch_cmd = ['patch', '-p1', "--fuzz=0", "--no-backup-if-mismatch", '-i', patch_dir, '-d', source_dir] 35 try: 36 result = subprocess.run(patch_cmd, check=True, text=True, capture_output=True) 37 if result.returncode != 0: 38 raise subprocess.CalledProcessError(result.returncode, result.args) 39 except subprocess.CalledProcessError: 40 print("sane-backends: {} apply error!".format(patch)) 41 42def main(): 43 backends_path = argparse.ArgumentParser() 44 backends_path.add_argument('--source-dir', help='generate path of log', required=True) 45 args = backends_path.parse_args() 46 source_dir = args.source_dir 47 apply_patch(source_dir) 48 return 0 49 50 51if __name__ == '__main__': 52 sys.exit(main())