class Fastlane::Actions::BuildSettingsToFlagsAction

Action to map build settings to build flags.

Public Class Methods

authors() click to toggle source

Plugin action authors.

# File lib/fastlane/plugin/xcconfig_actions/actions/build_settings_to_flags_action.rb, line 90
def self.authors
  ["Maksym Grebenets"]
end
available_options() click to toggle source

Plugin action available options.

# File lib/fastlane/plugin/xcconfig_actions/actions/build_settings_to_flags_action.rb, line 115
def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :build_settings,
                            env_name: "XCCONFIG_ACTIONS_BUILD_FLAGS_BUILD_SETTINGS",
                         description: "Build settings to convert to build flags",
                            optional: true,
                                type: Hash,
                        verify_block: proc do |value|
                                        UI.user_error!("Missing build settings") if value.nil?
                                      end),
    FastlaneCore::ConfigItem.new(key: :xcode,
                            env_name: "XCCONFIG_ACTIONS_BUILD_FLAGS_XCODE",
                         description: "Xcode version of path to Xcode.app",
                            optional: true,
                       default_value: "10.2",
                                type: String),
    FastlaneCore::ConfigItem.new(key: :output_path,
                            env_name: "XCCONFIG_ACTIONS_BUILD_FLAGS_OUTPUT_PATH",
                         description: "Output path to save build settings JSON",
                            optional: true,
                                type: String)
  ]
end
category() click to toggle source

Plugin action category.

# File lib/fastlane/plugin/xcconfig_actions/actions/build_settings_to_flags_action.rb, line 110
def self.category
  :building
end
description() click to toggle source

Plugin action description.

# File lib/fastlane/plugin/xcconfig_actions/actions/build_settings_to_flags_action.rb, line 85
def self.description
  "Map xcconfig build settings to compiler and linker build flags"
end
details() click to toggle source

Plugin action details.

# File lib/fastlane/plugin/xcconfig_actions/actions/build_settings_to_flags_action.rb, line 100
def self.details
  [
    "Build flags keys:",
    "- compiler_flags: CXX compiler flags for clang compiler",
    "- swift_compiler_flags: Compiler flags for Swift compiler",
    "- linker_flags: Linker flags for clang linker (Cxx and Swift)"
  ].join("\n")
end
is_supported?(platform) click to toggle source

Check if platform is supported by the action. @param [Symbol] platform Platform to check. @return [Boolean] A Boolean indicating whether the platform is supported by the action.

# File lib/fastlane/plugin/xcconfig_actions/actions/build_settings_to_flags_action.rb, line 142
def self.is_supported?(platform)
  [:ios, :mac].include?(platform)
end
load_complete_spec(name, xcode:) click to toggle source

Load complete spec. @param [String] name Name of the xcspec. @param [String] xcode Path to or version of Xcode. @return [Xcspec] Xcspec that includes Core Build System options.

# File lib/fastlane/plugin/xcconfig_actions/actions/build_settings_to_flags_action.rb, line 64
def self.load_complete_spec(name, xcode:)
  Xcspec.new(
    ActionHelper.find_xcspec(name, xcode: xcode),
    core_build_system_spec: load_spec("CoreBuildSystem*", xcode: xcode)
  )
end
load_spec(name, xcode:) click to toggle source

Load xcspec. @param [String] name Spec name. @param [String] xcode Path to or version of Xcode. @return [Xcspec] Loaded xcspecs.

# File lib/fastlane/plugin/xcconfig_actions/actions/build_settings_to_flags_action.rb, line 75
def self.load_spec(name, xcode:)
  spec_path = ActionHelper.find_xcspec(name, xcode: xcode)
  Xcspec.new(spec_path)
end
return_value() click to toggle source

Plugin action return value.

# File lib/fastlane/plugin/xcconfig_actions/actions/build_settings_to_flags_action.rb, line 95
def self.return_value
  "Build flags dictionary"
end
run(params) click to toggle source

Run action. @param [Hash] params Action parameters. @return [Hash] Build flags.

# File lib/fastlane/plugin/xcconfig_actions/actions/build_settings_to_flags_action.rb, line 22
def self.run(params)
  build_settings = params[:build_settings] || Actions.lane_context[SharedValues::XCCONFIG_ACTIONS_BUILD_SETTINGS]
  UI.user_error!("Missing build settings input") unless build_settings
  xcode = params[:xcode]

  # TODO: Add support for com.apple.compilers.llvm.clang.1_0.analyzer tool.
  clang_spec = load_complete_spec("Clang*", xcode: xcode)
  swift_spec = load_complete_spec("Swift*", xcode: xcode)
  linker_spec = load_complete_spec("Ld*", xcode: xcode)

  clang_mapping = clang_spec.map_build_settings(build_settings)
  swift_mapping = swift_spec.map_build_settings(build_settings)
  linker_mapping = linker_spec.map_build_settings(build_settings)

  flags = {
    "compiler_flags" => clang_mapping.flags,
    "swift_compiler_flags" => swift_mapping.flags,
    "linker_flags" => [
      linker_mapping.flags,
      linker_mapping.linker_flags,
      clang_mapping.linker_flags,
      swift_mapping.linker_flags
    ].reject(&:empty?).join(" ")
  }

  Actions.lane_context[SharedValues::XCCONFIG_ACTIONS_BUILD_FLAGS] = flags

  if params[:output_path]
    File.open(params[:output_path], "w") { |f| f.puts(flags.to_json) }
  else
    return flags
  end
end