class XcodeArchiveCache::BuildSettings::Filter

Constants

PATH_FLAGS

most of these are unlikely to be used, most used are -I -L -F -iquote -isystem

first part is from Clang, second is from swiftc some flags mean the same for both compilers

SETTINGS_TO_KEEP

TODO: extend

SETTINGS_TO_STRIP

Public Instance Methods

filter(settings, settings_to_keep = SETTINGS_TO_KEEP) click to toggle source

@param [Hash{String => String}] settings

@return [Hash{String => String}]

Meaningful settings affecting build result Machine-dependent settings i.e. paths, user names, group names are rejected

# File lib/build_settings/filter.rb, line 12
def filter(settings, settings_to_keep = SETTINGS_TO_KEEP)
  filtered_settings = settings.select { |name, _| settings_to_keep.include?(name) }
  SETTINGS_TO_STRIP.each do |name|
    value = filtered_settings[name]
    next if value == nil

    filtered_settings[name] = strip(value)
  end

  filtered_settings
end

Private Instance Methods

strip(value) click to toggle source

@param [String] value

@return [String]

# File lib/build_settings/filter.rb, line 30
def strip(value)
  # one can quote flag (like Pods do with "-D" "COCOAPODS");
  # we can safely ignore those quotes as long as
  # we won't pass our return value to any (compiler / linker) calls
  #
  # leaving quotes may lead to weird situations:
  # having value: -iquote "-D" "COCOAPODS"
  # we're going to get output: -D" "COCOAPODS"
  # because leading quote of -D becomes a part of -iquote string after split,
  # and we delete all iquotes
  #
  value_without_quotes = value.gsub(/["']/, "")

  # in case if we meet a path like "/some/dir/something -else",
  # splitting will be broken, but probability of
  # someone using such path is quite low (or it isn't ?)
  #
  value_components = value_without_quotes
                         .split(/^-|\s-/)
                         .select { |component| component.length > 0 }

  index = 0
  indices_to_remove = []
  while index < value_components.length do
    component = value_components[index]

    PATH_FLAGS.each do |flag|
      if component.start_with?(flag)
        indices_to_remove += [index]
        break
      end
    end

    index += 1
  end

  kept_components = []
  value_components.each_with_index do |component, component_index|
    kept_components.push(component) unless indices_to_remove.include?(component_index)
  end

  result = kept_components.join(" -")
  result.length > 0 ? "-#{result}" : ""
end