1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3# Copyright (c) 2023 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 21 22def untar_file(tar_file_path, extract_path, args): 23 try: 24 if os.path.exists(extract_path): 25 rm_cmd = ['rm', '-rf', extract_path] 26 subprocess.run(rm_cmd, check=True) 27 28 tar_cmd = ['tar', '-zxvf', tar_file_path, '-C', args.gen_dir] 29 subprocess.run(tar_cmd, check=True) 30 31 except Exception as e: 32 print("tar error!") 33 return 34 35 36def apply_patch(patch_file, target_dir): 37 try: 38 if not os.path.exists(target_dir): 39 return 40 41 patch_cmd = ['patch', '-p1', "--fuzz=0", "--no-backup-if-mismatch", '-i', patch_file, '-d', target_dir] 42 subprocess.run(patch_cmd, check=True) 43 44 except Exception as e: 45 print("apply_patch error!") 46 return 47 48 49def do_patch(args, target_dir): 50 patch_file = [ "Fix error whenparses the value of 5E-324 with libc++.patch" ] 51 52 for patch in patch_file: 53 file_path = os.path.join(args.source_file, patch) 54 apply_patch(file_path, target_dir) 55 56 57def main(): 58 libpng_path = argparse.ArgumentParser() 59 libpng_path.add_argument('--gen-dir', help='generate path of jsoncpp') 60 libpng_path.add_argument('--source-file', help='jsoncpp source compressed dir') 61 args = libpng_path.parse_args() 62 tar_file_path = os.path.join(args.source_file, "jsoncpp-1.9.5.tar.gz") 63 target_dir = os.path.join(args.gen_dir, "jsoncpp-1.9.5") 64 untar_file(tar_file_path, target_dir, args) 65 do_patch(args, target_dir) 66 return 0 67 68 69if __name__ == '__main__': 70 sys.exit(main()) 71