Class: Dependabot::Swift::FileParser::PbxprojParser
- Inherits:
-
Object
- Object
- Dependabot::Swift::FileParser::PbxprojParser
- Extended by:
- T::Sig
- Defined in:
- lib/dependabot/swift/file_parser/pbxproj_parser.rb
Overview
Parses XCRemoteSwiftPackageReference entries from a project.pbxproj file to extract dependency requirement constraints declared in Xcode.
Returns a hash keyed by normalized dependency name (e.g. "github.com/owner/repo") mapping to requirement metadata, so the main parser can enrich Package.resolved dependencies with requirement info from the Xcode project.
Constant Summary collapse
- PACKAGE_REF_BLOCK =
Regex to extract XCRemoteSwiftPackageReference blocks from pbxproj. Uses [^}]* to match the requirement block content — this is safe because Xcode requirement blocks are always flat dictionaries with no nested braces.
/ isa\s*=\s*XCRemoteSwiftPackageReference;\s* repositoryURL\s*=\s*"(?<url>[^"]+)";\s* requirement\s*=\s*\{(?<requirement>[^}]*)\}; /mx- KIND_PATTERN =
Patterns for extracting requirement fields
/kind\s*=\s*(\w+);/- VERSION_NUMBER_PATTERN =
/[0-9A-Za-z.+-]+/- MIN_VERSION_PATTERN =
/minimumVersion\s*=\s*(#{VERSION_NUMBER_PATTERN});/- MAX_VERSION_PATTERN =
/maximumVersion\s*=\s*(#{VERSION_NUMBER_PATTERN});/- VERSION_PATTERN =
/version\s*=\s*(#{VERSION_NUMBER_PATTERN});/- BRANCH_PATTERN =
/branch\s*=\s*"?([^";]+)"?;/- REVISION_PATTERN =
/revision\s*=\s*"?([^";]+)"?;/
Instance Method Summary collapse
-
#initialize(pbxproj_file) ⇒ PbxprojParser
constructor
A new instance of PbxprojParser.
- #parse ⇒ Object
Constructor Details
#initialize(pbxproj_file) ⇒ PbxprojParser
Returns a new instance of PbxprojParser.
42 43 44 |
# File 'lib/dependabot/swift/file_parser/pbxproj_parser.rb', line 42 def initialize(pbxproj_file) @pbxproj_file = pbxproj_file end |
Instance Method Details
#parse ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/dependabot/swift/file_parser/pbxproj_parser.rb', line 50 def parse content = pbxproj_file.content return {} unless content requirements = T.let({}, T::Hash[String, T::Hash[Symbol, Object]]) content.scan(PACKAGE_REF_BLOCK).each do |url, requirement_block| url = T.cast(url, String) requirement_block = T.cast(requirement_block, String) normalized_url = SharedHelpers.scp_to_standard(url) name = UrlHelpers.normalize_name(normalized_url) req_info = parse_requirement_block(requirement_block) next unless req_info requirements[name] = req_info.merge( url: normalized_url, file: pbxproj_file.name ) end requirements end |