Skip to content
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

Missing support for easily adding swift packages to project #305

Open
garrik opened this issue Jul 16, 2021 · 1 comment
Open

Missing support for easily adding swift packages to project #305

garrik opened this issue Jul 16, 2021 · 1 comment

Comments

@garrik
Copy link

garrik commented Jul 16, 2021

I have not found an api to perform all steps required to add a swift package to project.
When a swift package is added to an xcode project, it is modified as follows:

  • a single entry is added to XCRemoteSwiftPackageReference section
  • a single entry is added to PBXProject section
  • an entry for each package product is added to XCSwiftPackageProductDependency section
  • an entry for each package product is added to PBXFrameworksBuildPhase section, for given target
  • an entry for each package product is added to PBXBuildFile section (the entry has productRef attribute in place of fileRef), for given target
  • an entry for each package product is added to PBXNativeTarget section, for given target

As a side note, a file *.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved is also created, but I think this is out of scope.

I have modified mod-pbxproj and added an add_package function that performs the steps stated above. It can be used as follows:

from pbxproj import XcodeProject
    
# open the project
project = XcodeProject.load('DummyProject/DummyProject.xcodeproj/project.pbxproj')

project.add_package('https://github.com/SnapKit/SnapKit.git', 'SnapKit', 'DummyProject (iOS)', {
    "kind": "upToNextMajorVersion",
    "minimumVersion": "5.0.1"
})
project.add_package('https://github.com/openid/AppAuth-iOS.git', ['AppAuth','AppAuthCore'], 'DummyProject (iOS)', {
    "kind": "upToNextMajorVersion",
    "minimumVersion": "1.4.0"
})

project.save()

You can take a look the patch master...garrik:develop

This code just suits my needs but if you find it a viable solution, I would be happy to add tests, refactor, accept suggestion for improvement and contribute a pull request.
Regards

@kronenthaler
Copy link
Owner

Thanks @garrik, from a quick view it seems like a valuable addition, please create a PR and we can iterate there :)

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

No branches or pull requests

2 participants