1 #!/usr/bin/env python 2 # 3 # Copyright 2016 Google Inc. 4 # 5 # Use of this source code is governed by a BSD-style license that can be 6 # found in the LICENSE file. 7 8 import os 9 import subprocess 10 import sys 11 12 # Equivalent to: rm -f $2 && $1 rcs $2 @$3 13 14 ar, output, rspfile = sys.argv[1:] 15 16 if os.path.exists(output): 17 os.remove(output) 18 19 if sys.platform != 'darwin': 20 sys.exit(subprocess.call([ar, "rcs", output, "@" + rspfile])) 21 22 # Mac ar doesn't support @rspfile syntax. 23 objects = open(rspfile).read().split() 24 # It also spams stderr with warnings about objects having no symbols. 25 pipe = subprocess.Popen([ar, "rcs", output] + objects, stderr=subprocess.PIPE) 26 _, err = pipe.communicate() 27 for line in err.splitlines(): 28 if 'has no symbols' not in line: 29 sys.stderr.write(line + '\n') 30 sys.exit(pipe.returncode) 31