1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3# Copyright (c) 2022 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 16 17import argparse 18import os 19import subprocess 20import sys 21 22 23def do_strip(strip, output, unstripped_file, mini_debug, clang_base_dir): 24 if strip: 25 result = subprocess.call( 26 [strip, '-o', output, unstripped_file]) 27 28 if mini_debug and not unstripped_file.endswith(".exe"): 29 unstripped_libfile = os.path.abspath(unstripped_file) 30 script_path = os.path.join( 31 os.path.dirname(__file__), 'mini_debug_info.py') 32 ohos_root_path = os.path.join(os.path.dirname(__file__), '../..') 33 result = subprocess.call( 34 ['python3', script_path, '--unstripped-path', unstripped_libfile, '--stripped-path', output, 35 '--root-path', ohos_root_path, '--clang-base-dir', clang_base_dir]) 36 37 return result 38 39 40def main(): 41 parser = argparse.ArgumentParser(description=__doc__) 42 parser.add_argument('--strip', 43 help='The strip binary to run', 44 metavar='FILE') 45 parser.add_argument('--unstripped-file', 46 help='Binary file produced by linking command', 47 metavar='FILE') 48 parser.add_argument('--output', 49 required=True, 50 help='Final output binary file', 51 metavar='FILE') 52 parser.add_argument('command', nargs='+', 53 help='Linking command') 54 parser.add_argument('--mini-debug', 55 action='store_true', 56 default=False, 57 help='Add .gnu_debugdata section for stripped sofile') 58 parser.add_argument('--clang-base-dir', help='') 59 args = parser.parse_args() 60 61 return do_strip(args.strip, args.output, args.unstripped_file, args.mini_debug, args.clang_base_dir) 62 63 64if __name__ == "__main__": 65 sys.exit(main()) 66