Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2008 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2008 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 """ | 5 """ |
| 6 Commandline modification of Xcode project files | 6 Commandline modification of Xcode project files |
| 7 """ | 7 """ |
| 8 | 8 |
| 9 import sys | 9 import sys |
| 10 import os | 10 import os |
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 545 # Only files are sorted, they keep groups at the top | 545 # Only files are sorted, they keep groups at the top |
| 546 try: | 546 try: |
| 547 self.FileReferenceForUUID(parent_group.child_uuids[i]) | 547 self.FileReferenceForUUID(parent_group.child_uuids[i]) |
| 548 if new_file_ref.name.lower() < parent_group.child_names[i].lower(): | 548 if new_file_ref.name.lower() < parent_group.child_names[i].lower(): |
| 549 break | 549 break |
| 550 except RuntimeError: | 550 except RuntimeError: |
| 551 pass # Must be a child group | 551 pass # Must be a child group |
| 552 i += 1 | 552 i += 1 |
| 553 parent_group.child_names.insert(i, new_file_ref.name) | 553 parent_group.child_names.insert(i, new_file_ref.name) |
| 554 parent_group.child_uuids.insert(i, new_file_ref.uuid) | 554 parent_group.child_uuids.insert(i, new_file_ref.uuid) |
| 555 # Add file ref uuid sorted | |
| 555 self._sections['PBXFileReference'].append(new_file_ref) | 556 self._sections['PBXFileReference'].append(new_file_ref) |
| 557 self._sections['PBXFileReference'].sort(cmp=lambda x,y: cmp(x.uuid, y.uuid )) | |
|
sgk
2009/01/26 18:53:01
Nit: 80 chars.
| |
| 556 return new_file_ref | 558 return new_file_ref |
| 557 | 559 |
| 558 # Group-relative failed, how about SOURCE_ROOT relative in the main group | 560 # Group-relative failed, how about SOURCE_ROOT relative in the main group |
| 559 src_rel_path = self.RelativeSourceRootPath(os.path.abspath(path)) | 561 src_rel_path = self.RelativeSourceRootPath(os.path.abspath(path)) |
| 560 if src_rel_path: | 562 if src_rel_path: |
| 561 src_rel_path = src_rel_path.replace('\\', '/') # Convert to Unix | 563 src_rel_path = src_rel_path.replace('\\', '/') # Convert to Unix |
| 562 new_file_ref = PBXFileReference(NewUUID(), | 564 new_file_ref = PBXFileReference(NewUUID(), |
| 563 os.path.basename(path), | 565 os.path.basename(path), |
| 564 source_type, | 566 source_type, |
| 565 None, | 567 None, |
| 566 src_rel_path, | 568 src_rel_path, |
| 567 'SOURCE_ROOT', | 569 'SOURCE_ROOT', |
| 568 None) | 570 None) |
| 569 self._root_group.child_uuids.append(new_file_ref.uuid) | 571 self._root_group.child_uuids.append(new_file_ref.uuid) |
| 570 self._root_group.child_names.append(new_file_ref.name) | 572 self._root_group.child_names.append(new_file_ref.name) |
| 573 # Add file ref uuid sorted | |
| 571 self._sections['PBXFileReference'].append(new_file_ref) | 574 self._sections['PBXFileReference'].append(new_file_ref) |
| 575 self._sections['PBXFileReference'].sort(cmp=lambda x,y: cmp(x.uuid, y.uuid )) | |
|
sgk
2009/01/26 18:53:01
Nit: 80 chars.
| |
| 572 return new_file_ref | 576 return new_file_ref |
| 573 | 577 |
| 574 # Win to Unix absolute paths probably not practical | 578 # Win to Unix absolute paths probably not practical |
| 575 raise RuntimeError('Could not construct group or source PBXFileReference ' | 579 raise RuntimeError('Could not construct group or source PBXFileReference ' |
| 576 'for path "%s"' % path) | 580 'for path "%s"' % path) |
| 577 | 581 |
| 578 def AddSourceFileToSourcesBuildPhase(self, source_ref, source_phase): | 582 def AddSourceFileToSourcesBuildPhase(self, source_ref, source_phase): |
| 579 """Add a PBXFileReference to a PBXSourcesBuildPhase, creating a new | 583 """Add a PBXFileReference to a PBXSourcesBuildPhase, creating a new |
| 580 PBXBuildFile as needed. | 584 PBXBuildFile as needed. |
| 581 | 585 |
| 582 Args: | 586 Args: |
| 583 source_ref: PBXFileReference instance appropriate for use in | 587 source_ref: PBXFileReference instance appropriate for use in |
| 584 PBXSourcesBuildPhase | 588 PBXSourcesBuildPhase |
| 585 source_phase: PBXSourcesBuildPhase instance | 589 source_phase: PBXSourcesBuildPhase instance |
| 586 """ | 590 """ |
| 587 # Prevent duplication | 591 # Prevent duplication |
| 588 for source_uuid in source_phase.file_uuids: | 592 for source_uuid in source_phase.file_uuids: |
| 589 build_file = self.BuildFileForUUID(source_uuid) | 593 build_file = self.BuildFileForUUID(source_uuid) |
| 590 if build_file.file_ref_uuid == source_ref.uuid: | 594 if build_file.file_ref_uuid == source_ref.uuid: |
| 591 return | 595 return |
| 592 # Create PBXBuildFile | 596 # Create PBXBuildFile |
| 593 new_build_file = PBXBuildFile(NewUUID(), | 597 new_build_file = PBXBuildFile(NewUUID(), |
| 594 source_ref.name, | 598 source_ref.name, |
| 595 'Sources', | 599 'Sources', |
| 596 source_ref.uuid, | 600 source_ref.uuid, |
| 597 '') | 601 '') |
| 602 # Add to build file list (uuid sorted) | |
| 598 self._sections['PBXBuildFile'].append(new_build_file) | 603 self._sections['PBXBuildFile'].append(new_build_file) |
| 604 self._sections['PBXBuildFile'].sort(cmp=lambda x,y: cmp(x.uuid, y.uuid)) | |
| 599 # Add to sources phase list (name sorted) | 605 # Add to sources phase list (name sorted) |
| 600 i = 0 | 606 i = 0 |
| 601 while i < len(source_phase.file_names): | 607 while i < len(source_phase.file_names): |
| 602 if source_ref.name.lower() < source_phase.file_names[i].lower(): | 608 if source_ref.name.lower() < source_phase.file_names[i].lower(): |
| 603 break | 609 break |
| 604 i += 1 | 610 i += 1 |
| 605 source_phase.file_names.insert(i, new_build_file.name) | 611 source_phase.file_names.insert(i, new_build_file.name) |
| 606 source_phase.file_uuids.insert(i, new_build_file.uuid) | 612 source_phase.file_uuids.insert(i, new_build_file.uuid) |
| 607 | 613 |
| 608 | 614 |
| (...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1257 elif args[0] == 'parse_sanity': | 1263 elif args[0] == 'parse_sanity': |
| 1258 if ''.join(project.FileContent()) != ''.join(project._raw_content): | 1264 if ''.join(project.FileContent()) != ''.join(project._raw_content): |
| 1259 option_parser.error('Project rewrite sanity fail "%s"' % project.path) | 1265 option_parser.error('Project rewrite sanity fail "%s"' % project.path) |
| 1260 | 1266 |
| 1261 else: | 1267 else: |
| 1262 Usage(option_parser) | 1268 Usage(option_parser) |
| 1263 | 1269 |
| 1264 | 1270 |
| 1265 if __name__ == '__main__': | 1271 if __name__ == '__main__': |
| 1266 Main() | 1272 Main() |
| OLD | NEW |