Class: Dependabot::Swift::FileUpdater::PbxprojUpdater

Inherits:
Object
  • Object
show all
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 =
T.let(
  /
    (isa\s*=\s*XCRemoteSwiftPackageReference;\s*
    repositoryURL\s*=\s*")
    ([^"]+)
    (";\s*
    requirement\s*=\s*\{)
    ([^}]*)
    (\};)
  /mx,
  Regexp
)
KIND_PATTERN =
T.let(/kind\s*=\s*(\w+);/, Regexp)
MIN_VERSION_PATTERN =
T.let(/minimumVersion\s*=\s*[0-9A-Za-z.+-]+;/, Regexp)
VERSION_PATTERN =
T.let(/\bversion\s*=\s*[0-9A-Za-z.+-]+;/, Regexp)

Instance Method Summary collapse

Constructor Details

#initialize(pbxproj_file:, dependencies:) ⇒ PbxprojUpdater

Returns a new instance of PbxprojUpdater.



45
46
47
48
# File 'lib/dependabot/swift/file_updater/pbxproj_updater.rb', line 45

def initialize(pbxproj_file:, dependencies:)
  @pbxproj_file = pbxproj_file
  @dependencies = dependencies
end

Instance Method Details

#updated_pbxproj_contentObject



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
77
78
79
# File 'lib/dependabot/swift/file_updater/pbxproj_updater.rb', line 51

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