Module: XcodeParser

Defined in:
lib/spm_version_updates/xcode_parser.rb

Overview

Xcode project and Package.resolved parsing (migrated from xcode.rb)

Defined Under Namespace

Classes: CouldNotFindResolvedFile, XcodeprojPathMustBeSet

Class Method Summary collapse

Class Method Details

.get_packages(xcodeproj_path) ⇒ Hash<String, Hash>

Find the configured SPM dependencies in the xcodeproj.

Keyed by the normalized repository URL (used to match against ‘Package.resolved` pins and `ignore-repos`), while the original, scheme-bearing `repository_url` is retained for git operations.

Parameters:

  • xcodeproj_path (String)

    The path of the Xcode project

Returns:

  • (Hash<String, Hash>)

    normalized URL => { “repository_url”, “requirement” }

Raises:



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/spm_version_updates/xcode_parser.rb', line 17

def self.get_packages(xcodeproj_path)
  raise(XcodeprojPathMustBeSet) if xcodeproj_path.nil? || xcodeproj_path.empty?

  XcodeProjectPackageReader.package_references(xcodeproj_path).to_h { |package|
    repository_url = package.repository_url
    [
      GitOperations.trim_repo_url(repository_url),
      { "repository_url" => repository_url, "requirement" => package.requirement },
    ]
  }
end

.get_resolved_versions(xcodeproj_path) ⇒ Hash<String, String>

Extracts resolved versions from Package.resolved relative to an Xcode project. When a block is given, malformed resolved files are reported to it as ‘(resolved_path, error)` and skipped; without a block the error is raised.

Parameters:

  • xcodeproj_path (String)

    The path to your Xcode project

Returns:

  • (Hash<String, String>)

Raises:



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/spm_version_updates/xcode_parser.rb', line 36

def self.get_resolved_versions(xcodeproj_path)
  resolved_paths = find_packages_resolved_file(xcodeproj_path)
  raise(CouldNotFindResolvedFile) if resolved_paths.empty?

  resolved_paths.each_with_object({}) { |resolved_path, pins|
    begin
      pins.merge!(PackageResolved.versions_from(resolved_path))
    rescue PackageResolved::MalformedFileError => error
      raise unless block_given?

      yield(resolved_path, error)
    end
  }
end