Class: HMap::XcodeprojHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-hmap/helper/xcconfig_helper.rb

Overview

A collection of Helper functions used throughout cocoapods-hmap.

Constant Summary collapse

OTHER_CFLAGS =
'OTHER_CFLAGS'
HEAD_SEARCH_PATHS =
'HEADER_SEARCH_PATHS'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xcconfig) ⇒ XcodeprojHelper

Returns a new instance of XcodeprojHelper.



12
13
14
15
# File 'lib/cocoapods-hmap/helper/xcconfig_helper.rb', line 12

def initialize(xcconfig)
  @xcconfig_path = xcconfig
  @xcconfig = Xcodeproj::Config.new(xcconfig_path)
end

Instance Attribute Details

#build_setting_keyObject (readonly)

A collection of Pods Helper functions used throughout cocoapods-hmap.



10
11
12
# File 'lib/cocoapods-hmap/helper/xcconfig_helper.rb', line 10

def build_setting_key
  @build_setting_key
end

#xcconfig_pathObject (readonly)

A collection of Pods Helper functions used throughout cocoapods-hmap.



10
11
12
# File 'lib/cocoapods-hmap/helper/xcconfig_helper.rb', line 10

def xcconfig_path
  @xcconfig_path
end

Instance Method Details

#change_xcconfig_build_setting(build_setting_key, setting, save_origin) {|@xcconfig| ... } ⇒ Object

Yields:

  • (@xcconfig)


32
33
34
35
36
37
38
39
40
41
# File 'lib/cocoapods-hmap/helper/xcconfig_helper.rb', line 32

def change_xcconfig_build_setting(build_setting_key, setting, save_origin)
  origin_build_setting = @xcconfig.attributes[build_setting_key]
  save_origin_build_setting = save_build_setting_to_xcconfig(build_setting_key)
  hmap_build_setting = @xcconfig.attributes[hmap_key(build_setting_key)]
  value = setting
  value = "#{value} ${#{save_key(build_setting_key)}}" if save_origin && !save_origin_build_setting.nil?
  @xcconfig.attributes[hmap_key(build_setting_key)] = value
  @xcconfig.attributes[build_setting_key] = "${#{hmap_key(build_setting_key)}}"
  yield(@xcconfig) if block_given?
end

#change_xcconfig_other_c_flags_and_save(values, build_as_framework, use_headermap: false, save_origin: true) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/cocoapods-hmap/helper/xcconfig_helper.rb', line 17

def change_xcconfig_other_c_flags_and_save(values, build_as_framework, use_headermap: false, save_origin: true)
  setting = values.flat_map do |config|
    ['$(inherited)', "-I\"#{Helper::Pods.pods_hmap_files_dir}/#{config}.hmap\"",
     "-iquote \"#{Helper::Pods.pods_hmap_files_dir}/#{config}-iquote.hmap\""]
  end
  if build_as_framework
    setting << "-ivfsoverlay \"#{Helper::Pods.pods_hmap_files_dir}/vfs/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/all-product-headers.yaml\""
  end
  change_xcconfig_build_setting(OTHER_CFLAGS, setting.join(' '), save_origin) do |xcconfig|
    xcconfig.attributes['USE_HEADERMAP'] = 'NO' unless use_headermap
    save_build_setting_to_xcconfig(HMap::XcodeprojHelper::HEAD_SEARCH_PATHS)
  end
  save_to_path
end

#clean_hmap_build_setting_to_xcconfig(build_setting) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/cocoapods-hmap/helper/xcconfig_helper.rb', line 59

def clean_hmap_build_setting_to_xcconfig(build_setting)
  save_origin_build_setting = @xcconfig.attributes[save_key(build_setting)]
  origin_build_setting = @xcconfig.attributes[build_setting]
  @xcconfig.attributes[build_setting] = save_origin_build_setting unless save_origin_build_setting.nil?
  @xcconfig.attributes.delete(hmap_key(build_setting))
  @xcconfig.attributes.delete(save_key(build_setting))
end

#clean_hmap_xcconfig_other_c_flags_and_saveObject



52
53
54
55
56
57
# File 'lib/cocoapods-hmap/helper/xcconfig_helper.rb', line 52

def clean_hmap_xcconfig_other_c_flags_and_save
  clean_hmap_build_setting_to_xcconfig(OTHER_CFLAGS)
  clean_hmap_build_setting_to_xcconfig(HEAD_SEARCH_PATHS)
  @xcconfig.attributes['USE_HEADERMAP'] = 'YES'
  save_to_path
end

#save_build_setting_to_xcconfig(key) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/cocoapods-hmap/helper/xcconfig_helper.rb', line 43

def save_build_setting_to_xcconfig(key)
  origin_build_setting = @xcconfig.attributes[key]
  if origin_build_setting.nil? || !origin_build_setting.include?(hmap_key(key))
    @xcconfig.attributes[save_key(key)] = origin_build_setting unless origin_build_setting.nil?
    @xcconfig.attributes.delete(key)
  end
  @xcconfig.attributes[save_key(key)]
end

#save_to_path(path = nil) ⇒ Object



67
68
69
70
# File 'lib/cocoapods-hmap/helper/xcconfig_helper.rb', line 67

def save_to_path(path = nil)
  path = xcconfig_path if path.nil?
  @xcconfig.save_as(path)
end