xcanafail 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +15 -0
  2. data/bin/xcanafail +6 -0
  3. data/lib/xcanafail.rb +138 -0
  4. metadata +49 -0
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MjJjNzFlYzVhODliNGNmMGVkNmUwNTJiMTdhYzNjOGQ4ZGNjMTQ0NA==
5
+ data.tar.gz: !binary |-
6
+ NmE1ZmZhYmM3MTA2YzNkYTVhNDg3OTZlMDIxNDA2MWQ1MzVmZjUwOQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NWZmYTQ2MjZjYjU0Mzg0YTcwOTcxMDk3MzljZjQzNWEyNjUzM2ZlZDIxMzFl
10
+ NmVkOGZjYWNlMzAyYjJiYTZmNzMyYTQwZTU1MDY3YWExMjQyNzc1ZDA4ZDdj
11
+ M2NhYjA4Y2JiZGRiNGI0YmM4MDU2YWYyNjc2Y2E3NmNmYzQzMzM=
12
+ data.tar.gz: !binary |-
13
+ ZjQ0MThjMDUwZWZkNDBkMzhkOWU1MDY5NTg4ZTlkZWI1MWQyMDZiMTZlOWYz
14
+ OWQxY2IwMWI5ODMyYzYxYTg1NDM2NjcwNjM4YTRiNTcxMjMyYzA2MGNkNjUy
15
+ NjMyMmNlZWFmNjQ4MDMxZTMxNjliOTFlNmM4YjM3YjkwNTMwMTY=
data/bin/xcanafail ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require_relative '../lib/xcanafail'
5
+
6
+ XCAnafail.run
data/lib/xcanafail.rb ADDED
@@ -0,0 +1,138 @@
1
+ #!/usr/bin/ruby
2
+ # encoding: UTF-8
3
+
4
+ require 'optparse'
5
+ require 'ostruct'
6
+
7
+ #
8
+ # A class to give this gem some scope. The designed way to use it is through the binary, though all the binary does is call the run method on this class.
9
+ #
10
+ # ==== Examples
11
+ # > set -o pipefail
12
+ # > xctool -workspace MyApp.workspace -scheme MyApp.scheme -reporter plain analyze | xcanafail | <other utilities>
13
+ #
14
+ class XCAnafail
15
+
16
+ # Keep track of which file we are currently looking at
17
+ private
18
+ ANALYZE_FILE_LINE_REGEX = / *~ Analyze (.*)/
19
+
20
+ # Use this to not record warnings that occur during compilation
21
+ private
22
+ COMPILE_FILE_LINE_REGEX = / *~ Compile (.*)/
23
+
24
+ # Detect when a separator has happened
25
+ private
26
+ SEPARATOR_REGEX = /--------------------------------------------------------------------------------/
27
+
28
+ # Check to see if there have been any warnings created
29
+ private
30
+ WARNING_COUNT_LINE_REGEX = /[0-9]* warning.* generated./
31
+
32
+ # An enumeration to store some state about where we are in the parse
33
+ private
34
+ module ParseState
35
+ private
36
+ ROOT = 0
37
+
38
+ private
39
+ INSIDE_BLOCK = 1 # We are inside a greyed out message block
40
+ end
41
+
42
+ #
43
+ # This method will start to read in from either a pipe for stdin, parse the input to detect any analysis warnings and then stream the input back out through stdout
44
+ #
45
+ def self.run
46
+
47
+ # Read in the arguments and verify etc.
48
+ options = OpenStruct.new
49
+ options.output = '/dev/null'
50
+ OptionParser.new do |opts|
51
+ opts.banner = 'Usage: xcanafail.rb [options]'
52
+
53
+ opts.on('-o', '--out FILE', 'An optional output file') do |o|
54
+ options.output = o
55
+ end
56
+
57
+ # No argument, shows at tail. This will print an options summary.
58
+ opts.on_tail('-h', '--help', 'Show this message') do
59
+ puts opts
60
+ exit
61
+ end
62
+ end.parse!
63
+
64
+ # Assume success, but this might change during the parse
65
+ exit_code = 0
66
+
67
+ # open the output file if we have been given one
68
+ File.open(options.output, 'w') do |output|
69
+
70
+ current_file = nil
71
+
72
+ # We start at the root level
73
+ state = ParseState::ROOT
74
+
75
+ # We need to store up the contents of a warning block to deal with it all when we get to the end
76
+ block_contents = nil
77
+
78
+ ARGF.each_line { |line|
79
+ # We should appear transparent to the end user
80
+ puts line
81
+
82
+ # Get each line from the pipe and see where we are
83
+ if ANALYZE_FILE_LINE_REGEX.match(line)
84
+ current_file = line
85
+ next
86
+ end
87
+
88
+ # If we are entering a compile for a file, we just don't care
89
+ if COMPILE_FILE_LINE_REGEX.match(line)
90
+ current_file = nil
91
+ next
92
+ end
93
+
94
+ # If we don't know which file we are in yet, don't process the rest of this line
95
+ next if current_file.nil?
96
+
97
+ # Or if we are going in/out of a separator block?
98
+ if SEPARATOR_REGEX.match(line)
99
+
100
+ if state == ParseState::ROOT
101
+ state = ParseState::INSIDE_BLOCK
102
+ block_contents = []
103
+ else
104
+ # If the last line of the block contains a warning count then we have had a valid warning
105
+ if block_contents.count > 0
106
+ last_line = block_contents.last
107
+ if WARNING_COUNT_LINE_REGEX.match(last_line)
108
+ output.print("Warning -> Error\n")
109
+ output.print(current_file + "\n")
110
+ output.print(block_contents.join("\n"))
111
+ exit_code = 1
112
+ end
113
+ end
114
+
115
+ #puts "Leaving warning block : " + block_contents.to_s
116
+
117
+ block_contents = nil
118
+ state = ParseState::ROOT
119
+ current_file = nil
120
+ end
121
+
122
+ next
123
+ end
124
+
125
+ if state == ParseState::INSIDE_BLOCK
126
+ block_contents << line
127
+ end
128
+
129
+ #puts line
130
+ }
131
+ end
132
+
133
+ exit(exit_code)
134
+
135
+ end
136
+
137
+ end
138
+
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xcanafail
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.12
5
+ platform: ruby
6
+ authors:
7
+ - Sam Dean
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-12 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Pipe in the output of `xctool analyze` and it will fail on warnings.
14
+ This is designed as a temporary workaround for the --fail-on-warnings flag not failing
15
+ on warnings :) When that bug is fixed, this gem should go away immediately.
16
+ email: sam.dean@net-a-porter.com
17
+ executables:
18
+ - xcanafail
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - bin/xcanafail
23
+ - lib/xcanafail.rb
24
+ homepage: http://rubygems.org/gems/xcanafail
25
+ licenses:
26
+ - Apache-2.0
27
+ metadata:
28
+ source: https://github.com/net-a-porter-mobile/xcanafail
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 2.5.0
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: Pipe in the output of `xctool analyze` and it will fail on warnings.
49
+ test_files: []