Class: Fastlane::Actions::XamarinBuildAction

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

Constant Summary collapse

MDTOOL =
'/Applications/Xamarin\ Studio.app/Contents/MacOS/mdtool'.freeze
XBUILD =
'/Library/Frameworks/Mono.framework/Commands/xbuild'.freeze
BUILD_TYPES =
%w(Release Debug).freeze
[true, false].freeze
BUILD_UTIL =
%w(xbuild mdtool).freeze

Class Method Summary collapse

Class Method Details

.authorsObject



102
103
104
# File 'lib/fastlane/plugin/xamarin_build/actions/xamarin_build_action.rb', line 102

def self.authors
  ['punksta']
end

.available_optionsObject



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/fastlane/plugin/xamarin_build/actions/xamarin_build_action.rb', line 110

def self.available_options
  [
    FastlaneCore::ConfigItem.new(
      key: :solution,
        env_name: 'FL_XAMARIN_BUILD_SOLUTION',
        description: 'path to Xamarin .sln file',
        verify_block: proc do |value|
          UI.user_error!('File not found'.red) unless File.file? value
        end
    ),

    FastlaneCore::ConfigItem.new(
      key: :platform,
      env_name: 'FL_XAMARIN_BUILD_PLATFORM',
      description: 'build platform',
      type: String
    ),

    FastlaneCore::ConfigItem.new(
        key: :build_type,
        env_name: 'FL_XAMARIN_BUILD_TYPE',
        description: 'Release or Debug',
        type: String
    ),

    FastlaneCore::ConfigItem.new(
      key: :target,
      env_name: 'FL_XAMARIN_BUILD_TARGET',
      description: 'Target build type',
      type: String
    ),

    FastlaneCore::ConfigItem.new(
      key: :print_all,
      env_name: 'FL_XAMARIN_BUILD_PRINT_ALL',
      description: 'Print std out',
      default_value: true,
      is_string: false,
      optional: true,
      verify_block: proc do |value|
        UI.user_error!("Unsupported value! Use one of #{PRINT_ALL.join '\' '}".red) unless PRINT_ALL.include? value
      end
    ),

    FastlaneCore::ConfigItem.new(
        key: :build_util,
        env_name: 'FL_XAMARIN_BUILD_BUILD_UTIL',
        description: 'Build util which use to build project. mdtool',
        default_value: 'mdtool',
        is_string: false,
        optional: true,
        verify_block: proc do |value|
          UI.user_error!("Unsupported build util! Une of #{BUILD_UTIL.join '\' '}".red) unless BUILD_UTIL.include? value
        end
    ),

    FastlaneCore::ConfigItem.new(
        key: :project,
        env_name: 'FL_XAMARIN_BUILD_PROJECT',
        description: 'Project to build or clean',
        is_string: true,
        optional: true
    ),

    FastlaneCore::ConfigItem.new(
        key: :projects,
        env_name: 'FL_XAMARIN_BUILD_PROJECTS',
        description: 'Projects to build or clean, separated by ,',
        is_string: true,
        optional: true
    )
  ]
end

.descriptionObject



98
99
100
# File 'lib/fastlane/plugin/xamarin_build/actions/xamarin_build_action.rb', line 98

def self.description
  'Build xamarin android and ios projects'
end

.get_build_path(platform, build_type, solution) ⇒ Object

Returns bin path for given platform and build_type or nil



84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/fastlane/plugin/xamarin_build/actions/xamarin_build_action.rb', line 84

def self.get_build_path(platform, build_type, solution)
  root = File.dirname(solution)

  build = Dir.glob(File.join(root, "*/bin/#{platform}/#{build_type}/"))

  if build.size > 0
    b = build[0]
    UI.message("build artifact path #{b}".blue)
    return b
  else
    return nil
  end
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


184
185
186
187
# File 'lib/fastlane/plugin/xamarin_build/actions/xamarin_build_action.rb', line 184

def self.is_supported?(platform)
  # android not tested
  [:ios, :android].include?(platform)
end

.mdtool_build_projects(params, projects) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/fastlane/plugin/xamarin_build/actions/xamarin_build_action.rb', line 39

def self.mdtool_build_projects(params, projects)
  platform = params[:platform]
  build_type = params[:build_type]
  target = params[:target]
  solution = params[:solution]

  for project in projects
    configuration = "--configuration:#{build_type}|#{platform}"
    command = "#{MDTOOL} build -t:#{target} -p:#{project} #{solution} \"#{configuration}\""
    Helper::XamarinBuildHelper.bash(command, !params[:print_all])
  end

end

.mdtool_build_solution(params) ⇒ Object



72
73
74
75
76
77
78
79
80
81
# File 'lib/fastlane/plugin/xamarin_build/actions/xamarin_build_action.rb', line 72

def self.mdtool_build_solution(params)
  platform = params[:platform]
  build_type = params[:build_type]
  target = params[:target]
  solution = params[:solution]

  configuration = "--configuration:#{build_type}|#{platform}"
  command = "#{MDTOOL} build -t:#{target} #{solution} \"#{configuration}\""
  Helper::XamarinBuildHelper.bash(command, !params[:print_all])
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
# File 'lib/fastlane/plugin/xamarin_build/actions/xamarin_build_action.rb', line 7

def self.run(params)
  platform = params[:platform]
  project = params[:project]

  projects = (params[:projects] or '').split(',').select do |item|
    item.size > 0
  end

  projects << project if project != nil
  projects = projects.uniq

  if params[:build_util] == 'mdtool'
    if projects.size > 0
      mdtool_build_projects(params, projects)
    else
      mdtool_build_solution(params)
    end
  else
    if projects.size > 0
      puts "echo 'not supported yet'"
    else
      xbuild_build_solution(params)
    end
  end

  build_type = params[:build_type]
  solution = params[:solution]
  get_build_path(platform, build_type, solution)
end

.xbuild_build_solution(params) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/fastlane/plugin/xamarin_build/actions/xamarin_build_action.rb', line 53

def self.xbuild_build_solution(params)
  platform = params[:platform]
  build_type = params[:build_type]
  target = params[:target]
  solution = params[:solution]

  command = "#{XBUILD} "
  command << "/target:#{target} " if target != nil
  command << "/p:Platform=#{platform} " if platform != nil
  command << "/p:Configuration=#{build_type} " if build_type != nil
  command << solution

  Helper::XamarinBuildHelper.bash(command, !params[:print_all])
end