@@ -183,7 +183,10 @@ class Target(object):
183183 added_to_compile_targets: used when determining if the target was added to the
184184 set of targets that needs to be built.
185185 in_roots: true if this target is a descendant of one of the root nodes.
186- is_executable: true if the type of target is executable."""
186+ is_executable: true if the type of target is executable.
187+ is_static_library: true if the type of target is static_library.
188+ is_or_has_linked_ancestor: true if the target does a link (eg executable), or
189+ if there is a target in back_deps that does a link."""
187190 def __init__ (self , name ):
188191 self .deps = set ()
189192 self .match_status = MATCH_STATUS_TBD
@@ -196,6 +199,8 @@ def __init__(self, name):
196199 self .added_to_compile_targets = False
197200 self .in_roots = False
198201 self .is_executable = False
202+ self .is_static_library = False
203+ self .is_or_has_linked_ancestor = False
199204
200205
201206class Config (object ):
@@ -266,8 +271,8 @@ def _GetOrCreateTargetByName(targets, target_name):
266271def _DoesTargetTypeRequireBuild (target_dict ):
267272 """Returns true if the target type is such that it needs to be built."""
268273 # If a 'none' target has rules or actions we assume it requires a build.
269- return target_dict ['type' ] != 'none' or \
270- target_dict .get ('actions' ) or target_dict .get ('rules' )
274+ return bool ( target_dict ['type' ] != 'none' or
275+ target_dict .get ('actions' ) or target_dict .get ('rules' ) )
271276
272277
273278def _GenerateTargets (data , target_list , target_dicts , toplevel_dir , files ,
@@ -309,7 +314,11 @@ def _GenerateTargets(data, target_list, target_dicts, toplevel_dir, files,
309314 target .visited = True
310315 target .requires_build = _DoesTargetTypeRequireBuild (
311316 target_dicts [target_name ])
312- target .is_executable = target_dicts [target_name ]['type' ] == 'executable'
317+ target_type = target_dicts [target_name ]['type' ]
318+ target .is_executable = target_type == 'executable'
319+ target .is_static_library = target_type == 'static_library'
320+ target .is_or_has_linked_ancestor = (target_type == 'executable' or
321+ target_type == 'shared_library' )
313322
314323 build_file = gyp .common .ParseQualifiedTarget (target_name )[0 ]
315324 if not build_file in build_file_in_files :
@@ -378,6 +387,7 @@ def _DoesTargetDependOn(target):
378387 for dep in target .deps :
379388 if _DoesTargetDependOn (dep ):
380389 target .match_status = MATCH_STATUS_MATCHES_BY_DEPENDENCY
390+ print '\t ' , target .name , 'matches by dep' , dep .name
381391 return True
382392 target .match_status = MATCH_STATUS_DOESNT_MATCH
383393 return False
@@ -388,6 +398,7 @@ def _GetTargetsDependingOn(possible_targets):
388398 directly on indirectly) on the matched targets.
389399 possible_targets: targets to search from."""
390400 found = []
401+ print 'Targets that matched by dependency:'
391402 for target in possible_targets :
392403 if _DoesTargetDependOn (target ):
393404 found .append (target )
@@ -411,14 +422,27 @@ def _AddBuildTargets(target, roots, add_if_no_ancestor, result):
411422 _AddBuildTargets (back_dep_target , roots , False , result )
412423 target .added_to_compile_targets |= back_dep_target .added_to_compile_targets
413424 target .in_roots |= back_dep_target .in_roots
425+ target .is_or_has_linked_ancestor |= (
426+ back_dep_target .is_or_has_linked_ancestor )
414427
415428 # Always add 'executable' targets. Even though they may be built by other
416429 # targets that depend upon them it makes detection of what is going to be
417430 # built easier.
431+ # And always add static_libraries that have no dependencies on them from
432+ # linkables. This is necessary as the other dependencies on them may be
433+ # static libraries themselves, which are not compile time dependencies.
418434 if target .in_roots and \
419435 (target .is_executable or
420436 (not target .added_to_compile_targets and
421- (add_if_no_ancestor or target .requires_build ))):
437+ (add_if_no_ancestor or target .requires_build )) or
438+ (target .is_static_library and add_if_no_ancestor and
439+ not target .is_or_has_linked_ancestor )):
440+ print '\t \t adding to build targets' , target .name , 'executable' , \
441+ target .is_executable , 'added_to_compile_targets' , \
442+ target .added_to_compile_targets , 'add_if_no_ancestor' , \
443+ add_if_no_ancestor , 'requires_build' , target .requires_build , \
444+ 'is_static_library' , target .is_static_library , \
445+ 'is_or_has_linked_ancestor' , target .is_or_has_linked_ancestor
422446 result .add (target )
423447 target .added_to_compile_targets = True
424448
@@ -429,6 +453,7 @@ def _GetBuildTargets(matching_targets, roots):
429453 roots: set of root targets in the build files to search from."""
430454 result = set ()
431455 for target in matching_targets :
456+ print '\t finding build targets for match' , target .name
432457 _AddBuildTargets (target , roots , True , result )
433458 return result
434459
@@ -536,6 +561,10 @@ def GenerateOutput(target_list, target_dicts, data, params):
536561 data , target_list , target_dicts , toplevel_dir , frozenset (config .files ),
537562 params ['build_files' ])
538563
564+ print 'roots:'
565+ for root in roots :
566+ print '\t ' , root .name
567+
539568 unqualified_mapping = _GetUnqualifiedToTargetMapping (all_targets ,
540569 config .targets )
541570 invalid_targets = None
@@ -544,10 +573,20 @@ def GenerateOutput(target_list, target_dicts, data, params):
544573
545574 if matching_targets :
546575 search_targets = _LookupTargets (config .targets , unqualified_mapping )
576+ print 'supplied targets'
577+ for target in config .targets :
578+ print '\t ' , target
579+ print 'expanded supplied targets'
580+ for target in search_targets :
581+ print '\t ' , target .name
547582 matched_search_targets = _GetTargetsDependingOn (search_targets )
583+ print 'raw matched search targets:'
584+ for target in matched_search_targets :
585+ print '\t ' , target .name
548586 # Reset the visited status for _GetBuildTargets.
549587 for target in all_targets .itervalues ():
550588 target .visited = False
589+ print 'Finding build targets'
551590 build_targets = _GetBuildTargets (matching_targets , roots )
552591 matched_search_targets = [gyp .common .ParseQualifiedTarget (target .name )[1 ]
553592 for target in matched_search_targets ]
0 commit comments