4545__COMPILATION_DB_ENTRIES = []
4646
4747
48- # We make no effort to avoid rebuilding the entries. Someday, perhaps we could and even
49- # integrate with the cache, but there doesn't seem to be much call for it.
50- class __CompilationDbNode (SCons .Node .Python .Value ):
51- def __init__ (self , value ):
52- SCons .Node .Python .Value .__init__ (self , value )
53- self .Decider (changed_since_last_build_node )
54-
55-
56- def changed_since_last_build_node (child , target , prev_ni , node ):
57- """ Dummy decider to force always building"""
58- return True
59-
60-
6148def make_emit_compilation_DB_entry (comstr ):
6249 """
6350 Effectively this creates a lambda function to capture:
@@ -79,74 +66,40 @@ def emit_compilation_db_entry(target, source, env):
7966 :return: target(s), source(s)
8067 """
8168
82- dbtarget = __CompilationDbNode (source )
83-
84- entry = env .__COMPILATIONDB_Entry (
85- target = dbtarget ,
86- source = [],
87- __COMPILATIONDB_UOUTPUT = target ,
88- __COMPILATIONDB_USOURCE = source ,
89- __COMPILATIONDB_UACTION = user_action ,
90- __COMPILATIONDB_ENV = env ,
91- )
92-
93- # TODO: Technically, these next two lines should not be required: it should be fine to
94- # cache the entries. However, they don't seem to update properly. Since they are quick
95- # to re-generate disable caching and sidestep this problem.
96- env .AlwaysBuild (entry )
97- env .NoCache (entry )
98-
99- __COMPILATION_DB_ENTRIES .append (dbtarget )
69+ entry = {
70+ "directory" : env .Dir ("#" ).abspath ,
71+ "command" : user_action .strfunction (
72+ target = target , source = source , env = env
73+ ),
74+ "file" : {
75+ "abspath" : source [0 ].srcnode ().abspath ,
76+ "path" : source [0 ].srcnode ().path
77+ },
78+ "output" : {
79+ "abspath" : target [0 ].abspath ,
80+ "path" : target [0 ].path
81+ }
82+ }
83+
84+ __COMPILATION_DB_ENTRIES .append (entry )
10085
10186 return target , source
10287
10388 return emit_compilation_db_entry
10489
10590
106- def compilation_db_entry_action (target , source , env , ** kw ):
107- """
108- Create a dictionary with evaluated command line, target, source
109- and store that info as an attribute on the target
110- (Which has been stored in __COMPILATION_DB_ENTRIES array
111- :param target: target node(s)
112- :param source: source node(s)
113- :param env: Environment for use building this node
114- :param kw:
115- :return: None
116- """
117-
118- command = env ["__COMPILATIONDB_UACTION" ].strfunction (
119- target = env ["__COMPILATIONDB_UOUTPUT" ],
120- source = env ["__COMPILATIONDB_USOURCE" ],
121- env = env ["__COMPILATIONDB_ENV" ],
122- )
123-
124- entry = {
125- "directory" : env .Dir ("#" ).abspath ,
126- "command" : command ,
127- "file" : env ["__COMPILATIONDB_USOURCE" ][0 ],
128- "output" : env ['__COMPILATIONDB_UOUTPUT' ][0 ]
129- }
130-
131- target [0 ].write (entry )
132-
133-
13491def write_compilation_db (target , source , env ):
13592 entries = []
13693
13794 use_abspath = env ['COMPILATIONDB_USE_ABSPATH' ] in [True , 1 , 'True' , 'true' ]
13895
139- for s in __COMPILATION_DB_ENTRIES :
140- entry = s .read ()
141- source_file = entry ['file' ]
142- output_file = entry ['output' ]
143-
96+ for entry in __COMPILATION_DB_ENTRIES :
14497 if use_abspath :
145- source_file = source_file . srcnode (). abspath
146- output_file = output_file . abspath
98+ source_file = entry [ 'file' ][ ' abspath' ]
99+ output_file = entry [ 'output' ][ ' abspath' ]
147100 else :
148- source_file = source_file . srcnode (). path
149- output_file = output_file . path
101+ source_file = entry [ 'file' ][ ' path' ]
102+ output_file = entry [ 'output' ][ ' path' ]
150103
151104 path_entry = {'directory' : entry ['directory' ],
152105 'command' : entry ['command' ],
@@ -162,7 +115,7 @@ def write_compilation_db(target, source, env):
162115
163116
164117def scan_compilation_db (node , env , path ):
165- return __COMPILATION_DB_ENTRIES
118+ return [ SCons . Node . Python . Value ( __COMPILATION_DB_ENTRIES )]
166119
167120
168121def compilation_db_emitter (target , source , env ):
@@ -230,10 +183,6 @@ def generate(env, **kwargs):
230183 [emitter , make_emit_compilation_DB_entry (command ), ]
231184 )
232185
233- env ["BUILDERS" ]["__COMPILATIONDB_Entry" ] = SCons .Builder .Builder (
234- action = SCons .Action .Action (compilation_db_entry_action , None ),
235- )
236-
237186 env ["BUILDERS" ]["CompilationDatabase" ] = SCons .Builder .Builder (
238187 action = SCons .Action .Action (write_compilation_db , "$COMPILATIONDB_COMSTR" ),
239188 target_scanner = SCons .Scanner .Scanner (
0 commit comments