ar.py 803 B

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