class DeployGate::Xcode::Analyze

Constants

BASE_WORK_DIR_NAME
DEFAULT_BUILD_CONFIGURATION
PROVISIONING_STYLE_AUTOMATIC
PROVISIONING_STYLE_MANUAL

Attributes

build_workspace[R]
scheme[R]
scheme_workspace[R]
workspaces[R]
xcodeproj[R]

Public Class Methods

new(workspaces, build_configuration = nil, target_scheme = nil) click to toggle source

@param [Array] workspaces @param [String] build_configuration @param [String] target_scheme @return [DeployGate::Xcode::Analyze]

# File lib/deploygate/xcode/analyze.rb, line 19
def initialize(workspaces, build_configuration = nil, target_scheme = nil)
  @workspaces = workspaces
  @build_configuration = build_configuration || DEFAULT_BUILD_CONFIGURATION
  @scheme_workspace = find_scheme_workspace(workspaces)
  @build_workspace = find_build_workspace(workspaces)
  @xcodeproj = File.dirname(@scheme_workspace)

  config = FastlaneCore::Configuration.create(Gym::Options.available_options, { project: @xcodeproj })
  Gym.config = config
  @project = FastlaneCore::Project.new(config)

  if @project.schemes.length > 1 && target_scheme && @project.schemes.include?(target_scheme)
    @project.options[:scheme] = target_scheme
  else
    @project.select_scheme
  end
  @scheme = @project.options[:scheme]
end

Public Instance Methods

code_sign_identity() click to toggle source
# File lib/deploygate/xcode/analyze.rb, line 47
def code_sign_identity
  identity = nil
  resolve_build_configuration do |build_configuration, target|
    identity = build_configuration.resolve_build_setting("CODE_SIGN_IDENTITY", target)
  end

  identity
end
code_sign_style() click to toggle source
# File lib/deploygate/xcode/analyze.rb, line 38
def code_sign_style
  style = nil
  resolve_build_configuration do |build_configuration, target|
    style = build_configuration.resolve_build_setting("CODE_SIGN_STYLE", target)
  end

  style
end
developer_team() click to toggle source
# File lib/deploygate/xcode/analyze.rb, line 67
def developer_team
  team = nil
  resolve_build_configuration do |build_configuration, target|
    team = build_configuration.resolve_build_setting("DEVELOPMENT_TEAM", target)
  end

  team
end
project_profile_info() click to toggle source
# File lib/deploygate/xcode/analyze.rb, line 76
def project_profile_info
  gym = Gym::CodeSigningMapping.new(project: @project)

  {
      provisioningProfiles: gym.detect_project_profile_mapping
  }
end
target_bundle_identifier() click to toggle source

TODO: Need to support UDID additions for watchOS and App Extension @return [String]

# File lib/deploygate/xcode/analyze.rb, line 58
def target_bundle_identifier
  bundle_identifier = nil
  resolve_build_configuration do |build_configuration, target|
    bundle_identifier = build_configuration.resolve_build_setting("PRODUCT_BUNDLE_IDENTIFIER", target)
  end

  bundle_identifier
end
target_provisioning_profile() click to toggle source
# File lib/deploygate/xcode/analyze.rb, line 84
def target_provisioning_profile
  gym = Gym::CodeSigningMapping.new(project: @project)
  bundle_id = target_bundle_identifier

  Xcode::Export.provisioning_profile(bundle_id, nil, developer_team, gym.merge_profile_mapping[bundle_id.to_sym])
end

Private Instance Methods

find_build_workspace(workspaces) click to toggle source

@param [Array] workspaces @return [String]

# File lib/deploygate/xcode/analyze.rb, line 133
def find_build_workspace(workspaces)
  return nil if workspaces.empty?
  return workspaces.first if workspaces.count == 1

  select = nil
  workspaces.each do |workspace|
    if BASE_WORK_DIR_NAME != File.basename(workspace)
      select = workspace
    end
  end

  select
end
find_scheme_workspace(workspaces) click to toggle source

@param [Array] workspaces @return [String]

# File lib/deploygate/xcode/analyze.rb, line 117
def find_scheme_workspace(workspaces)
  return nil if workspaces.empty?
  return workspaces.first if workspaces.count == 1

  select = nil
  workspaces.each do |workspace|
    if BASE_WORK_DIR_NAME == File.basename(workspace)
      select = workspace
    end
  end

  select
end
resolve_build_configuration(&block) click to toggle source
# File lib/deploygate/xcode/analyze.rb, line 93
def resolve_build_configuration(&block)
  gym = Gym::CodeSigningMapping.new(project: @project)
  specified_configuration = gym.detect_configuration_for_archive

  Xcodeproj::Project.open(@xcodeproj).targets.each do |target|
    target.build_configuration_list.build_configurations.each do |build_configuration|
      # Used the following code as an example
      # https://github.com/fastlane/fastlane/blob/2.148.1/gym/lib/gym/code_signing_mapping.rb#L138
      current = build_configuration.build_settings
      next if gym.test_target?(current)
      sdk_root = build_configuration.resolve_build_setting("SDKROOT", target)
      next unless gym.same_platform?(sdk_root)
      next unless specified_configuration == build_configuration.name

      # If SKIP_INSTALL is true, it is an app extension or watch app
      next if current["SKIP_INSTALL"]

      block.call(build_configuration, target)
    end
  end
end