Class: EmergeCLI::Commands::Fix::ExportedSymbols

Inherits:
GlobalOptions
  • Object
show all
Defined in:
lib/commands/fix/exported_symbols.rb

Constant Summary collapse

DEFAULT_EXPORTED_SYMBOLS =

Constants

%(_main
__mh_execute_header).freeze
EXPORTED_SYMBOLS_FILE =
'EXPORTED_SYMBOLS_FILE'.freeze
EXPORTED_SYMBOLS_PATH =
'$(SRCROOT)/EmergeToolsHelperFiles/ExportedSymbols'.freeze
EXPORTED_SYMBOLS_FILE_NAME =
'ExportedSymbols'.freeze
EMERGE_TOOLS_GROUP =
'EmergeToolsHelperFiles'.freeze

Instance Method Summary collapse

Methods inherited from GlobalOptions

#before

Instance Method Details

#call(**options) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/commands/fix/exported_symbols.rb', line 20

def call(**options)
  @options = options
  before(options)

  raise 'Path must be an xcodeproj' unless @options[:path].end_with?('.xcodeproj')
  raise 'Path does not exist' unless File.exist?(@options[:path])

  Sync do
    project = Xcodeproj::Project.open(@options[:path])

    # Add the exported symbols file to the project
    group = project.main_group
    emergetools_group = group.find_subpath(EMERGE_TOOLS_GROUP, true)
    emergetools_group.set_path(EMERGE_TOOLS_GROUP)

    unless emergetools_group.find_file_by_path(EXPORTED_SYMBOLS_FILE_NAME)
      emergetools_group.new_file(EXPORTED_SYMBOLS_FILE_NAME)
    end

    # Create Folder if it doesn't exist

    FileUtils.mkdir_p(File.join(File.dirname(@options[:path]), EMERGE_TOOLS_GROUP))

    # Create the exported symbols file
    path = File.join(File.dirname(@options[:path]), EMERGE_TOOLS_GROUP, EXPORTED_SYMBOLS_FILE_NAME)
    File.write(path, DEFAULT_EXPORTED_SYMBOLS)

    project.targets.each do |target|
      # Only do it for app targets
      next unless target.product_type == 'com.apple.product-type.application'

      target.build_configurations.each do |config|
        config.build_settings[EXPORTED_SYMBOLS_FILE] = EXPORTED_SYMBOLS_PATH
      end
    end

    project.save
  end
end