Class: Dependabot::Swift::FileUpdater::PbxprojUpdater
- Inherits:
-
Object
- Object
- Dependabot::Swift::FileUpdater::PbxprojUpdater
- Extended by:
- T::Sig
- Defined in:
- lib/dependabot/swift/file_updater/pbxproj_updater.rb
Overview
Updates version requirements in project.pbxproj files for XCRemoteSwiftPackageReference entries that match the dependencies being updated. This ensures the Xcode project stays consistent with the updated Package.resolved.
Constant Summary collapse
- PACKAGE_REF_BLOCK =
/ (isa\s*=\s*XCRemoteSwiftPackageReference;\s* repositoryURL\s*=\s*") ([^"]+) (";\s* requirement\s*=\s*\{) ([^}]*) (\};) /mx- KIND_PATTERN =
/kind\s*=\s*(\w+);/- MIN_VERSION_PATTERN =
/minimumVersion\s*=\s*[0-9A-Za-z.+-]+;/- VERSION_PATTERN =
/\bversion\s*=\s*[0-9A-Za-z.+-]+;/
Instance Method Summary collapse
-
#initialize(pbxproj_file:, dependencies:) ⇒ PbxprojUpdater
constructor
A new instance of PbxprojUpdater.
- #updated_pbxproj_content ⇒ Object
Constructor Details
#initialize(pbxproj_file:, dependencies:) ⇒ PbxprojUpdater
Returns a new instance of PbxprojUpdater.
42 43 44 45 |
# File 'lib/dependabot/swift/file_updater/pbxproj_updater.rb', line 42 def initialize(pbxproj_file:, dependencies:) @pbxproj_file = pbxproj_file @dependencies = dependencies end |
Instance Method Details
#updated_pbxproj_content ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/dependabot/swift/file_updater/pbxproj_updater.rb', line 48 def updated_pbxproj_content content = pbxproj_file.content unless content raise Dependabot::DependencyFileNotParseable.new( pbxproj_file.name, "#{pbxproj_file.name} has no content" ) end dep_lookup = build_dependency_lookup content.gsub(PACKAGE_REF_BLOCK) do prefix = T.must(Regexp.last_match(1)) url = T.must(Regexp.last_match(2)) mid = T.must(Regexp.last_match(3)) req_block = T.must(Regexp.last_match(4)) suffix = T.must(Regexp.last_match(5)) normalized = normalize_url(url) dep = dep_lookup[normalized] if dep&.version updated_block = update_requirement_block(req_block, T.must(dep.version)) "#{prefix}#{url}#{mid}#{updated_block}#{suffix}" else T.must(Regexp.last_match(0)) end end end |