2 # Thomas Nagy, 2008-2010 (ita)
5 Execute the tasks with gcc -MD, read the dependencies from the .d file
6 and prepare the dependency calculation for the next run
9 import os
, re
, threading
10 import Task
, Logs
, Utils
, preproc
11 from TaskGen
import before
, after
, feature
13 lock
= threading
.Lock()
15 preprocessor_flag
= '-MD'
20 if self
.env
.get_flat('CCFLAGS').find(preprocessor_flag
) < 0:
21 self
.env
.append_value('CCFLAGS', preprocessor_flag
)
25 def add_mmd_cxx(self
):
26 if self
.env
.get_flat('CXXFLAGS').find(preprocessor_flag
) < 0:
27 self
.env
.append_value('CXXFLAGS', preprocessor_flag
)
30 "the scanner does not do anything initially"
31 nodes
= self
.generator
.bld
.node_deps
.get(self
.unique_id(), [])
35 re_o
= re
.compile("\.o$")
36 re_src
= re
.compile("^(\.\.)[\\/](.*)$")
39 # The following code is executed by threads, it is not safe, so a lock is needed...
41 if getattr(self
, 'cached', None):
42 return Task
.Task
.post_run(self
)
44 name
= self
.outputs
[0].abspath(self
.env
)
45 name
= re_o
.sub('.d', name
)
46 txt
= Utils
.readf(name
)
49 txt
= txt
.replace('\\\n', '')
51 lst
= txt
.strip().split(':')
52 val
= ":".join(lst
[1:])
56 bld
= self
.generator
.bld
58 f
= re
.compile("^("+self
.env
.variant()+"|\.\.)[\\/](.*)$")
62 if not preproc
.go_absolute
:
67 node
= bld
.root
.find_resource(x
)
71 g
= re
.search(re_src
, x
)
76 node
= bld
.bldnode
.parent
.find_resource(x
)
85 node
= bld
.srcnode
.find_resource(x
)
89 if id(node
) == id(self
.inputs
[0]):
90 # ignore the source file, it is already in the dependencies
91 # this way, successful config tests may be retrieved from the cache
95 raise ValueError('could not find %r for %r' % (x
, self
))
99 Logs
.debug('deps: real scanner for %s returned %s' % (str(self
), str(nodes
)))
101 bld
.node_deps
[self
.unique_id()] = nodes
102 bld
.raw_deps
[self
.unique_id()] = []
109 Task
.Task
.post_run(self
)
111 import Constants
, Utils
112 def sig_implicit_deps(self
):
114 return Task
.Task
.sig_implicit_deps(self
)
115 except Utils
.WafError
:
116 return Constants
.SIG_NIL
118 for name
in 'cc cxx'.split():
120 cls
= Task
.TaskBase
.classes
[name
]
124 cls
.post_run
= post_run
126 cls
.sig_implicit_deps
= sig_implicit_deps