Module: Xcode

Defined in:
lib/spm_version_updates/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

Parameters:

  • xcodeproj_path (String)

    The path of the Xcode project

Returns:

  • (Hash<String, Hash>)

Raises:



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/spm_version_updates/xcode.rb', line 10

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

  project = Xcodeproj::Project.open(xcodeproj_path)
  project.objects.select { |obj|
    obj.kind_of?(Xcodeproj::Project::Object::XCRemoteSwiftPackageReference) &&
      obj.requirement["kind"] != "commit"
  }
    .to_h { |package|
      [Git.trim_repo_url(package.repositoryURL), package.requirement]
    }
end

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

Extracts resolved versions from Package.resolved relative to an Xcode project

Parameters:

  • xcodeproj_path (String)

    The path to your Xcode project

Returns:

  • (Hash<String, String>)

Raises:



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/spm_version_updates/xcode.rb', line 28

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

  resolved_versions = resolved_paths.map { |resolved_path|
    contents = JSON.load_file!(resolved_path)
    pins = contents["pins"] || contents["object"]["pins"]
    pins.to_h { |pin|
      [
        Git.trim_repo_url(pin["location"] || pin["repositoryURL"]),
        pin["state"]["version"] || pin["state"]["revision"],
      ]
    }
  }
  resolved_versions.reduce(:merge!)
end