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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#!/usr/bin/env python
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Runs the 'ar' command after removing its output file first.
This script is invoked like:
python gcc_ar_wrapper.py --ar=$AR --output=$OUT $OP $INPUTS
to do the equivalent of:
rm -f $OUT && $AR $OP $OUT $INPUTS
"""
import argparse
import os
import subprocess
import sys
import wrapper_utils
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--ar',
required=True,
help='The ar binary to run',
metavar='PATH')
parser.add_argument('--output',
required=True,
help='Output archive file',
metavar='ARCHIVE')
parser.add_argument('--plugin',
help='Load plugin')
parser.add_argument('--resource-whitelist',
help='Merge all resource whitelists into a single file.',
metavar='PATH')
parser.add_argument('operation',
help='Operation on the archive')
parser.add_argument('inputs', nargs='+',
help='Input files')
args = parser.parse_args()
if args.resource_whitelist:
whitelist_candidates = wrapper_utils.ResolveRspLinks(args.inputs)
wrapper_utils.CombineResourceWhitelists(
whitelist_candidates, args.resource_whitelist)
command = [args.ar, args.operation]
if args.plugin is not None:
command += ['--plugin', args.plugin]
command.append(args.output)
command += args.inputs
# Remove the output file first.
try:
os.remove(args.output)
except OSError as e:
if e.errno != os.errno.ENOENT:
raise
# Now just run the ar command.
return subprocess.call(wrapper_utils.CommandToRun(command))
if __name__ == "__main__":
sys.exit(main())
|