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 8import os 9import subprocess 10import sys 11 12# Equivalent to: rm -f $2 && $1 rcs $2 @$3 13 14ar, output, rspfile = sys.argv[1:] 15 16if os.path.exists(output): 17 os.remove(output) 18 19if sys.platform != 'darwin': 20 sys.exit(subprocess.call([ar, "rcs", output, "@" + rspfile])) 21 22# Mac ar doesn't support @rspfile syntax. 23objects = open(rspfile).read().split() 24# It also spams stderr with warnings about objects having no symbols. 25pipe = subprocess.Popen([ar, "rcs", output] + objects, stderr=subprocess.PIPE) 26_, err = pipe.communicate() 27for line in err.splitlines(): 28 if 'has no symbols' not in line: 29 sys.stderr.write(line + '\n') 30sys.exit(pipe.returncode) 31