| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 | 2 |
| 3 import errno | 3 import errno |
| 4 import filecmp | 4 import filecmp |
| 5 import os.path | 5 import os.path |
| 6 import re | 6 import re |
| 7 import tempfile | 7 import tempfile |
| 8 import sys | 8 import sys |
| 9 | 9 |
| 10 def ExceptionAppend(e, msg): | 10 def ExceptionAppend(e, msg): |
| 11 """Append a message to the given exception's message.""" | 11 """Append a message to the given exception's message.""" |
| 12 if not e.args: | 12 if not e.args: |
| 13 e.args = (msg,) | 13 e.args = (msg,) |
| 14 elif len(e.args) == 1: | 14 elif len(e.args) == 1: |
| 15 e.args = (str(e.args[0]) + ' ' + msg,) | 15 e.args = (str(e.args[0]) + ' ' + msg,) |
| 16 else: | 16 else: |
| 17 e.args = (str(e.args[0]) + ' ' + msg,) + e.args[1:] | 17 e.args = (str(e.args[0]) + ' ' + msg,) + e.args[1:] |
| 18 | 18 |
| 19 | 19 |
| 20 def BuildFileAndTarget(build_file, target): | 20 def ParseQualifiedTarget(target): |
| 21 # NOTE: If you just want to split up target into a build_file and target, | 21 # Splits a qualified target into a build file, target name and toolset. |
| 22 # and you know that target already has a build_file that's been produced by | |
| 23 # this function, pass '' for build_file. | |
| 24 | 22 |
| 25 # NOTE: rsplit is used to disambiguate the Windows drive letter separator. | 23 # NOTE: rsplit is used to disambiguate the Windows drive letter separator. |
| 26 target_split = target.rsplit(':', 1) | 24 target_split = target.rsplit(':', 1) |
| 27 if len(target_split) == 2: | 25 if len(target_split) == 2: |
| 28 [build_file_rel, target] = target_split | 26 [build_file, target] = target_split |
| 27 else: |
| 28 build_file = None |
| 29 | 29 |
| 30 # If a relative path, build_file_rel is relative to the directory | 30 target_split = target.rsplit('#', 1) |
| 31 # containing build_file. If build_file is not in the current directory, | 31 if len(target_split) == 2: |
| 32 # build_file_rel is not a usable path as-is. Resolve it by interpreting it | 32 [target, toolset] = target_split |
| 33 # as relative to build_file. If build_file_rel is absolute, it is usable | 33 else: |
| 34 # as a path regardless of the current directory, and os.path.join will | 34 toolset = None |
| 35 # return it as-is. | |
| 36 build_file = os.path.normpath(os.path.join(os.path.dirname(build_file), | |
| 37 build_file_rel)) | |
| 38 | 35 |
| 39 return [build_file, target, build_file + ':' + target] | 36 return [build_file, target, toolset] |
| 40 | 37 |
| 41 | 38 |
| 42 def QualifiedTarget(build_file, target): | 39 def ResolveTarget(build_file, target, toolset): |
| 40 # This function resolves a target into a canonical form: |
| 41 # - a fully defined build file, either absolute or relative to the current |
| 42 # directory |
| 43 # - a target name |
| 44 # - a toolset |
| 45 # |
| 46 # build_file is the file relative to which 'target' is defined. |
| 47 # target is the qualified target. |
| 48 # toolset is the default toolset for that target. |
| 49 [parsed_build_file, target, parsed_toolset] = ParseQualifiedTarget(target) |
| 50 |
| 51 if parsed_build_file: |
| 52 if build_file: |
| 53 # If a relative path, parsed_build_file is relative to the directory |
| 54 # containing build_file. If build_file is not in the current directory, |
| 55 # parsed_build_file is not a usable path as-is. Resolve it by |
| 56 # interpreting it as relative to build_file. If parsed_build_file is |
| 57 # absolute, it is usable as a path regardless of the current directory, |
| 58 # and os.path.join will return it as-is. |
| 59 build_file = os.path.normpath(os.path.join(os.path.dirname(build_file), |
| 60 parsed_build_file)) |
| 61 else: |
| 62 build_file = parsed_build_file |
| 63 |
| 64 if parsed_toolset: |
| 65 toolset = parsed_toolset |
| 66 |
| 67 return [build_file, target, toolset] |
| 68 |
| 69 |
| 70 def BuildFile(fully_qualified_target): |
| 71 # Extracts the build file from the fully qualified target. |
| 72 return ParseQualifiedTarget(fully_qualified_target)[0] |
| 73 |
| 74 |
| 75 def QualifiedTarget(build_file, target, toolset): |
| 43 # "Qualified" means the file that a target was defined in and the target | 76 # "Qualified" means the file that a target was defined in and the target |
| 44 # name, separated by a colon. | 77 # name, separated by a colon, suffixed by a # and the toolset name: |
| 45 return BuildFileAndTarget(build_file, target)[2] | 78 # /path/to/file.gyp:target_name#toolset |
| 79 fully_qualified = build_file + ':' + target |
| 80 if toolset: |
| 81 fully_qualified = fully_qualified + '#' + toolset |
| 82 return fully_qualified |
| 46 | 83 |
| 47 | 84 |
| 48 def RelativePath(path, relative_to): | 85 def RelativePath(path, relative_to): |
| 49 # Assuming both |path| and |relative_to| are relative to the current | 86 # Assuming both |path| and |relative_to| are relative to the current |
| 50 # directory, returns a relative path that identifies path relative to | 87 # directory, returns a relative path that identifies path relative to |
| 51 # relative_to. | 88 # relative_to. |
| 52 | 89 |
| 53 # Convert to absolute (and therefore normalized paths). | 90 # Convert to absolute (and therefore normalized paths). |
| 54 path = os.path.abspath(path) | 91 path = os.path.abspath(path) |
| 55 relative_to = os.path.abspath(relative_to) | 92 relative_to = os.path.abspath(relative_to) |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 dependencies.add(d) | 229 dependencies.add(d) |
| 193 for d in DeepDependencyTargets(target_dicts, r_deps): | 230 for d in DeepDependencyTargets(target_dicts, r_deps): |
| 194 if d not in roots: | 231 if d not in roots: |
| 195 dependencies.add(d) | 232 dependencies.add(d) |
| 196 return list(dependencies) | 233 return list(dependencies) |
| 197 | 234 |
| 198 | 235 |
| 199 def BuildFileTargets(target_list, build_file): | 236 def BuildFileTargets(target_list, build_file): |
| 200 """From a target_list, returns the subset from the specified build_file. | 237 """From a target_list, returns the subset from the specified build_file. |
| 201 """ | 238 """ |
| 202 return [p for p in target_list if | 239 return [p for p in target_list if BuildFile(p) == build_file] |
| 203 BuildFileAndTarget('', p)[0] == build_file] | |
| 204 | 240 |
| 205 | 241 |
| 206 def AllTargets(target_list, target_dicts, build_file): | 242 def AllTargets(target_list, target_dicts, build_file): |
| 207 """Returns all targets (direct and dependencies) for the specified build_file. | 243 """Returns all targets (direct and dependencies) for the specified build_file. |
| 208 """ | 244 """ |
| 209 bftargets = BuildFileTargets(target_list, build_file) | 245 bftargets = BuildFileTargets(target_list, build_file) |
| 210 deptargets = DeepDependencyTargets(target_dicts, bftargets) | 246 deptargets = DeepDependencyTargets(target_dicts, bftargets) |
| 211 return bftargets + deptargets | 247 return bftargets + deptargets |
| 212 | 248 |
| 213 | 249 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 if idfun is None: | 330 if idfun is None: |
| 295 def idfun(x): return x | 331 def idfun(x): return x |
| 296 seen = {} | 332 seen = {} |
| 297 result = [] | 333 result = [] |
| 298 for item in seq: | 334 for item in seq: |
| 299 marker = idfun(item) | 335 marker = idfun(item) |
| 300 if marker in seen: continue | 336 if marker in seen: continue |
| 301 seen[marker] = 1 | 337 seen[marker] = 1 |
| 302 result.append(item) | 338 result.append(item) |
| 303 return result | 339 return result |
| OLD | NEW |