Class: Xcodeproj::Command::ConfigDump

Inherits:
Xcodeproj::Command show all
Defined in:
lib/xcodeproj/command/config_dump.rb

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ ConfigDump

Returns a new instance of ConfigDump.



25
26
27
28
29
30
# File 'lib/xcodeproj/command/config_dump.rb', line 25

def initialize(argv)
  self.xcodeproj_path = argv.shift_argument
  @output_path = Pathname(argv.shift_argument || '.')

  super
end

Instance Method Details

#dump_all_configs(configurable, name) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/xcodeproj/command/config_dump.rb', line 47

def dump_all_configs(configurable, name)
  path = Pathname(name)

  # Dump base configuration to file
  base_settings = extract_common_settings!(configurable.build_configurations)
  base_file_path = path + "#{name}_base.xcconfig"
  dump_config_to_file(base_settings, base_file_path)

  # Dump each configuration to file
  configurable.build_configurations.each do |config|
    settings = config.build_settings
    dump_config_to_file(settings, path + "#{name}_#{config.name.downcase}.xcconfig", [base_file_path])
  end
end

#dump_config_to_file(settings, file_path, includes = []) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/xcodeproj/command/config_dump.rb', line 77

def dump_config_to_file(settings, file_path, includes = [])
  dir = @output_path + file_path + '..'
  dir.mkpath

  settings = Hash[settings.map do |k, v|
    [k, Array(v).join(' ')]
  end]

  config = Config.new(settings)
  config.includes = includes
  config.save_as(@output_path + file_path)
end

#extract_common_settings!(build_configurations) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/xcodeproj/command/config_dump.rb', line 62

def extract_common_settings!(build_configurations)
  # Grasp all common build settings
  all_build_settings = build_configurations.map(&:build_settings)
  common_build_settings = all_build_settings.reduce do |settings, config_build_settings|
    settings.select { |key, value| value == config_build_settings[key] }
  end

  # Remove all common build settings from each configuration specific build settings
  build_configurations.each do |config|
    config.build_settings.reject! { |key| !common_build_settings[key].nil? }
  end

  common_build_settings
end

#runObject



39
40
41
42
43
44
45
# File 'lib/xcodeproj/command/config_dump.rb', line 39

def run
  dump_all_configs(xcodeproj, 'Project')

  xcodeproj.targets.each do |target|
    dump_all_configs(target, target.name)
  end
end

#validate!Object

Raises:



32
33
34
35
36
37
# File 'lib/xcodeproj/command/config_dump.rb', line 32

def validate!
  super

  raise Informative, 'The output path must be a directory.' unless @output_path.directory?
  open_project!
end