feat: Add Swift FileParser support for Xcode-managed SwiftPM projects#14360
Draft
markhallen wants to merge 1 commit intoswift-xcode-spm-file-fetcherfrom
Draft
feat: Add Swift FileParser support for Xcode-managed SwiftPM projects#14360markhallen wants to merge 1 commit intoswift-xcode-spm-file-fetcherfrom
markhallen wants to merge 1 commit intoswift-xcode-spm-file-fetcherfrom
Conversation
Extend Swift FileParser to handle Xcode-managed SwiftPM projects that don't have a Package.swift file. This adds: - PackageResolvedParser: Parses Package.resolved v1, v2, and v3 schemas into Dependabot::Dependency objects with proper version/source info - PbxprojParser: Extracts XCRemoteSwiftPackageReference entries from project.pbxproj files to enrich dependencies with requirement types (upToNextMajor, upToNextMinor, exact, range, branch, revision) - FileParser dual-mode: Detects Xcode SPM mode (no Package.swift but Package.resolved present) under enable_swift_xcode_spm experiment flag - Support for multiple .xcodeproj directories with separate resolved files - Comprehensive test fixtures and specs for all parsers and edge cases - xcodeproj gem (~> 1.27) added as a dependency
Contributor
Code Review: Xcode SPM FileParser & FileFetcher Support🔴 High Priority
🟡 Medium Priority
🟢 Low Priority
Summary Table
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What are you trying to accomplish?
This is Part 2 of adding Xcode SwiftPM support, building on the FileFetcher work in #14332. It extends the Swift
FileParserto parse dependencies from Xcode-managed SwiftPM projects that don't have aPackage.swiftfile.Many iOS/macOS projects use Xcode's built-in SwiftPM integration, where dependency pins are stored in
Package.resolved(inside.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/) and version requirements are declared asXCRemoteSwiftPackageReferenceentries inproject.pbxproj. This change teaches the FileParser to extractDependabot::Dependencyobjects from those files.Relates to #7694
Anything you want to highlight for special attention from reviewers?
Feature flag gated: All new parsing logic is behind
Dependabot::Experiments.enabled?(:enable_swift_xcode_spm)— when disabled, the FileParser behaves identically to before.Dual-mode parsing: The
parsemethod detects whether the project is classic SPM (hasPackage.swift) or Xcode SPM (hasPackage.resolvedinside.xcodeprojbut noPackage.swift), and dispatches accordingly. When both exist, classic SPM mode takes precedence.PackageResolvedParser: New helper that parsesPackage.resolvedv1, v2, and v3 schemas intoDependabot::Dependencyobjects. Each schema version has a different JSON structure:object.pinswithpackage,repositoryURL,state.versionpinswithidentity,location,state.versionoriginHashfieldRaises
DependencyFileNotParseablefor invalid JSON, unsupported schema versions, or missing pin data.PbxprojParser: New helper that uses regex to extractXCRemoteSwiftPackageReferenceentries fromproject.pbxprojfiles. Supports all Xcode requirement kinds:upToNextMajorVersion,upToNextMinorVersion,exactVersion,versionRange,branch, andrevision. These are mapped toNativeRequirementstrings that the SwiftUpdateCheckercan process.Requirement enrichment: Dependencies from
Package.resolvedare enriched with requirement info from matchingproject.pbxprojentries. The enrichment matches by normalized dependency name (derived from the repository URL). If noproject.pbxprojis available (e.g. wasn't fetched), the dependency is still created with anilrequirement.Multiple
.xcodeprojsupport: When a repo contains multiple Xcode projects (each with their ownPackage.resolved), the parser processes each one independently and merges results viaDependencySet.xcodeprojgem added: Addedxcodeproj ~> 1.27as a dependency for future use in more robust pbxproj parsing.How will you know you've accomplished your goal?
PackageResolvedParser: 15 examples covering v1/v2/v3 schemas, revision-only pins, multiple dependencies, empty pins, invalid JSON, unknown schema, SCP-style URLsPbxprojParser: 10 examples covering all requirement kinds (major, minor, exact, range, branch, revision), multiple entries, empty/nil contentFileParserintegration: 31 examples (12 existing + 19 new) covering single v2 project, v1 project, v3 project, multi-requirement types, multiple xcodeproj directories, revision-only, no pbxproj, invalid JSON, unknown schema, empty pins, both Package.swift and xcodeproj present, and flag-disabled behaviorChecklist