Class: Fastlane::Actions::GetInfoPlistPathAction

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

Documentation collapse

Class Method Summary collapse

Class Method Details

.authorsObject



114
115
116
# File 'lib/fastlane/plugin/versioning/actions/get_info_plist_path.rb', line 114

def self.authors
  ["SiarheiFedartsou"]
end

.available_optionsObject



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/fastlane/plugin/versioning/actions/get_info_plist_path.rb', line 84

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :xcodeproj,
                                 env_name: "FL_INFO_PLIST_PROJECT",
                                 description: "Optional, you must specify the path to your main Xcode project if it is not in the project root directory or if you have multiple *.xcodeproj's in the root directory",
                                 optional: true,
                                 verify_block: proc do |value|
                                   UI.user_error!("Please pass the path to the project, not the workspace") if value.end_with? ".xcworkspace"
                                   UI.user_error!("Could not find Xcode project at path '#{File.expand_path(value)}'") if !File.exist?(value) and !Helper.is_test?
                                 end),
    FastlaneCore::ConfigItem.new(key: :target,
                                 env_name: "FL_INFO_PLIST_TARGET",
                                 optional: true,
                                 conflicting_options: [:scheme],
                                 description: "Specify a specific target if you have multiple per project, optional"),
    FastlaneCore::ConfigItem.new(key: :scheme,
                                 env_name: "FL_INFO_PLIST_SCHEME",
                                 optional: true,
                                 conflicting_options: [:target],
                                 description: "Specify a specific scheme if you have multiple per project, optional"),
    FastlaneCore::ConfigItem.new(key: :build_configuration_name,
                                 optional: true,
                                 description: "Specify a specific build configuration if you have different Info.plist build settings for each configuration"),
    FastlaneCore::ConfigItem.new(key: :skip_package_dependencies_resolution,
                                 description: "Skips resolution of Swift Package Manager dependencies",
                                 type: Boolean,
                                 default_value: false)
  ]
end

.descriptionObject



76
77
78
# File 'lib/fastlane/plugin/versioning/actions/get_info_plist_path.rb', line 76

def self.description
  "Get the version number of your project"
end

.detailsObject



80
81
82
# File 'lib/fastlane/plugin/versioning/actions/get_info_plist_path.rb', line 80

def self.details
  'This action will return path to Info.plist for specific target in your project.'
end

.find_path_using_scheme(params) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/fastlane/plugin/versioning/actions/get_info_plist_path.rb', line 55

def self.find_path_using_scheme(params)
  config = {
    project: params[:xcodeproj],
    scheme: params[:scheme],
    configuration: params[:build_configuration_name],
    skip_package_dependencies_resolution: params[:skip_package_dependencies_resolution]
  }
  project = FastlaneCore::Project.new(config)
  project.select_scheme

  path = project.build_settings(key: 'INFOPLIST_FILE')
  unless (Pathname.new path).absolute?
    path = File.join(Pathname.new(project.path).parent.to_path, path)
  end
  path
end

.find_path_using_target(params) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/fastlane/plugin/versioning/actions/get_info_plist_path.rb', line 24

def self.find_path_using_target(params)
  project = Xcodeproj::Project.open(params[:xcodeproj])
  if params[:target]
    target = project.targets.detect { |t| t.name == params[:target] }
  else
    # firstly we are trying to find modern application target
    target = project.targets.detect do |t|
      t.kind_of?(Xcodeproj::Project::Object::PBXNativeTarget) &&
        t.product_type == 'com.apple.product-type.application'
    end
    target = project.targets[0] if target.nil?
  end

  # This ensures we get correctly resolved variables against present configuration files.
  plist = target.resolved_build_setting('INFOPLIST_FILE', true)
  UI.user_error! 'Cannot resolve Info.plist build setting. Check it\'s defined or try defining it explicitly on the target without variables.' if plist.nil? || plist.empty?

  if !(build_configuration_name = params[:build_configuration_name]).nil?
    plist = plist[build_configuration_name]
    UI.user_error! "Cannot resolve Info.plist build setting for #{build_configuration_name}." if plist.nil?
  else
    plist = plist.values.compact.uniq
    UI.user_error! 'Cannot accurately resolve Info.plist build setting, try specifying :build_configuration_name.' if plist.count > 1
    plist = plist.first
  end

  path = plist.gsub('SRCROOT', project.path.parent.to_path)
  path = File.join(project.path.parent.to_path, path) unless (Pathname.new path).absolute?
  path
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


118
119
120
# File 'lib/fastlane/plugin/versioning/actions/get_info_plist_path.rb', line 118

def self.is_supported?(platform)
  %i[ios mac].include? platform
end

.run(params) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/fastlane/plugin/versioning/actions/get_info_plist_path.rb', line 7

def self.run(params)
  unless params[:xcodeproj]
    if Helper.test?
      params[:xcodeproj] = "/tmp/fastlane/tests/fastlane/xcodeproj/bundle.xcodeproj"
    else
      params[:xcodeproj] = Dir["*.xcodeproj"][0] unless params[:xcodeproj]
    end
  end

  if params[:target]
    path = find_path_using_target(params)
  else
    path = find_path_using_scheme(params)
  end
  path
end