class Xcodeproj::Config


provides support for serialization.
This class holds the data for a Xcode build settings file (xcconfig) and

def ==(other)

def ==(other)
  other.respond_to?(:to_hash) && other.to_hash == to_hash
end

def dup

Returns:
  • (Config) - A copy of the receiver.
def dup
  Xcodeproj::Config.new(to_hash.dup)
end

def extract_hash(argument)

Returns:
  • (Hash) -

Parameters:
  • argument (String, Pathname, Hash) --
def extract_hash(argument)
  if argument.respond_to? :read
    hash_from_file_content(argument.read)
  elsif File.readable?(argument.to_s)
    hash_from_file_content(File.read(argument))
  else
    argument
  end
end

def extract_include(line)

Returns:
  • (Nil) - if no include was found in the line.
  • (String) - the included file.

Parameters:
  • line (String) --
def extract_include(line)
  regexp = /#include\s*"(.+)"/
  match = line.match(regexp)
  match[1] if match
end

def extract_key_value(line)

Returns:
  • (Array) - A tuple where the first entry is the key and the second

Parameters:
  • line (String) --
def extract_key_value(line)
  match = line.match(KEY_VALUE_PATTERN)
  if match
    key, value = match[1], match[2]
    [key.strip, value.strip]
  else
    []
  end
end

def frameworks

Returns:
  • (Set) - The list of the frameworks required by this
def frameworks
  other_linker_flags[:frameworks]
end

def hash_from_file_content(string)

Returns:
  • (Hash) - the hash containing the xcconfig data.

Parameters:
  • string (String) --
def hash_from_file_content(string)
  hash = {}
  string.split("\n").each do |line|
    uncommented_line = strip_comment(line)
    if include = extract_include(uncommented_line)
      @includes.push include
    else
      key, value = extract_key_value(uncommented_line)
      hash[key] = value if key
    end
  end
  hash
end

def initialize(xcconfig_hash_or_file = {})

Parameters:
  • xcconfig_hash_or_file (Hash, File, String) --
def initialize(xcconfig_hash_or_file = {})
  @attributes = {}
  @includes = []
  @other_linker_flags = {}
  [:simple, :frameworks, :weak_frameworks, :libraries, :force_load].each do |key|
    @other_linker_flags[key] = Set.new
  end
  merge!(extract_hash(xcconfig_hash_or_file))
end

def inspect

def inspect
  to_hash.inspect
end

def libraries

Returns:
  • (Set) - The list of the libraries required by this
def libraries
  other_linker_flags[:libraries]
end

def merge(config)

Returns:
  • (Config) - the new xcconfig.

Parameters:
  • config (Hash, Config) --
def merge(config)
  dup.tap { |x| x.merge!(config) }
end

def merge!(xcconfig)

Returns:
  • (void) -

Other tags:
    Todo: - The logic to normalize an hash should be extracted and the

Parameters:
  • config (Hash, Config) --

Other tags:
    Note: - If a key in the given hash already exists in the internal data
def merge!(xcconfig)
  if xcconfig.is_a? Config
    merge_attributes!(xcconfig.attributes)
    other_linker_flags.keys.each do |key|
      other_linker_flags[key].merge(xcconfig.other_linker_flags[key])
    end
  else
    merge_attributes!(xcconfig.to_hash)
    if flags = attributes.delete('OTHER_LDFLAGS')
      flags_by_key = OtherLinkerFlagsParser.parse(flags)
      other_linker_flags.keys.each do |key|
        other_linker_flags[key].merge(flags_by_key[key])
      end
    end
  end
end

def merge_attributes!(attributes)

Returns:
  • (void) -

Parameters:
  • attributes (Hash) --
def merge_attributes!(attributes)
  @attributes.merge!(attributes) do |_, v1, v2|
    v1, v2 = v1.strip, v2.strip
    existing = v1.strip.shellsplit
    existing.include?(v2) ? v1 : "#{v1} #{v2}"
  end
end

def normalized_xcconfig_path(path)

Returns:
  • (String) - The normalized path.

Parameters:
  • path (String) --
def normalized_xcconfig_path(path)
  if File.extname(path) == '.xcconfig'
    path
  else
    "#{path}.xcconfig"
  end
end

def save_as(pathname, prefix = nil)

Returns:
  • (void) -

Parameters:
  • pathname (Pathname) --
def save_as(pathname, prefix = nil)
  if File.exist?(pathname)
    return if Config.new(pathname) == self
  end
  pathname.open('w') { |file| file << to_s(prefix) }
end

def strip_comment(line)

Returns:
  • (String) - the uncommented line.

Parameters:
  • line (String) --
def strip_comment(line)
  line.partition('//').first
end

def to_hash(prefix = nil)

Returns:
  • (Hash) - The hash representation

Other tags:
    Note: - All the values are sorted to have a consistent output in Ruby
def to_hash(prefix = nil)
  list = []
  list += other_linker_flags[:simple].to_a.sort
  modifiers = {
    :frameworks => '-framework ',
    :weak_frameworks => '-weak_framework ',
    :libraries => '-l',
    :force_load => '-force_load',
  }
  [:libraries, :frameworks, :weak_frameworks, :force_load].each do |key|
    modifier = modifiers[key]
    sorted = other_linker_flags[key].to_a.sort
    if key == :force_load
      list += sorted.map { |l| %(#{modifier} #{l}) }
    else
      list += sorted.map { |l| %(#{modifier}"#{l}") }
    end
  end
  result = attributes.dup
  result['OTHER_LDFLAGS'] = list.join(' ') unless list.empty?
  if prefix
    Hash[result.map { |k, v| [prefix + k, v] }]
  else
    result
  end
end

def to_s(prefix = nil)

Returns:
  • (String) - The serialized internal data.
def to_s(prefix = nil)
  include_lines = includes.map { |path| "#include \"#{normalized_xcconfig_path(path)}\"" }
  settings = to_hash(prefix).sort_by(&:first).map { |k, v| "#{k} = #{v}" }
  [include_lines + settings].join("\n")
end

def weak_frameworks

Returns:
  • (Set) - The list of the *weak* frameworks required by
def weak_frameworks
  other_linker_flags[:weak_frameworks]
end