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 os 17import re 18import subprocess 19import sys 20 21# This script executes libtool and filters out logspam lines like: 22# '/path/to/libtool: file: foo.o has no symbols' 23BLOCKLIST_PATTERNS = map(re.compile, [ 24 r'^.*libtool: (?:for architecture: \S* )?file: .* has no symbols$', 25 r'^.*libtool: warning for library: .* the table of contents is empty ' 26 r'\(no object file members in the library define global symbols\)$', 27 r'^.*libtool: warning same member name \(\S*\) in output file used for ' 28 r'input files: \S* and: \S* \(due to use of basename, truncation, ' 29 r'blank padding or duplicate input files\)$', 30]) 31 32 33def is_blocklisted_line(line): 34 """Returns whether the line should be filtered out.""" 35 for pattern in BLOCKLIST_PATTERNS: 36 if isinstance(line, bytes): 37 line = line.decode() 38 if pattern.match(line): 39 return True 40 return False 41 42 43def main(cmd_list): 44 env = os.environ.copy() 45 # The problem with this flag is that it resets the file mtime on the file 46 # to epoch=0, e.g. 1970-1-1 or 1969-12-31 depending on timezone. 47 env['ZERO_AR_DATE'] = '1' 48 libtoolout = subprocess.Popen(cmd_list, stderr=subprocess.PIPE, env=env) 49 _, err = libtoolout.communicate() 50 for line in err.splitlines(): 51 if not is_blocklisted_line(line): 52 print(line, file=sys.stderr) 53 # Unconditionally touch the output .a file on the command line if present 54 # and the command succeeded. A bit hacky. 55 if not libtoolout.returncode: 56 for i in range(len(cmd_list) - 1): 57 if cmd_list[i] == '-o' and cmd_list[i + 1].endswith('.a'): 58 os.utime(cmd_list[i + 1], None) 59 break 60 return libtoolout.returncode 61 62 63if __name__ == '__main__': 64 sys.exit(main(sys.argv[1:])) 65