From abecbf2d170e244453a851d149ada9cca745e99a Mon Sep 17 00:00:00 2001 From: Jan Nash Date: Thu, 12 Nov 2020 17:30:35 +0100 Subject: [PATCH 1/7] Prettify debug json file --- xUnique.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xUnique.py b/xUnique.py index 49a7692..43e651e 100755 --- a/xUnique.py +++ b/xUnique.py @@ -192,7 +192,7 @@ def unique_project(self): if self.verbose: debug_result_file_path = path.join(self.xcodeproj_path, 'debug_result.json') with open(debug_result_file_path, 'w') as debug_result_file: - json_dump(self.__result, debug_result_file) + json_dump(self.__result, debug_result_file, indent=4) warning_print("Debug result json file has been written to '", debug_result_file_path, sep='') self.substitute_old_keys() From 85e6b442164eb1fa4a36a27211cec645a04695f0 Mon Sep 17 00:00:00 2001 From: Jan Nash Date: Thu, 12 Nov 2020 17:51:04 +0100 Subject: [PATCH 2/7] Move vPrint into loop, add comments and newlines --- xUnique.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/xUnique.py b/xUnique.py index 43e651e..e5ce97d 100755 --- a/xUnique.py +++ b/xUnique.py @@ -177,6 +177,8 @@ def unique_project(self): PBXProject XCConfigurationList + XCRemoteSwiftPackageReference + XCSwiftPackageProductDependency PBXNativeTarget PBXTargetDependency PBXContainerItemProxy @@ -349,8 +351,10 @@ def file_dir_order(x): def __unique_project(self, project_hex): """PBXProject. It is root itself, no parents to it""" self.vprint('uniquify PBXProject') + self.vprint('uniquify PBX*Group and PBX*Reference*') self.__unique_group_or_ref(project_hex, self.main_group_hex) + self.vprint('uniquify XCConfigurationList') bcl_hex = self.root_node['buildConfigurationList'] self.__unique_build_configuration_list(project_hex, bcl_hex) @@ -463,8 +467,8 @@ def __unique_build_phase(self, parent_hex, build_phase_hex): else: cur_path_key = bp_type self.__set_to_result(parent_hex, build_phase_hex, cur_path_key) - self.vprint('uniquify PBXBuildFile') for build_file_hex in current_node['files']: + self.vprint('uniquify PBXBuildFile {}'.format(build_file_hex)) self.__unique_build_file(build_phase_hex, build_file_hex) def __unique_group_or_ref(self, parent_hex, group_ref_hex): From 2416f6ade0ee5d83d55e3aaa43d8a5d27ab56743 Mon Sep 17 00:00:00 2001 From: Jan Nash Date: Thu, 12 Nov 2020 17:52:02 +0100 Subject: [PATCH 3/7] Add processing for 'packageReferences' --- xUnique.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/xUnique.py b/xUnique.py index e5ce97d..c51b8f6 100755 --- a/xUnique.py +++ b/xUnique.py @@ -358,6 +358,11 @@ def __unique_project(self, project_hex): self.vprint('uniquify XCConfigurationList') bcl_hex = self.root_node['buildConfigurationList'] self.__unique_build_configuration_list(project_hex, bcl_hex) + + package_references_list = self.root_node['packageReferences'] + for package_reference_hex in package_references_list: + self.__unique_package_reference(project_hex, package_reference_hex) + subprojects_list = self.root_node.get('projectReferences') if subprojects_list: self.vprint('uniquify Subprojects') @@ -387,6 +392,12 @@ def __unique_build_configuration(self, parent_hex, build_configuration_hex): cur_path_key = 'name' self.__set_to_result(parent_hex, build_configuration_hex, cur_path_key) + def __unique_package_reference(self, parent_hex, package_reference_hex): + """XCRemoteSwiftPackageReference""" + self.vprint('uniquify XCRemoteSwiftPackageReference') + cur_path_key = 'isa' + self.__set_to_result(parent_hex, package_reference_hex, cur_path_key) + def __unique_target(self, target_hex): """PBXNativeTarget PBXAggregateTarget""" self.vprint('uniquify PBX*Target') From 95331010b31fa5dce00ea3131f65932c0957ced2 Mon Sep 17 00:00:00 2001 From: Jan Nash Date: Thu, 12 Nov 2020 17:52:34 +0100 Subject: [PATCH 4/7] Add processing for 'packageProductDependencies' --- xUnique.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/xUnique.py b/xUnique.py index c51b8f6..f2e79ab 100755 --- a/xUnique.py +++ b/xUnique.py @@ -404,6 +404,15 @@ def __unique_target(self, target_hex): current_node = self.nodes[target_hex] bcl_hex = current_node['buildConfigurationList'] self.__unique_build_configuration_list(target_hex, bcl_hex) + + try: + package_product_dependency_list = current_node['packageProductDependencies'] + if package_product_dependency_list: + for package_product_dependency_hex in package_product_dependency_list: + self.__unique_package_product_dependency(target_hex, package_product_dependency_hex) + except KeyError: + pass + dependencies_list = current_node.get('dependencies') if dependencies_list: self.vprint('uniquify PBXTargetDependency') @@ -431,6 +440,13 @@ def __unique_target_dependency(self, parent_hex, target_dependency_hex): raise XUniqueExit('PBXTargetDependency item "', target_dependency_hex, '" is invalid due to lack of "targetProxy" attribute') + def __unique_package_product_dependency(self, parent_hex, package_product_dependency_hex): + """XCSwiftPackageProductDependency""" + self.vprint('uniquify XCSwiftPackageProductDependency') + cur_path_key = 'isa' + self.vprint(package_product_dependency_hex) + self.__set_to_result(parent_hex, package_product_dependency_hex, cur_path_key) + def __unique_container_item_proxy(self, parent_hex, container_item_proxy_hex): """PBXContainerItemProxy""" self.vprint('uniquify PBXContainerItemProxy') From 8a8e0dd8c034ddfd59a4c515d7a6ed793de4d378 Mon Sep 17 00:00:00 2001 From: Jan Nash Date: Thu, 12 Nov 2020 17:57:52 +0100 Subject: [PATCH 5/7] Add parsing for 'productRef' to `__unique_build_file`, refactor it a bit --- xUnique.py | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/xUnique.py b/xUnique.py index f2e79ab..3e2c6c4 100755 --- a/xUnique.py +++ b/xUnique.py @@ -523,20 +523,29 @@ def __unique_build_file(self, parent_hex, build_file_hex): """PBXBuildFile""" current_node = self.nodes.get(build_file_hex) if not current_node: + self.vprint("No node could be found for '{}'. It will be removed.".format(build_file_hex)) self.__result.setdefault('to_be_removed', []).append(build_file_hex) - else: - file_ref_hex = current_node.get('fileRef') - if not file_ref_hex: - self.vprint("PBXFileReference '", file_ref_hex, "' not found, it will be removed.") - self.__result.setdefault('to_be_removed', []).append(build_file_hex) - else: - if self.__result.get(file_ref_hex): - cur_path_key = self.__result[file_ref_hex]['path'] - self.__set_to_result(parent_hex, build_file_hex, cur_path_key) - else: - self.vprint("PBXFileReference '", file_ref_hex, "' not found in PBXBuildFile '", build_file_hex, - "'. To be removed.", sep='') - self.__result.setdefault('to_be_removed', []).extend((build_file_hex, file_ref_hex)) + return + + def __set_result(ref): + cur_path_key = self.__result[ref]['path'] + self.__set_to_result(parent_hex, build_file_hex, cur_path_key) + + file_ref_hex = current_node.get('fileRef') + if file_ref_hex: + if self.__result.get(file_ref_hex): + __set_result(file_ref_hex) + return + + product_ref_hex = current_node.get('productRef') + if product_ref_hex: + if self.__result.get(product_ref_hex): + __set_result(product_ref_hex) + return + + self.vprint("Neither 'fileRef' nor 'productRef' could be found in '{}'. It will be removed.".format(build_file_hex)) + self.__result.setdefault('to_be_removed', []).append(build_file_hex) + def __unique_build_rules(self, parent_hex, build_rule_hex): """PBXBuildRule""" From 46efb8f49a9c1d8aba5599b506a52743a1723f5a Mon Sep 17 00:00:00 2001 From: Jan Nash Date: Thu, 12 Nov 2020 19:08:32 +0100 Subject: [PATCH 6/7] Correct cur_path_key in __unique_package_[reference/product_dependency] --- xUnique.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xUnique.py b/xUnique.py index 3e2c6c4..de6cf42 100755 --- a/xUnique.py +++ b/xUnique.py @@ -395,7 +395,7 @@ def __unique_build_configuration(self, parent_hex, build_configuration_hex): def __unique_package_reference(self, parent_hex, package_reference_hex): """XCRemoteSwiftPackageReference""" self.vprint('uniquify XCRemoteSwiftPackageReference') - cur_path_key = 'isa' + cur_path_key = 'repositoryURL' self.__set_to_result(parent_hex, package_reference_hex, cur_path_key) def __unique_target(self, target_hex): @@ -443,7 +443,7 @@ def __unique_target_dependency(self, parent_hex, target_dependency_hex): def __unique_package_product_dependency(self, parent_hex, package_product_dependency_hex): """XCSwiftPackageProductDependency""" self.vprint('uniquify XCSwiftPackageProductDependency') - cur_path_key = 'isa' + cur_path_key = 'productName' self.vprint(package_product_dependency_hex) self.__set_to_result(parent_hex, package_product_dependency_hex, cur_path_key) From c6e1d74455947ec5113a102e6afdbd46522ca3bf Mon Sep 17 00:00:00 2001 From: Jan Nash Date: Thu, 26 Nov 2020 17:20:46 +0100 Subject: [PATCH 7/7] Catch KeyError in non-SPM projects --- xUnique.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/xUnique.py b/xUnique.py index de6cf42..8162627 100755 --- a/xUnique.py +++ b/xUnique.py @@ -359,9 +359,12 @@ def __unique_project(self, project_hex): bcl_hex = self.root_node['buildConfigurationList'] self.__unique_build_configuration_list(project_hex, bcl_hex) - package_references_list = self.root_node['packageReferences'] - for package_reference_hex in package_references_list: - self.__unique_package_reference(project_hex, package_reference_hex) + try: + package_references_list = self.root_node['packageReferences'] + for package_reference_hex in package_references_list: + self.__unique_package_reference(project_hex, package_reference_hex) + except KeyError: + pass subprojects_list = self.root_node.get('projectReferences') if subprojects_list: