Class: Fastlane::Actions::XcodeToolsSelectAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/xcode_tools_select/actions/xcode_tools_select_action.rb

Class Method Summary collapse

Class Method Details

.authorsObject



42
43
44
# File 'lib/fastlane/plugin/xcode_tools_select/actions/xcode_tools_select_action.rb', line 42

def self.authors
  ["Vincent HO-SUNE"]
end

.available_optionsObject



46
47
48
49
50
51
52
53
54
# File 'lib/fastlane/plugin/xcode_tools_select/actions/xcode_tools_select_action.rb', line 46

def self.available_options
  [
     FastlaneCore::ConfigItem.new(key: :version,
                             env_name: "XCODE_TOOLS_SELECT_VERSION",
                          description: "Version of Xcode to select",
                             optional: false,
                                 type: String)
  ]
end

.categoryObject



67
68
69
# File 'lib/fastlane/plugin/xcode_tools_select/actions/xcode_tools_select_action.rb', line 67

def self.category
  :building
end

.descriptionObject



38
39
40
# File 'lib/fastlane/plugin/xcode_tools_select/actions/xcode_tools_select_action.rb', line 38

def self.description
  "Set the [version] of the default Xcode Command Line Tools path to use."
end

.example_codeObject



61
62
63
64
65
# File 'lib/fastlane/plugin/xcode_tools_select/actions/xcode_tools_select_action.rb', line 61

def self.example_code
  [
    'xcode_tools_select(version: "10.*")'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
59
# File 'lib/fastlane/plugin/xcode_tools_select/actions/xcode_tools_select_action.rb', line 56

def self.is_supported?(platform)
  [:ios, :mac].include?(platform)
  true
end

.run(params) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/fastlane/plugin/xcode_tools_select/actions/xcode_tools_select_action.rb', line 7

def self.run(params)      
  required_version = params[:version]

  UI.message("Search for Xcode Command Line Tools with version: #{required_version}")
  
  # Search for Xcode paths
  output = Actions.sh_no_action("mdfind -0 'kMDItemCFBundleIdentifier = 'com.apple.dt.Xcode' && kMDItemVersion = '#{required_version}''", log: false)

  UI.user_error!("Xcode matching version `#{required_version}` not found !") unless !output.empty?

  paths = output.split("\0")
  paths.each do |line|
    UI.message("found: #{line} ")
  end

  # Select the first matching one
  xcode_path = paths.first
  xcode_tools_path = File.join(xcode_path, "/Contents/Developer")
  
  # Verify that the path exists
  UI.user_error!("Path '#{xcode_tools_path}' doesn't exist") unless Dir.exist?(xcode_tools_path)

  # Get the exact Version found
  itemVersion = Actions.sh_no_action("mdls -name 'kMDItemVersion' -raw #{xcode_path}", log: false)

  UI.message("Setting Xcode version #{itemVersion} to #{xcode_tools_path} for all build steps")
  
  ENV["DEVELOPER_DIR"] = xcode_tools_path

end