From da4957c99be3fbab19b7810df0257f6bf40efeb0 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Thu, 5 May 2022 14:39:10 +0200 Subject: [PATCH] CMake: Pick first non-free team id for iOS Xcode projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously we picked the first reported team id as found in the Xcode settings file. Now we pick the first non-free team id if there is one, otherwise we pick the first free one. This aligns with qmake behavior. Using a non-free team id usually leads to fewer issues with automatic code-signing. [ChangeLog][iOS][CMake] A non-free Xcode team id is now preferred for project signing. Pick-to: 6.2 6.3 Fixes: QTBUG-96341 Change-Id: I58618fe5c6ca04184812e9bf955a9cb0b3842447 Reviewed-by: Jörg Bornemann --- src/corelib/Qt6CoreMacros.cmake | 103 +++++++++++++++++++++++++------- 1 file changed, 83 insertions(+), 20 deletions(-) diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake index 84b17b24dc8..00704349459 100644 --- a/src/corelib/Qt6CoreMacros.cmake +++ b/src/corelib/Qt6CoreMacros.cmake @@ -799,35 +799,98 @@ function(_qt_internal_find_ios_development_team_id out_var) -x -c "print IDEProvisioningTeams" "${xcode_preferences_path}" OUTPUT_VARIABLE teams_xml ERROR_VARIABLE plist_error) + + # Parsing state. + set(is_free "") + set(current_team_id "") + set(parsing_is_free FALSE) + set(parsing_team_id FALSE) + set(first_team_id "") + + # Parse the xml output and return the first encountered non-free team id. If no non-free team id + # is found, return the first encountered free team id. + # If no team is found, return an empty string. + # + # Example input: + # + # + # marty@planet.local + # + # + # isFreeProvisioningTeam + # + # teamID + # AAA + # ... + # + # + # isFreeProvisioningTeam + # + # teamID + # BBB + # ... + # + # + # + # if(teams_xml AND NOT plist_error) string(REPLACE "\n" ";" teams_xml_lines "${teams_xml}") + foreach(xml_line ${teams_xml_lines}) - if(xml_line MATCHES "(.+)") - set(first_account "${CMAKE_MATCH_1}") - string(STRIP "${first_account}" first_account) - break() + string(STRIP "${xml_line}" xml_line) + if(xml_line STREQUAL "") + # Clean any previously found values when a new team dict is matched. + set(is_free "") + set(current_team_id "") + + elseif(xml_line STREQUAL "isFreeProvisioningTeam") + set(parsing_is_free TRUE) + + elseif(parsing_is_free) + set(parsing_is_free FALSE) + + if(xml_line MATCHES "true") + set(is_free TRUE) + else() + set(is_free FALSE) + endif() + + elseif(xml_line STREQUAL "teamID") + set(parsing_team_id TRUE) + + elseif(parsing_team_id) + set(parsing_team_id FALSE) + if(xml_line MATCHES "([^<]+)") + set(current_team_id "${CMAKE_MATCH_1}") + else() + continue() + endif() + + string(STRIP "${current_team_id}" current_team_id) + + # If this is the first team id we found so far, remember that, regardless if's free + # or not. + if(NOT first_team_id AND current_team_id) + set(first_team_id "${current_team_id}") + endif() + + # Break early if we found a non-free team id and use it, because we prefer + # a non-free team for signing, just like qmake. + if(NOT is_free AND current_team_id) + set(first_team_id "${current_team_id}") + break() + endif() endif() endforeach() endif() - if(NOT first_account) + if(NOT first_team_id) message(DEBUG "Failed to extract an Xcode development team id.") - return() - endif() - - # Extract the first team ID - execute_process(COMMAND "/usr/libexec/PlistBuddy" - -c "print IDEProvisioningTeams:${first_account}:0:teamID" - "${xcode_preferences_path}" - OUTPUT_VARIABLE team_id - ERROR_VARIABLE team_id_error) - if(team_id AND NOT team_id_error) - message(DEBUG "Successfully extracted the first encountered Xcode development team id.") - string(STRIP "${team_id}" team_id) - set_property(GLOBAL PROPERTY _qt_internal_ios_development_team_id "${team_id}") - set("${out_var}" "${team_id}" PARENT_SCOPE) - else() set("${out_var}" "" PARENT_SCOPE) + else() + message(DEBUG "Successfully extracted the first encountered Xcode development team id.") + set_property(GLOBAL PROPERTY _qt_internal_ios_development_team_id "${first_team_id}") + set("${out_var}" "${first_team_id}" PARENT_SCOPE) endif() endfunction()