1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 # Copyright 2016 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6 
7 import os
8 import re
9 import subprocess
10 import sys
11 
12 # This script executes libtool and filters out logspam lines like:
13 #    '/path/to/libtool: file: foo.o has no symbols'
14 BLOCKLIST_PATTERNS = map(re.compile, [
15     r'^.*libtool: (?:for architecture: \S* )?file: .* has no symbols$',
16     r'^.*libtool: warning for library: .* the table of contents is empty '
17     r'\(no object file members in the library define global symbols\)$',
18     r'^.*libtool: warning same member name \(\S*\) in output file used for '
19     r'input files: \S* and: \S* \(due to use of basename, truncation, '
20     r'blank padding or duplicate input files\)$',
21 ])
22 
23 
24 def is_blocklisted_line(line):
25     """Returns whether the line should be filtered out."""
26     for pattern in BLOCKLIST_PATTERNS:
27         if isinstance(line, bytes):
28             line = line.decode()
29         if pattern.match(line):
30             return True
31     return False
32 
33 
34 def main(cmd_list):
35     env = os.environ.copy()
36     # The problem with this flag is that it resets the file mtime on the file
37     # to epoch=0, e.g. 1970-1-1 or 1969-12-31 depending on timezone.
38     env['ZERO_AR_DATE'] = '1'
39     libtoolout = subprocess.Popen(cmd_list, stderr=subprocess.PIPE, env=env)
40     _, err = libtoolout.communicate()
41     for line in err.splitlines():
42         if not is_blocklisted_line(line):
43             print(line, file=sys.stderr)
44     # Unconditionally touch the output .a file on the command line if present
45     # and the command succeeded. A bit hacky.
46     if not libtoolout.returncode:
47         for i in range(len(cmd_list) - 1):
48             if cmd_list[i] == '-o' and cmd_list[i + 1].endswith('.a'):
49                 os.utime(cmd_list[i + 1], None)
50                 break
51     return libtoolout.returncode
52 
53 
54 if __name__ == '__main__':
55     sys.exit(main(sys.argv[1:]))
56