OSDN Git Service

am 6ef046c8: Fixes ProGuard options.
[android-x86/build.git] / tools / merge-event-log-tags.py
1 #!/usr/bin/env python
2 #
3 # Copyright (C) 2009 The Android Open Source Project
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #      http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 """
18 Usage: merge-event-log-tags.py [-o output_file] [input_files...]
19
20 Merge together zero or more event-logs-tags files to produce a single
21 output file, stripped of comments.  Checks that no tag numbers conflict
22 and fails if they do.
23
24 -h to display this usage message and exit.
25 """
26
27 import cStringIO
28 import getopt
29 import sys
30
31 import event_log_tags
32
33 by_tagnum = {}
34 errors = []
35 warnings = []
36
37 output_file = None
38
39 try:
40   opts, args = getopt.getopt(sys.argv[1:], "ho:")
41 except getopt.GetoptError, err:
42   print str(err)
43   print __doc__
44   sys.exit(2)
45
46 for o, a in opts:
47   if o == "-h":
48     print __doc__
49     sys.exit(2)
50   elif o == "-o":
51     output_file = a
52   else:
53     print >> sys.stderr, "unhandled option %s" % (o,)
54     sys.exit(1)
55
56 for fn in args:
57   tagfile = event_log_tags.TagFile(fn)
58
59   for t in tagfile.tags:
60     tagnum = t.tagnum
61     tagname = t.tagname
62     description = t.description
63
64     if t.tagnum in by_tagnum:
65       orig = by_tagnum[t.tagnum]
66
67       if (t.tagname == orig.tagname and
68           t.description == orig.description):
69         # if the name and description are identical, issue a warning
70         # instead of failing (to make it easier to move tags between
71         # projects without breaking the build).
72         tagfile.AddWarning("tag %d \"%s\" duplicated in %s:%d" %
73                            (t.tagnum, t.tagname, orig.filename, orig.linenum),
74                            linenum=t.linenum)
75       else:
76         tagfile.AddError("tag %d used by conflicting \"%s\" from %s:%d" %
77                          (t.tagnum, orig.tagname, orig.filename, orig.linenum),
78                          linenum=t.linenum)
79       continue
80
81     by_tagnum[t.tagnum] = t
82
83   errors.extend(tagfile.errors)
84   warnings.extend(tagfile.warnings)
85
86 if errors:
87   for fn, ln, msg in errors:
88     print >> sys.stderr, "%s:%d: error: %s" % (fn, ln, msg)
89   sys.exit(1)
90
91 if warnings:
92   for fn, ln, msg in warnings:
93     print >> sys.stderr, "%s:%d: warning: %s" % (fn, ln, msg)
94
95 buffer = cStringIO.StringIO()
96 for n in sorted(by_tagnum):
97   t = by_tagnum[n]
98   if t.description:
99     buffer.write("%d %s %s\n" % (t.tagnum, t.tagname, t.description))
100   else:
101     buffer.write("%d %s\n" % (t.tagnum, t.tagname))
102
103 event_log_tags.WriteOutput(output_file, buffer)