set executable bit on promote-build.sh (r=cpeyer)
[tamarin-stm.git] / build / dependparser.py
blob9e945143c724b2b007352b769a278cc5b72ceba7
1 #!/usr/bin/env python
2 # -*- Mode: Python; indent-tabs-mode: nil -*-
3 # ***** BEGIN LICENSE BLOCK *****
4 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 # The contents of this file are subject to the Mozilla Public License Version
7 # 1.1 (the "License"); you may not use this file except in compliance with
8 # the License. You may obtain a copy of the License at
9 # http://www.mozilla.org/MPL/
11 # Software distributed under the License is distributed on an "AS IS" basis,
12 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 # for the specific language governing rights and limitations under the
14 # License.
16 # The Original Code is [Open Source Virtual Machine].
18 # The Initial Developer of the Original Code is
19 # Adobe System Incorporated.
20 # Portions created by the Initial Developer are Copyright (C) 2005-2006
21 # the Initial Developer. All Rights Reserved.
23 # Contributor(s):
25 # Alternatively, the contents of this file may be used under the terms of
26 # either the GNU General Public License Version 2 or later (the "GPL"), or
27 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 # in which case the provisions of the GPL or the LGPL are applicable instead
29 # of those above. If you wish to allow use of your version of this file only
30 # under the terms of either the GPL or the LGPL, and not to allow others to
31 # use your version of this file under the terms of the MPL, indicate your
32 # decision by deleting the provisions above and replace them with the notice
33 # and other provisions required by the GPL or the LGPL. If you do not delete
34 # the provisions above, a recipient may use your version of this file under
35 # the terms of any one of the MPL, the GPL or the LGPL.
37 # ***** END LICENSE BLOCK *****
40 """Pipes stdin | stdout and extracts a list of all header dependencies to
41 a file. It requires exactly two arguments.
43 The input is expected to take form of C preprocessor output, where
44 paths to originating input source files are indicated via the form
45 # LINENO "PATH"
47 The first argument to the script is the target file to be overwritten.
48 It will contain the extracted dependencies (unquoted paths).
50 The second argument to the script is the path of an originating source
51 file. It is used to resolve relative paths within the input.
52 (Relative paths are unusual, but can arise via manual #line directives
53 in the source code; e.g. see bug 477230.)"""
55 import re
56 import sys
57 import os
59 if len(sys.argv) != 3:
60 raise Exception("Unexpected command line argument.")
62 outfile = sys.argv[1]
63 originating_file = sys.argv[2]
65 relative_to_dir = os.path.dirname(originating_file)
67 _lineExp = re.compile("#(?:line)? ?\d+ \"([^\"<>]+[^/])\"");
69 deps = set()
71 for line in sys.stdin:
72 sys.stdout.write(line)
73 m = _lineExp.match(line)
74 if m:
75 path = m.group(1)
76 if not os.path.isabs(path):
77 path = os.path.abspath(os.path.join(relative_to_dir, path))
78 deps.add(path)
81 ostream = open(outfile, "w")
82 ostream.write("\n".join(deps))
83 ostream.close()