| OLD | NEW |
| 1 #!/usr/bin/python2.4 | 1 #!/usr/bin/python2.4 |
| 2 # Copyright 2008, Google Inc. | 2 # Copyright 2008, Google Inc. |
| 3 # All rights reserved. | 3 # All rights reserved. |
| 4 # | 4 # |
| 5 # Redistribution and use in source and binary forms, with or without | 5 # Redistribution and use in source and binary forms, with or without |
| 6 # modification, are permitted provided that the following conditions are | 6 # modification, are permitted provided that the following conditions are |
| 7 # met: | 7 # met: |
| 8 # | 8 # |
| 9 # * Redistributions of source code must retain the above copyright | 9 # * Redistributions of source code must retain the above copyright |
| 10 # notice, this list of conditions and the following disclaimer. | 10 # notice, this list of conditions and the following disclaimer. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 if exclude_pattern: | 57 if exclude_pattern: |
| 58 exclude_pattern = re.compile(exclude_pattern) | 58 exclude_pattern = re.compile(exclude_pattern) |
| 59 | 59 |
| 60 def _FindSources(ptrns, tgt, all): | 60 def _FindSources(ptrns, tgt, all): |
| 61 """Internal Recursive function to find all pattern matches.""" | 61 """Internal Recursive function to find all pattern matches.""" |
| 62 # Recursively process lists | 62 # Recursively process lists |
| 63 if SCons.Util.is_List(tgt): | 63 if SCons.Util.is_List(tgt): |
| 64 for t in tgt: | 64 for t in tgt: |
| 65 _FindSources(ptrns, t, all) | 65 _FindSources(ptrns, t, all) |
| 66 else: | 66 else: |
| 67 # Get key to use for tracking whether we've seen this node |
| 68 target_abspath = None |
| 69 if hasattr(tgt, 'abspath'): |
| 70 # Use target's absolute path as the key |
| 71 target_abspath = tgt.abspath |
| 72 target_key = target_abspath |
| 73 else: |
| 74 # Hope node's representation is unique enough (the default repr |
| 75 # contains a pointer to the target as a string). This works for |
| 76 # Alias() nodes. |
| 77 target_key = repr(tgt) |
| 78 |
| 67 # Skip if we have been here before | 79 # Skip if we have been here before |
| 68 if tgt.abspath in all: return | 80 if target_key in all: return |
| 69 # Note that we have been here | 81 # Note that we have been here |
| 70 all[tgt.abspath] = True | 82 all[target_key] = True |
| 71 # Skip ones that match an exclude pattern, if we have one. | 83 # Skip ones that match an exclude pattern, if we have one. |
| 72 if exclude_pattern and exclude_pattern.match(tgt.abspath): return | 84 if (exclude_pattern and target_abspath |
| 85 and exclude_pattern.match(target_abspath)): |
| 86 return |
| 73 | 87 |
| 74 # Handle non-leaf nodes recursively | 88 # Handle non-leaf nodes recursively |
| 75 lst = tgt.children(scan=1) | 89 lst = tgt.children(scan=1) |
| 76 if lst: | 90 if lst: |
| 77 _FindSources(ptrns, lst, all) | 91 _FindSources(ptrns, lst, all) |
| 78 return | 92 return |
| 79 | 93 |
| 80 # See who it matches | 94 # See who it matches |
| 81 for pattern, lst in ptrns.items(): | 95 for pattern, lst in ptrns.items(): |
| 82 # Get real file (backed by repositories). | 96 # Get real file (backed by repositories). |
| 83 rfile = tgt.rfile() | 97 rfile = tgt.rfile() |
| 84 # Add to the list for the first pattern that matches. | 98 # Add files to the list for the first pattern that matches (implicitly, |
| 85 if pattern.match(rfile.path): | 99 # don't add directories). |
| 100 if rfile.isfile() and pattern.match(rfile.path): |
| 86 lst.append(rfile.abspath) | 101 lst.append(rfile.abspath) |
| 87 break | 102 break |
| 88 | 103 |
| 89 # Prepare a group for each pattern. | 104 # Prepare a group for each pattern. |
| 90 patterns = {} | 105 patterns = {} |
| 91 for g in groups: | 106 for g in groups: |
| 92 patterns[re.compile(g, re.IGNORECASE)] = [] | 107 patterns[re.compile(g, re.IGNORECASE)] = [] |
| 93 | 108 |
| 94 # Do the search. | 109 # Do the search. |
| 95 _FindSources(patterns, target, {}) | 110 _FindSources(patterns, target, {}) |
| 96 | 111 |
| 97 return patterns.values() | 112 return patterns.values() |
| 98 | 113 |
| 99 | 114 |
| 100 def generate(env): | 115 def generate(env): |
| 101 # NOTE: SCons requires the use of this name, which fails gpylint. | 116 # NOTE: SCons requires the use of this name, which fails gpylint. |
| 102 """SCons entry point for this tool.""" | 117 """SCons entry point for this tool.""" |
| 103 | 118 |
| 104 # Add a method to gather all inputs needed by a target. | 119 # Add a method to gather all inputs needed by a target. |
| 105 env.AddMethod(GatherInputs, 'GatherInputs') | 120 env.AddMethod(GatherInputs, 'GatherInputs') |
| OLD | NEW |