Module: Xcake::Constants

Defined in:
lib/xcake/constants.rb

Constant Summary collapse

COMMON_BUILD_SETTINGS =
Xcodeproj::Constants::COMMON_BUILD_SETTINGS.dup.deep_merge(
  [:ios, :unit_test_bundle] => {
    'LD_RUNPATH_SEARCH_PATHS' => [
      '$(inherited)',
      '@executable_path/Frameworks',
      '@loader_path/Frameworks'
    ]
  }.freeze,
  [:ios, :ui_test_bundle] => {
    'LD_RUNPATH_SEARCH_PATHS' => [
      '$(inherited)',
      '@executable_path/Frameworks',
      '@loader_path/Frameworks'
    ]
  }.freeze,
  [:osx, :unit_test_bundle] => {
    'LD_RUNPATH_SEARCH_PATHS' => [
      '$(inherited)',
      '@executable_path/../Frameworks',
      '@loader_path/../Frameworks'
    ]
  }.freeze,
  [:osx, :ui_test_bundle] => {
    'LD_RUNPATH_SEARCH_PATHS' => [
      '$(inherited)',
      '@executable_path/../Frameworks',
      '@loader_path/../Frameworks'
    ]
  }.freeze
).freeze
PRODUCT_TYPE_UTI =
Xcodeproj::Constants::PRODUCT_TYPE_UTI
COPY_FILES_BUILD_PHASE_DESTINATIONS =
Xcodeproj::Constants::COPY_FILES_BUILD_PHASE_DESTINATIONS

Class Method Summary collapse

Class Method Details

.common_build_settings(type, platform = nil, deployment_target = nil, target_product_type = nil, language = :objc) ⇒ Hash

Returns the common build settings for a given platform and configuration name.

Parameters:

  • type (Symbol)

    the type of the build configuration, can be :release or :debug.

  • platform (Symbol) (defaults to: nil)

    the platform for the build settings, can be :ios or :osx.

  • deployment_target (String) (defaults to: nil)

    the deployment target for the platform.

  • target_product_type (Symbol) (defaults to: nil)

    the product type of the target, can be any of Constants::PRODUCT_TYPE_UTI.values or Constants::PRODUCT_TYPE_UTI.keys. Default is :application.

  • language (Symbol) (defaults to: :objc)

    the primary language of the target, can be :objc or :swift.

Returns:

  • (Hash)

    The common build settings



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/xcake/constants.rb', line 63

def self.common_build_settings(type, platform = nil, deployment_target = nil, target_product_type = nil, language = :objc) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/LineLength
  target_product_type = (PRODUCT_TYPE_UTI.find { |_, v| v == target_product_type } || [target_product_type || :application])[0] # rubocop:disable Metrics/LineLength
  common_settings = COMMON_BUILD_SETTINGS

  # Use intersecting settings for all key sets as base
  settings = deep_dup(common_settings[:all])

  # Match further common settings by key sets
  keys = [type, platform, target_product_type, language].compact
  key_combinations = (1..keys.length).flat_map { |n| keys.combination(n).to_a }
  key_combinations.each do |key_combination|
    settings.merge!(deep_dup(common_settings[key_combination] || {}))
  end

  if deployment_target
    case platform
    when :ios then settings['IPHONEOS_DEPLOYMENT_TARGET'] = deployment_target
    when :osx then settings['MACOSX_DEPLOYMENT_TARGET'] = deployment_target
    when :tvos then settings['TVOS_DEPLOYMENT_TARGET'] = deployment_target
    when :watchos then settings['WATCHOS_DEPLOYMENT_TARGET'] = deployment_target
    end
  end

  settings
end

.deep_dup(object) ⇒ Object

Creates a deep copy of the given object

Parameters:

  • object (Object)

    the object to copy.

Returns:

  • (Object)

    The deeply copy of the obejct object.



96
97
98
# File 'lib/xcake/constants.rb', line 96

def self.deep_dup(object)
  Xcodeproj::Project::ProjectHelper.deep_dup(object)
end