8000 Support folder-based .xcconfig references in XCConfigIntegrator by wogus3602 · Pull Request #12811 · CocoaPods/CocoaPods · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Support folder-based .xcconfig references in XCConfigIntegrator #12811

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wogus3602
Copy link
@wogus3602 wogus3602 commented May 14, 2025

Support folder-based .xcconfig references in XCConfigIntegrator

Problem

When an Xcode project uses a folder reference (blue folder) for its .xcconfig files, CocoaPods’ XCConfigIntegrator only checks the baseConfigurationReference and ignores the base_configuration_reference_anchor and base_configuration_reference_relative_path. As a result, running pod install will overwrite the user’s custom .xcconfig file with Pods-*.xcconfig, breaking custom build configurations.

Related Properties

  • base_configuration_reference_anchor:

    • This property is of type PBXFileSystemSynchronizedRootGroup, representing a special attribute for folder references.
    • It serves as an anchor for managing folder references within the Xcode project structure.
    • It is used in CocoaPods’ XCConfigIntegrator.
    • PBXFileSystemSynchronizedRootGroup
    • Code Reference
  • base_configuration_reference_relative_path:

    • This property is of type String, representing the relative path of the .xcconfig file within the folder reference.
    • It is used to specify the relative path of folder-based configuration files in CocoaPods.
    • Code Reference

Solution

We updated the set_target_xcconfig method in XCConfigIntegrator to properly handle folder-based .xcconfig files.

Improvements

  1. Handling folder-based .xcconfig files:

    • We added logic to check both base_configuration_reference_anchor and base_configuration_reference_relative_path to handle folder-based configuration files.
    • If the folder reference exists and the path is not empty, a warning message is displayed to the user, and the method returns early.
  2. Improved warning messages:

    • Updated UI.warn to include folder reference and relative path information, making the issue clearer.
    • The warning message now instructs users to manually include the CocoaPods-generated xcconfig file when folder references are used.

Benefits

  • Users managing .xcconfig through folder references can retain their custom configurations.
  • CocoaPods integration no longer silently overwrites user-defined settings.
  • The standard group-based .xcconfig behavior remains unaffected.

Known Issue

Currently, the #{path} displayed in UI.warn does not accurately represent the intended relative path. Calculating the relative path correctly for display purposes remains a challenge, requiring further improvements.

Testing

  • Verified with projects containing both group-based and folder-based .xcconfig setups.
  • Confirmed that running pod install preserves the correct base configuration in all scenarios.

References

#12806

@zrajnai-shapr3d
Copy link

Wow. I just ran into this today.
I also have a fix, but I just noticed this PR 🚀

@wogus3602
Copy link
Author

@zrajnai-shapr3d
Could you explain how you fixed it?

@zrajnai-shapr3d
Copy link
zrajnai-shapr3d commented May 14, 2025

My fix is very similar:

          def self.set_target_xcconfig(pod_bundle, target, config)
            file_ref = create_xcconfig_ref(pod_bundle, config)
            path = file_ref.path

            if config.base_configuration_reference
              existing_path = config.base_configuration_reference.real_path
            elsif config.base_configuration_reference_anchor && config.base_configuration_reference_relative_path
              existing_path = Pathname.new(File.join(config.base_configuration_reference_anchor.path, config.base_configuration_reference_relative_path))
            end

            if existing_path && existing_path != file_ref.real_path
              if existing_path.to_path.start_with?(pod_bundle.sandbox.root.to_path << '/')
                config.base_configuration_reference = file_ref
              elsif !xcconfig_includes_target_xcconfig?(existing_path, path)
                unless existing_config_is_identical_to_pod_config?(existing_path, pod_bundle.xcconfig_path(config.name))
                  UI.warn 'CocoaPods did not set the base configuration of your ' \
                  'project because your project already has a custom ' \
                  'config set. In order for CocoaPods integration to work at ' \
                  'all, please either set the base configurations of the target ' \
                  "`#{target.name}` to `#{path}` or include the `#{path}` in your " \
                  "build configuration (#{UI.path(existing_path)})."
                end
              end
            elsif config.base_configuration_reference.nil? || file_ref.nil?
              config.base_configuration_reference = file_ref
            end
          end

I also had to change xcconfig_includes_target_xcconfig to take a path

@wogus3602
Copy link
Author

@zrajnai-shapr3d

The code looks clean. I think it would be better to use UI.warn as a single statement. I'll take this into account and make the changes accordingly. However, I still find it challenging to properly handle the path for xcconfig, especially when calculating the relative path.

@wogus3602 wogus3602 force-pushed the feature/support-folder-based-xcconfig branch from 8a98a88 to 00a18ca Compare May 15, 2025 02:24
@wogus3602 wogus3602 force-pushed the feature/support-folder-based-xcconfig branch from 00a18ca to 667c201 Compare May 15, 2025 02:29
@wogus3602
Copy link
Author

@segiddins
Can you check the PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0