Class: Xcodeproj::Project::Object::XCBuildConfiguration

Inherits:
Object
  • Object
show all
Defined in:
lib/kintsugi/xcodeproj_extensions.rb

Overview

Extends XCBuildConfiguration to convert array settings (which might be either array or string) to actual arrays in to_tree_hash so diffs are always between arrays. This means that if the values in both ours and theirs are different strings, we will know to solve the conflict into an array containing both strings. Code was mostly copied from github.com/CocoaPods/Xcodeproj/blob/master/lib/xcodeproj/project/object/build_configuration.rb#L211

Constant Summary collapse

@@old_to_tree_hash =
instance_method(:to_tree_hash)

Instance Method Summary collapse

Instance Method Details

#convert_array_settings_to_arrays(settings) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/kintsugi/xcodeproj_extensions.rb', line 46

def convert_array_settings_to_arrays(settings)
  return unless settings

  array_settings = BuildSettingsArraySettingsByObjectVersion[project.object_version]

  settings.each_key do |key|
    value = settings[key]
    next unless value.is_a?(String)

    stripped_key = key.sub(/\[[^\]]+\]$/, '')
    next unless array_settings.include?(stripped_key)

    array_value = split_string_setting_into_array(value)
    settings[key] = array_value
  end
end

#split_string_setting_into_array(string) ⇒ Object



63
64
65
# File 'lib/kintsugi/xcodeproj_extensions.rb', line 63

def split_string_setting_into_array(string)
  string.scan(/ *((['"]?).*?[^\\]\2)(?=( |\z))/).map(&:first)
end

#to_tree_hashObject



40
41
42
43
44
# File 'lib/kintsugi/xcodeproj_extensions.rb', line 40

def to_tree_hash
  @@old_to_tree_hash.bind(self).call.tap do |hash|
    convert_array_settings_to_arrays(hash['buildSettings'])
  end
end