fastlane-plugin-clang_tools 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c973cacd9d7e8c7f6ffb64fd97822317b4e1cfbb44a7e32ec36b7a717b484e71
4
- data.tar.gz: 81a60ad8463ee3ea9a5624b77f6f592236c5630bfef07f14b0892dbaf4ee8c25
3
+ metadata.gz: 4eef3741c5bbfce072759ccf54c9318e43e01afc07211871c8527d7952e94495
4
+ data.tar.gz: 77643735adb58fcc6c6da0cf2ba9e66e3c66b23b23f035a76328726126b6565d
5
5
  SHA512:
6
- metadata.gz: 92c022944ee859ec05f21b3a5d287690f3c282abe0d095928d478534d17a588f482f13bfa378cda899cc3742121d30638e33dfa28d00bedb4ee81c35f3c072d5
7
- data.tar.gz: 497c467a11adfab75b20c45f96f399baed3750bd2188401e0935fbb3756c85b1ed3d451b2caed2e31f273ea9fb24d7e082ef1a377ffe750793fd22276c5ca029
6
+ metadata.gz: a9bb793e4eacfd8e83dc59c6deb716937f950038f1bf39ea5d33f2f3be94230e6658e3e2d6ef6a7838c24641b17368eaffcab323b26838624ac084bf3729f9b9
7
+ data.tar.gz: 4437a709b9848134501ea9f7cd3b624fd7c3f55999b6cd7a8ec0e00236d076bf896e8564df83e56cc2da1041fe6c993e96d503334563b9b3bcc38f9e85b92518
@@ -1,16 +1,16 @@
1
1
  require 'nokogiri'
2
2
 
3
3
  require 'fastlane/action'
4
- require_relative '../helper/clang_analyzer_helper'
4
+ require_relative '../helper/clang_tools_helper'
5
5
 
6
6
  module Fastlane
7
7
  module Actions
8
8
  class ClangAnalyzerAction < Action
9
9
  def self.run(params)
10
10
  # Parse CLI parameters
11
- analyze_params = prepare(params)
11
+ analyze_params, err_msg = prepare(params)
12
12
  if analyze_params.nil?
13
- puts('ERROR : Invalid parameters. Exiting ......')
13
+ puts(Helper::ClangToolsHelper.is_empty?(err_msg) ? 'ERROR : Invalid parameters. Exiting ......' : err_msg)
14
14
  return
15
15
  end
16
16
 
@@ -35,27 +35,42 @@ module Fastlane
35
35
  def self.prepare(params)
36
36
  if params.nil?
37
37
  analyze_params = nil
38
+ err_msg = 'ERROR : No input parameters. Exiting ......'
38
39
  else
39
40
  analyze_params = {}
41
+ err_msg = nil
40
42
 
41
43
  params.all_keys.each do |item|
42
- unless params[item].nil? || params[item].empty?
44
+ unless Helper::ClangToolsHelper.is_empty?(params[item])
43
45
  analyze_params[item] = params[item]
44
46
  end
45
47
  end
46
48
 
49
+ # Check if only the .xcworkspace specified or only the .xcodeproj specified
50
+ if analyze_params.key?(:workspace) && analyze_params.key?(:project)
51
+ return [nil, 'ERROR : ".xcworkspace" and ".xcodeproj" cannot be specified at the same time. Exiting ......']
52
+ end
53
+ if !analyze_params.key?(:workspace) && !analyze_params.key?(:project)
54
+ return [nil, 'ERROR : ".xcworkspace" or ".xcodeproj" must be specified. Exiting ......']
55
+ end
56
+
57
+ unless analyze_params.key?(:configuration)
58
+ analyze_params[:configuration] = 'Debug'
59
+ end
60
+
47
61
  # The default output_format is 'plist-html'
48
62
  unless analyze_params.key?(:output_format)
49
63
  analyze_params[:output_format] = 'plist-html'
50
64
  end
51
65
  # For CI/CD convenience, this action only supports 'plist' or 'plist-html' as output_format
52
66
  unless analyze_params[:output_format].include?('plist')
53
- return nil
67
+ return [nil, 'ERROR : Invalid "output_format". Exiting ......']
54
68
  end
55
69
 
56
70
  # The default output_dir is './static_analysis'
71
+ project = Helper::ClangToolsHelper.pick_non_empty(params[:workspace], params[:project])
57
72
  unless analyze_params.key?(:output_dir)
58
- analyze_params[:output_dir] = './static_analysis'
73
+ analyze_params[:output_dir] = "#{File.dirname(File.realpath(project))}/static_analysis"
59
74
  end
60
75
  FileUtils.mkdir_p(analyze_params[:output_dir]) unless File.exist?(analyze_params[:output_dir])
61
76
  analyze_params[:output_compile_commands] = "#{analyze_params[:output_dir]}/compile_commands.json"
@@ -63,10 +78,10 @@ module Fastlane
63
78
  analyze_params[:output_report_dir] = "#{analyze_params[:output_dir]}/report-#{Time.new.strftime('%Y%m%d%H%M%S')}"
64
79
  FileUtils.mkdir_p(analyze_params[:output_report_dir]) unless File.exist?(analyze_params[:output_report_dir])
65
80
 
66
- analyze_params[:output_summary_file] = 'clang_analyzer_summary.xml'
81
+ analyze_params[:output_summary_file] = 'clang_analysis_report.xml'
67
82
  end
68
83
 
69
- analyze_params
84
+ [analyze_params, err_msg]
70
85
  end
71
86
 
72
87
  def self.xcode_build(params)
@@ -77,23 +92,21 @@ module Fastlane
77
92
  # xcodebuild executive
78
93
  cmd_line << (params.key?(:xcodebuild) ? params[:xcodebuild] : 'xcodebuild')
79
94
 
95
+ # -workspace
96
+ if params.key?(:workspace)
97
+ cmd_line << "-workspace #{params[:workspace]}"
80
98
  # -project
81
- if params.key?(:project)
99
+ elsif params.key?(:project)
82
100
  cmd_line << "-project #{params[:project]}"
83
- else
84
- # -workspace
85
- if params.key?(:workspace)
86
- cmd_line << "-workspace #{params[:workspace]}"
87
- end
101
+ end
88
102
 
89
- # -scheme
90
- if params.key?(:scheme)
91
- cmd_line << "-scheme #{params[:scheme]}"
92
- end
103
+ # -scheme
104
+ if params.key?(:scheme)
105
+ cmd_line << "-scheme #{params[:scheme]}"
93
106
  end
94
107
 
95
108
  # xcode configuration
96
- cmd_line << (params.key?(:configuration) ? "-configuration #{params[:configuration]}" : '-configuration Debug')
109
+ cmd_line << "-configuration #{params[:configuration]}"
97
110
 
98
111
  # build command
99
112
  cmd_line << 'clean'
@@ -148,29 +161,45 @@ module Fastlane
148
161
  issues = []
149
162
  plist_files.each { |plist_file| parse_plist("#{params[:output_report_dir]}/#{plist_file}", issues) }
150
163
 
151
- ordered_issues = parse_issues(issues)
164
+ grouped_issues = parse_issues(issues)
152
165
  builder = Nokogiri::XML::Builder.new do |xml|
153
- xml.IssueList do
154
- ordered_issues.values.each do |issue_entry|
155
- issue_entry.each do |issue|
156
- xml.Issue do
157
- xml.Checker(issue['checker'])
158
- xml.Category(issue['category'])
159
- xml.Type(issue['type'])
160
- xml.Message(issue['message'])
161
- xml.Source(issue['source_file'])
162
- xml.Line(issue['line'])
163
- xml.Col(issue['col'])
164
- xml.Context(issue['context'])
165
- xml.ContextKind(issue['context_kind'])
166
- xml.HtmlAttachments do
167
- issue['html_details'].each do |html|
168
- xml.Attachment(html)
169
- end
170
- end
171
- end
166
+ xml.Report do
167
+ xml.Summary do
168
+ project = Helper::ClangToolsHelper.pick_non_empty(params[:workspace], params[:project])
169
+ if project.nil?
170
+ raise 'ERROR : Invalid Project!'
172
171
  end
172
+
173
+ xml.Project(project)
174
+ xml.ReportDirectory(params[:output_report_dir])
175
+ xml.ReportFormat(params[:output_format])
176
+ xml.IssueCount(grouped_issues.size)
173
177
  end
178
+
179
+ next if Helper::ClangToolsHelper.is_empty?(grouped_issues)
180
+
181
+ xml.IssueList do
182
+ grouped_issues.values.each do |issue_entry|
183
+ issue_entry.each do |issue|
184
+ xml.Issue do
185
+ xml.Checker(issue['checker'])
186
+ xml.Category(issue['category'])
187
+ xml.Type(issue['type'])
188
+ xml.Message(issue['message'])
189
+ xml.Source(issue['source_file'])
190
+ xml.Line(issue['line'])
191
+ xml.Col(issue['col'])
192
+ xml.Context(issue['context'])
193
+ xml.ContextKind(issue['context_kind'])
194
+ xml.HtmlAttachments do
195
+ issue['html_details'].each do |html|
196
+ xml.Attachment(html)
197
+ end
198
+ end
199
+ end # xml.Issue
200
+ end # issue_entry
201
+ end # grouped_issues.values
202
+ end # xml.IssueList
174
203
  end
175
204
  end
176
205
 
@@ -256,12 +285,12 @@ module Fastlane
256
285
  # The corresponding source file of the plist file
257
286
  # Noted : the length of 'files' will always be 1 now
258
287
  plist_files = plist['files']
259
- if plist_files.nil? || plist_files.size.zero?
288
+ if Helper::ClangToolsHelper.is_empty?(plist_files)
260
289
  return
261
290
  end
262
291
 
263
292
  plist_diagnostics = plist['diagnostics']
264
- if plist_diagnostics.nil? || plist_diagnostics.size.zero?
293
+ if Helper::ClangToolsHelper.is_empty?(plist_diagnostics)
265
294
  return
266
295
  end
267
296
 
@@ -284,22 +313,22 @@ module Fastlane
284
313
  end
285
314
 
286
315
  def self.parse_issues(issues)
287
- ordered_issues = {}
316
+ grouped_issues = {}
288
317
 
289
- if issues.nil? || issues.size.zero?
290
- return ordered_issues
318
+ if Helper::ClangToolsHelper.is_empty?(issues)
319
+ return grouped_issues
291
320
  end
292
321
 
293
322
  issues.each do |issue|
294
323
  issue_key = issue['checker']
295
324
 
296
- unless ordered_issues.key?(issue_key)
297
- ordered_issues[issue_key] = []
325
+ unless grouped_issues.key?(issue_key)
326
+ grouped_issues[issue_key] = []
298
327
  end
299
- ordered_issues[issue_key] << issue
328
+ grouped_issues[issue_key] << issue
300
329
  end
301
330
 
302
- ordered_issues
331
+ grouped_issues
303
332
  end
304
333
 
305
334
  def self.description
@@ -321,14 +350,14 @@ module Fastlane
321
350
 
322
351
  def self.available_options
323
352
  [
324
- FastlaneCore::ConfigItem.new(key: :project,
325
- description: 'The xcode project',
326
- optional: true,
327
- type: String),
328
353
  FastlaneCore::ConfigItem.new(key: :workspace,
329
354
  description: 'The xcode workspace',
330
355
  optional: true,
331
356
  type: String),
357
+ FastlaneCore::ConfigItem.new(key: :project,
358
+ description: 'The xcode project',
359
+ optional: true,
360
+ type: String),
332
361
  FastlaneCore::ConfigItem.new(key: :scheme,
333
362
  description: 'The scheme of xcode project',
334
363
  optional: true,
@@ -0,0 +1,32 @@
1
+ require 'fastlane_core/ui/ui'
2
+
3
+ module Fastlane
4
+ UI = FastlaneCore::UI unless Fastlane.const_defined?('UI')
5
+
6
+ module Helper
7
+ class ClangToolsHelper
8
+ def self.is_empty?(obj)
9
+ if obj.nil?
10
+ return true
11
+ end
12
+
13
+ case obj
14
+ when String
15
+ obj.empty?
16
+ when Array, Hash
17
+ obj.size.zero?
18
+ else
19
+ false
20
+ end
21
+ end
22
+
23
+ def self.pick_non_empty(str1, str2)
24
+ if !is_empty?(str1)
25
+ str1
26
+ elsif !is_empty?(str2)
27
+ str2
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module ClangTools
3
- VERSION = '0.1.1'.freeze
3
+ VERSION = '0.1.2'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-clang_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - squirrel-explorer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-11 00:00:00.000000000 Z
11
+ date: 2020-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -66,6 +66,34 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec_junit_formatter
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: rubocop
71
99
  requirement: !ruby/object:Gem::Requirement
@@ -114,14 +142,14 @@ dependencies:
114
142
  requirements:
115
143
  - - ">="
116
144
  - !ruby/object:Gem::Version
117
- version: 2.149.1
145
+ version: 2.138.0
118
146
  type: :development
119
147
  prerelease: false
120
148
  version_requirements: !ruby/object:Gem::Requirement
121
149
  requirements:
122
150
  - - ">="
123
151
  - !ruby/object:Gem::Version
124
- version: 2.149.1
152
+ version: 2.138.0
125
153
  description:
126
154
  email: xvider.zx@gmail.com
127
155
  executables: []
@@ -132,7 +160,7 @@ files:
132
160
  - README.md
133
161
  - lib/fastlane/plugin/clang_tools.rb
134
162
  - lib/fastlane/plugin/clang_tools/actions/clang_analyzer_action.rb
135
- - lib/fastlane/plugin/clang_tools/helper/clang_analyzer_helper.rb
163
+ - lib/fastlane/plugin/clang_tools/helper/clang_tools_helper.rb
136
164
  - lib/fastlane/plugin/clang_tools/version.rb
137
165
  homepage: https://github.com/squirrel-explorer/fastlane-plugin-clang_tools
138
166
  licenses:
@@ -1,16 +0,0 @@
1
- require 'fastlane_core/ui/ui'
2
-
3
- module Fastlane
4
- UI = FastlaneCore::UI unless Fastlane.const_defined?('UI')
5
-
6
- module Helper
7
- class ClangToolsHelper
8
- # class methods that you define here become available in your action
9
- # as `Helper::ClangToolsHelper.your_method`
10
- #
11
- def self.show_message
12
- UI.message('Hello from the clang_tools plugin helper!')
13
- end
14
- end
15
- end
16
- end