Module: Xcodeproj

Defined in:
lib/autosparkle/helpers/xcodeproj_helpers.rb

Overview

Xcodeproj module to handle the fetch and manipulation of Xcode project

Class Method Summary collapse

Class Method Details

.check_sparkle_configuration_existence(project_path, workspace_path) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/autosparkle/helpers/xcodeproj_helpers.rb', line 64

def self.check_sparkle_configuration_existence(project_path, workspace_path)
  project, target = get_app_target(project_path, workspace_path)
  info_plist_file = project.files.find { |f| f.path.end_with?('Info.plist') }
  raise 'Info.plist not found in the project' unless info_plist_file

  info_plist_path = File.join(Env.variables.project_directory_path, "#{target.name}/#{info_plist_file.path}")
  info_plist = Xcodeproj::Plist.read_from_path(info_plist_path)

  raise 'Info.plist does not contain the needed Sparkle configuration: SUFeedURL'.red if info_plist['SUFeedURL'].nil?
  return unless info_plist['SUPublicEDKey'].nil?

  raise 'Info.plist does not contain the needed Sparkle configuration: SUPublicEDKey'.red
end

.get_app_display_name(project_path, workspace_path) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/autosparkle/helpers/xcodeproj_helpers.rb', line 12

def self.get_app_display_name(project_path, workspace_path)
  _, target = get_app_target(project_path, workspace_path)
  build_settings = target.build_configurations.first.build_settings
  display_name = build_settings['PRODUCT_NAME']
  display_name = target.name if display_name == '$(TARGET_NAME)'
  display_name
end

.get_app_target(project_path, workspace_path) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/autosparkle/helpers/xcodeproj_helpers.rb', line 43

def self.get_app_target(project_path, workspace_path)
  project = Xcodeproj::Project.open(project_path) if project_path
  workspace = Xcodeproj::Workspace.new_from_xcworkspace(workspace_path) if workspace_path

  target = project.targets.find { |t| t.name == Env.variables.scheme } if project

  # If workspace is used, find the project containing the scheme
  if workspace && !target
    workspace.file_references.each do |file_reference|
      project_path = File.join(File.dirname(workspace_path), file_reference.path)
      project = Xcodeproj::Project.open(project_path)
      target = project.targets.find { |t| t.name == Env.variables.scheme }
      break if target
    end
  end

  raise "Target not found for scheme #{Env.variables.scheme}".red unless target

  [project, target]
end

.get_minimum_deployment_macos_version(project_path, workspace) ⇒ Object



20
21
22
23
24
# File 'lib/autosparkle/helpers/xcodeproj_helpers.rb', line 20

def self.get_minimum_deployment_macos_version(project_path, workspace)
  _, target = get_app_target(project_path, workspace)
  config = target.build_configurations.first
  config.build_settings['MACOSX_DEPLOYMENT_TARGET']
end

.get_project_version(project_path, workspace_path) ⇒ Object



26
27
28
29
30
# File 'lib/autosparkle/helpers/xcodeproj_helpers.rb', line 26

def self.get_project_version(project_path, workspace_path)
  _, target = get_app_target(project_path, workspace_path)
  target.build_configurations.first.build_settings
  [build_settings['MARKETING_VERSION'], build_settings['CURRENT_PROJECT_VERSION']]
end

.update_project_version(project_path, workspace_path) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/autosparkle/helpers/xcodeproj_helpers.rb', line 32

def self.update_project_version(project_path, workspace_path)
  project, target = get_app_target(project_path, workspace_path)
  target.build_configurations.each do |config|
    config.build_settings['MARKETING_VERSION'] = Env.variables.marketing_version
    config.build_settings['CURRENT_PROJECT_VERSION'] = Env.variables.current_project_version
  end
  project.save

  puts_if_verbose "Successfully updated the project version to #{Env.variables.marketing_version} and saved the project."
end