aboutsummaryrefslogtreecommitdiffhomepage
path: root/gn/ar.py
blob: c7ffb04f67755984f7ef11fb488ca2696c8c2641 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python
#
# Copyright 2016 Google Inc.
#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import os
import subprocess
import sys

# Equivalent to: rm -f $2 && $1 rcs $2 @$3

ar, output, rspfile = sys.argv[1:]

if os.path.exists(output):
  os.remove(output)

if sys.platform != 'darwin':
  sys.exit(subprocess.call([ar, "rcs", output, "@" + rspfile]))

# Mac ar doesn't support @rspfile syntax.
objects = open(rspfile).read().split()
# It also spams stderr with warnings about objects having no symbols.
pipe = subprocess.Popen([ar, "rcs", output] + objects, stderr=subprocess.PIPE)
_, err = pipe.communicate()
for line in err.splitlines():
  if 'has no symbols' not in line:
    sys.stderr.write(line + '\n')
sys.exit(pipe.returncode)