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/.
9 CL_INCLUDES_PREFIX
= os
.environ
.get("CL_INCLUDES_PREFIX", "Note: including file:")
11 def InvokeClWithDependencyGeneration(cmdline
):
13 # Figure out what the target is
15 if arg
.startswith("-Fo"):
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
)
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:
40 sys
.stdout
.write(line
) # Make sure we preserve the relevant output
44 if ret
!= 0 or target
== "":
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
):
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:])