Class: Fastlane::Actions::ClangAnalyzerAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



68
69
70
# File 'lib/fastlane/plugin/clang_analyzer/actions/clang_analyzer_action.rb', line 68

def self.authors
  ["SiarheiFiedartsou"]
end

.available_optionsObject



72
73
74
75
76
77
78
79
80
81
82
83
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
113
114
115
116
117
118
119
120
121
# File 'lib/fastlane/plugin/clang_analyzer/actions/clang_analyzer_action.rb', line 72

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :analyzer_path,
                            env_name: "CLANG_ANALYZER_ANALYZER_PATH",
                             optional: true,
                            default_value: File.expand_path("~/analyze_tools/bin"),
                            verify_block: proc do |value|
                                            unless File.exist? value
                                              UI.user_error!("Couldn't find clang analyzer tools.") unless Helper.test?
                                            end
                                          end),
    FastlaneCore::ConfigItem.new(key: :workspace,
                            env_name: "CLANG_ANALYZER_WORKSPACE",
                             optional: true,
                             conflicting_options: [:project],
                                type: String),
    FastlaneCore::ConfigItem.new(key: :project,
                            env_name: "CLANG_ANALYZER_PROJECT",
                            optional: true,
                            conflicting_options: [:workspace],
                                type: String),
    FastlaneCore::ConfigItem.new(key: :scheme,
                            env_name: "CLANG_ANALYZER_SCHEME",
                            optional: true),
    FastlaneCore::ConfigItem.new(key: :configuration,
                            env_name: "CLANG_ANALYZER_CONFIGURATION",
                            optional: true),
    FastlaneCore::ConfigItem.new(key: :sdk,
                            env_name: "CLANG_ANALYZER_SDK",
                            optional: true,
                            default_value: "iphonesimulator"),
    FastlaneCore::ConfigItem.new(key: :arch,
                            env_name: "CLANG_ANALYZER_ARCH",
                            optional: true,
                            default_value: "i386"),
    FastlaneCore::ConfigItem.new(key: :clean,
                            env_name: "CLANG_ANALYZER_CLEAN",
                            optional: true,
                            default_value: true),
    FastlaneCore::ConfigItem.new(key: :log_file_path,
                            env_name: "CLANG_ANALYZER_LOG_FILE_PATH",
                            optional: true,
                            default_value: "clang-analyzer.log"),
    FastlaneCore::ConfigItem.new(key: :report_output_path,
                            env_name: "CLANG_ANALYZER_REPORT_OUTPUT_PATH",
                            optional: true,
                            default_value: "analyzer_report")

  ]
end

.descriptionObject



64
65
66
# File 'lib/fastlane/plugin/clang_analyzer/actions/clang_analyzer_action.rb', line 64

def self.description
  "Runs Clang Static Analyzer(http://clang-analyzer.llvm.org/) and generates report"
end

.is_supported?(_platform) ⇒ Boolean

Returns:

  • (Boolean)


123
124
125
126
127
128
129
# File 'lib/fastlane/plugin/clang_analyzer/actions/clang_analyzer_action.rb', line 123

def self.is_supported?(_platform)
  # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
  # See: https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Platforms.md
  #
  # [:ios, :mac, :android].include?(platform)
  true
end

.run(params) ⇒ Object



4
5
6
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/fastlane/plugin/clang_analyzer/actions/clang_analyzer_action.rb', line 4

def self.run(params)
  unless Helper.test?
    FastlaneCore::Project.detect_projects(params)
    project = FastlaneCore::Project.new(params)
    project.select_scheme

    params[:configuration] = project.configurations[0] unless params[:configuration]
  end

  analyzer_params = []

  if params[:workspace]
    analyzer_params << "-workspace #{params[:workspace]}"
  end

  if params[:project]
    analyzer_params << "-project #{params[:project]}"
  end

  analyzer_params += [
    "-scheme", params[:scheme],
    "-configuration", params[:configuration],
    "-sdk", params[:sdk],
    "-arch", params[:arch]
  ]

  analyzer_params_string = analyzer_params.join(" ")

  begin
    resulting_path = params[:report_output_path]
    FileUtils.rm_rf(resulting_path)

    log_file_path = params[:log_file_path]
    clean         = params[:clean] ? "clean" : ""
    command       = File.join(params[:analyzer_path], "scan-build") + " xcodebuild #{analyzer_params_string} #{clean} analyze | tee #{log_file_path} | xcpretty"

    FastlaneCore::CommandExecutor.execute(command: command,
                                        print_all: true,
                                    print_command: true,
                                            error: proc do |output|
                                              ErrorHandler.handle_build_error(output)
                                            end)

    output  = File.read(log_file_path)
    matches = output.match(/scan-view (.*)\'/)
    if matches
      path = output.match(/scan-view (.*)\'/)[1]
      FileUtils.mkdir_p(resulting_path)
      FileUtils.cp_r(path, resulting_path)
      UI.success "Successfully generated analyzer report at path #{File.expand_path(resulting_path)}"
    else
      UI.success "No bugs found by analyzer report"
    end

  rescue => ex
    UI.error ex
    raise "Static Analyzer failed!".red
  end
end