Bug 790132 - Add a test to make sure media sniffing occurs only when we want. r=bz
[gecko.git] / build / cl.py
blob00318ade63f2f6d128ea98a970c008a35ee24d36
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 import os, os.path
6 import subprocess
7 import sys
9 CL_INCLUDES_PREFIX = os.environ.get("CL_INCLUDES_PREFIX", "Note: including file:")
11 def InvokeClWithDependencyGeneration(cmdline):
12 target = ""
13 # Figure out what the target is
14 for arg in cmdline:
15 if arg.startswith("-Fo"):
16 target = arg[3:]
17 break
19 if target == None:
20 print >>sys.stderr, "No target set" and sys.exit(1)
22 # The deps target lives here
23 depstarget = os.path.basename(target) + ".pp"
25 cmdline += ['-showIncludes']
26 cl = subprocess.Popen(cmdline, stdout=subprocess.PIPE)
28 deps = set()
29 for line in cl.stdout:
30 # cl -showIncludes prefixes every header with "Note: including file:"
31 # and an indentation corresponding to the depth (which we don't need)
32 if line.startswith(CL_INCLUDES_PREFIX):
33 dep = line[len(CL_INCLUDES_PREFIX):].strip()
34 # We can't handle pathes with spaces properly in mddepend.pl, but
35 # we can assume that anything in a path with spaces is a system
36 # header and throw it away.
37 if dep.find(' ') == -1:
38 deps.add(dep)
39 else:
40 sys.stdout.write(line) # Make sure we preserve the relevant output
41 # from cl
43 ret = cl.wait()
44 if ret != 0 or target == "":
45 sys.exit(ret)
47 depsdir = os.path.normpath(os.path.join(os.curdir, ".deps"))
48 depstarget = os.path.join(depsdir, depstarget)
49 if not os.path.isdir(depsdir):
50 try:
51 os.makedirs(depsdir)
52 except OSError:
53 pass # This suppresses the error we get when the dir exists, at the
54 # cost of masking failure to create the directory. We'll just
55 # die on the next line though, so it's not that much of a loss.
57 f = open(depstarget, "w")
58 for dep in sorted(deps):
59 print >>f, "%s: %s" % (target, dep)
61 if __name__ == "__main__":
62 InvokeClWithDependencyGeneration(sys.argv[1:])