Class: Fastlane::Helper::XcconfigActionsHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/xcconfig_actions/helper/xcconfig_actions_helper.rb

Overview

Helper module for Xcconfig actions plugin.

Class Method Summary collapse

Class Method Details

.command_exist?(cmd) ⇒ Boolean

Check if shell command exists.

Parameters:

  • cmd (String)

    Shell command.

Returns:

  • (Boolean)

    A Boolean indicating whether the shell command exists.



12
13
14
# File 'lib/fastlane/plugin/xcconfig_actions/helper/xcconfig_actions_helper.rb', line 12

def self.command_exist?(cmd)
  `which #{cmd} 2>/dev/null`.chomp != ""
end

.find_xcspec(name, xcode:) ⇒ String

Find xcspec by name.

Parameters:

  • name (String)

    Xcspec name.

  • xcode (String)

    Path to Xcode app or Xcode version for version of bundled xcspecs, e.g. “10.2”.

Returns:

  • (String)

    Path to xcspec file.



54
55
56
57
58
59
60
61
# File 'lib/fastlane/plugin/xcconfig_actions/helper/xcconfig_actions_helper.rb', line 54

def self.find_xcspec(name, xcode:)
  search_path = File.exist?(xcode) ? File.join(xcode, "Contents/{Plugins,Developer/Platforms/MacOSX.platform/Developer/Library/Xcode/Specifications}") : File.join(File.dirname(__FILE__), "xcspecs", xcode)

  query = File.join(search_path, "**", name + ".xcspec")
  xcspec = Dir.glob(query, File::FNM_CASEFOLD).first
  UI.user_error!("Can't find xcspec with name: #{name}") unless xcspec && File.exist?(xcspec)
  xcspec
end

.read_xcconfig(path) ⇒ Hash

Read xcconfig and return hash with ‘config’ and ‘includes’ entries. ‘config’ containing the hash-map of resolved variables, ‘includes’ containing an array of include paths. The config values are not resolved.

Parameters:

  • path (String)

    Xcconfig path.

Returns:

  • (Hash)

    Dictionary representing xcconfig.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/fastlane/plugin/xcconfig_actions/helper/xcconfig_actions_helper.rb', line 28

def self.read_xcconfig(path)
  # Get rid of comments and blank lines.
  contents = File.read(path).gsub(%r{\s*//.*$}, "").gsub(/^$\n/, "")
  # Collect all include statements.
  includes_regex = /^\s*#include\s*"(.*)"$/
  includes = contents.scan(includes_regex).flatten
  # Get rid of include statements (makes it easier).
  contents = contents.gsub(includes_regex, "")
  # Collect all variable assignments.
  config = contents.scan(/^\s*([^=]*)=(.*)$/).reduce({}) do |acc, e|
    k = e[0].strip
    v = e[1].strip
    acc.merge({ k => v })
  end

  # Return.
  {
    config: config,
    includes: includes
  }
end

.show_messageObject

class methods that you define here become available in your action as ‘Helper::XcconfigActionsHelper.your_method`



18
19
20
# File 'lib/fastlane/plugin/xcconfig_actions/helper/xcconfig_actions_helper.rb', line 18

def self.show_message
  UI.message("Hello from the xcconfig_actions plugin helper!")
end