objective-ci 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. data/.gitignore +17 -0
  2. data/BSD-LICENSE.txt +31 -0
  3. data/GPL-LICENSE.txt +16 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +92 -0
  7. data/Rakefile +24 -0
  8. data/bin/ada_count +4 -0
  9. data/bin/asm_count +4 -0
  10. data/bin/awk_count +4 -0
  11. data/bin/break_filelist +4 -0
  12. data/bin/c_count +4 -0
  13. data/bin/cobol_count +4 -0
  14. data/bin/compute_all +4 -0
  15. data/bin/compute_sloc_lang +4 -0
  16. data/bin/count_extensions +4 -0
  17. data/bin/count_unknown_ext +4 -0
  18. data/bin/csh_count +4 -0
  19. data/bin/exp_count +4 -0
  20. data/bin/f90_count +4 -0
  21. data/bin/fortran_count +4 -0
  22. data/bin/generic_count +4 -0
  23. data/bin/get_sloc +4 -0
  24. data/bin/get_sloc_details +4 -0
  25. data/bin/haskell_count +4 -0
  26. data/bin/java_count +4 -0
  27. data/bin/jsp_count +4 -0
  28. data/bin/lex_count +4 -0
  29. data/bin/lexcount1 +4 -0
  30. data/bin/lisp_count +4 -0
  31. data/bin/make_filelists +4 -0
  32. data/bin/makefile_count +4 -0
  33. data/bin/ml_count +4 -0
  34. data/bin/modula3_count +4 -0
  35. data/bin/objc_count +4 -0
  36. data/bin/oclint-0.8 +4 -0
  37. data/bin/oclint-json-compilation-database +4 -0
  38. data/bin/oclint-xcodebuild +4 -0
  39. data/bin/pascal_count +4 -0
  40. data/bin/perl_count +4 -0
  41. data/bin/php_count +4 -0
  42. data/bin/pmd-cpd-objc +7 -0
  43. data/bin/print_sum +4 -0
  44. data/bin/python_count +4 -0
  45. data/bin/ruby_count +4 -0
  46. data/bin/sed_count +4 -0
  47. data/bin/sh_count +4 -0
  48. data/bin/show_filecount +4 -0
  49. data/bin/sloccount +4 -0
  50. data/bin/sql_count +4 -0
  51. data/bin/tcl_count +4 -0
  52. data/docs/jenkins-setup-violations.png +0 -0
  53. data/docs/jenkins-setup.jpg +0 -0
  54. data/externals/oclint/oclint-0.8 +0 -0
  55. data/externals/oclint/oclint-json-compilation-database +86 -0
  56. data/externals/oclint/oclint-xcodebuild +216 -0
  57. data/externals/pmd-cpd/ObjCLanguage-0.0.7-SNAPSHOT.jar +0 -0
  58. data/externals/pmd-cpd/pmd-4.2.5.jar +0 -0
  59. data/externals/sloccount/ada_count +27 -0
  60. data/externals/sloccount/asm_count +166 -0
  61. data/externals/sloccount/awk_count +27 -0
  62. data/externals/sloccount/break_filelist +1308 -0
  63. data/externals/sloccount/c_count +0 -0
  64. data/externals/sloccount/cobol_count +82 -0
  65. data/externals/sloccount/compute_all +87 -0
  66. data/externals/sloccount/compute_sloc_lang +66 -0
  67. data/externals/sloccount/count_extensions +56 -0
  68. data/externals/sloccount/count_unknown_ext +32 -0
  69. data/externals/sloccount/csh_count +27 -0
  70. data/externals/sloccount/exp_count +27 -0
  71. data/externals/sloccount/f90_count +81 -0
  72. data/externals/sloccount/fortran_count +83 -0
  73. data/externals/sloccount/generic_count +77 -0
  74. data/externals/sloccount/get_sloc +544 -0
  75. data/externals/sloccount/get_sloc_details +103 -0
  76. data/externals/sloccount/haskell_count +122 -0
  77. data/externals/sloccount/java_count +0 -0
  78. data/externals/sloccount/jsp_count +0 -0
  79. data/externals/sloccount/lex_count +70 -0
  80. data/externals/sloccount/lexcount1 +0 -0
  81. data/externals/sloccount/lisp_count +27 -0
  82. data/externals/sloccount/make_filelists +193 -0
  83. data/externals/sloccount/makefile_count +27 -0
  84. data/externals/sloccount/ml_count +0 -0
  85. data/externals/sloccount/modula3_count +65 -0
  86. data/externals/sloccount/objc_count +89 -0
  87. data/externals/sloccount/pascal_count +0 -0
  88. data/externals/sloccount/perl_count +147 -0
  89. data/externals/sloccount/php_count +0 -0
  90. data/externals/sloccount/print_sum +40 -0
  91. data/externals/sloccount/python_count +120 -0
  92. data/externals/sloccount/ruby_count +27 -0
  93. data/externals/sloccount/sed_count +27 -0
  94. data/externals/sloccount/sh_count +27 -0
  95. data/externals/sloccount/show_filecount +58 -0
  96. data/externals/sloccount/sloccount +258 -0
  97. data/externals/sloccount/sql_count +76 -0
  98. data/externals/sloccount/tcl_count +27 -0
  99. data/lib/objective-ci.rb +3 -0
  100. data/lib/objective_ci/ci_tasks.rb +142 -0
  101. data/lib/objective_ci/version.rb +3 -0
  102. data/objective-ci.gemspec +26 -0
  103. metadata +255 -0
@@ -0,0 +1,216 @@
1
+ #!/usr/bin/env python
2
+
3
+ import os
4
+ import sys
5
+ import json
6
+ import argparse
7
+ import re
8
+ import shlex
9
+ import StringIO
10
+ import glob
11
+ import itertools
12
+
13
+
14
+ SUPPORTED_COMPILERS = [
15
+ "clang",
16
+ "clang\+\+",
17
+ "llvm-cpp-4.2",
18
+ "llvm-g\+\+",
19
+ "llvm-g\+\+-4.2",
20
+ "llvm-gcc",
21
+ "llvm-gcc-4.2",
22
+ "arm-apple-darwin10-llvm-g\+\+-4.2",
23
+ "arm-apple-darwin10-llvm-gcc-4.2",
24
+ "i686-apple-darwin10-llvm-g\+\+-4.2",
25
+ "i686-apple-darwin10-llvm-gcc-4.2",
26
+ "gcc",
27
+ "g\+\+",
28
+ "c\+\+",
29
+ "cc"
30
+ ]
31
+
32
+ DEFAULT_INPUT_FILE = "xcodebuild.log"
33
+
34
+ JSON_COMPILATION_DATABASE = "compile_commands.json"
35
+
36
+
37
+ _find_unsafe = re.compile('[ "\\\\]').search
38
+
39
+ def clang_quote(s):
40
+ """
41
+ Return a minimally-escaped version of the string *s* that clang-based tools understand.
42
+ (See http://clang.llvm.org/docs/JSONCompilationDatabase.html)
43
+ ex:
44
+ clang_quote('aa') == r'aa'
45
+ clang_quote('a"a') == r'"a\"a"'
46
+ clang_quote('--my-option=a"a') == r'"--my-option=a\"a"'
47
+ """
48
+ if not s:
49
+ return '""'
50
+
51
+ if _find_unsafe(s) is None:
52
+ return s
53
+
54
+ return '"' + s.replace('\\', '\\\\').replace('"', '\\"') + '"'
55
+
56
+
57
+ _find_quoting = re.compile('[\'"\\\\]').search
58
+
59
+ def tokenize_command(c):
60
+ """Compute the list of shell arguments in *c* using shlex.split (note: make an explicit call to StringIO for compatibility with Python 2)."""
61
+ if _find_quoting(c) is None:
62
+ return map(str.strip, c.strip().split(' '))
63
+ else:
64
+ return shlex.split(StringIO.StringIO(c))
65
+
66
+ # global table to map pth files to (source) pch files
67
+ _pch_dictionary = {}
68
+
69
+ def register_source_for_pth_file(clang_command, directory):
70
+ tokens = iter(tokenize_command(clang_command))
71
+ src_file = ""
72
+ pth_file = ""
73
+ try:
74
+ while 1:
75
+ tok = tokens.next()
76
+ if tok == '-c':
77
+ file = tokens.next()
78
+ src_file = file
79
+ elif tok == '-o':
80
+ file = tokens.next()
81
+ if file.endswith('.pch.pth') or file.endswith('.pch.pch'):
82
+ pth_file = file
83
+ except StopIteration:
84
+ if src_file and pth_file:
85
+ _pch_dictionary[pth_file] = src_file
86
+
87
+ def get_source_for_pth_file(file):
88
+ src_file = _pch_dictionary.get(file + '.pth')
89
+ if src_file is not None:
90
+ return src_file
91
+ return _pch_dictionary.get(file + '.pch')
92
+
93
+ def process_clang_command(clang_command, directory):
94
+ tokens = iter(tokenize_command(clang_command))
95
+ command = []
96
+ source_file = None
97
+
98
+ try:
99
+ while 1:
100
+ tok = tokens.next()
101
+ if tok == '-include':
102
+ include_file = tokens.next()
103
+ if not os.path.isfile(include_file):
104
+ src_file = get_source_for_pth_file(include_file)
105
+ if src_file is not None:
106
+ include_file = src_file
107
+ else:
108
+ print "cannot find original pch source file for %s" % include_file
109
+ exit(3)
110
+ command.append(tok)
111
+ command.append(clang_quote(include_file))
112
+
113
+ elif tok == '-c':
114
+ source_file = tokens.next()
115
+ command.append(tok)
116
+ command.append(clang_quote(source_file))
117
+
118
+ else:
119
+ command.append(clang_quote(tok))
120
+
121
+ except StopIteration:
122
+ return {"directory": directory, "command": " ".join(command), "file": os.path.normpath(source_file)}
123
+
124
+
125
+ def read_directory(line):
126
+ tokens = tokenize_command(line)
127
+ if tokens[0] == "cd":
128
+ return tokens[1]
129
+ else:
130
+ return ""
131
+
132
+ def convert(input_file, output_file, is_excluded=None):
133
+ json_input_mode = input_file.endswith('.json')
134
+
135
+ find_compileC = re.compile("CompileC").search
136
+
137
+ find_processPCH = re.compile("ProcessPCH").search
138
+
139
+ find_clang_command = re.compile("(" + "|".join(SUPPORTED_COMPILERS) + ") .* -c .* -o ").search
140
+
141
+ if is_excluded is None:
142
+ is_excluded = (lambda x: False)
143
+
144
+ with open(output_file, "w") as output:
145
+ with open(input_file, "r") as input:
146
+ if json_input_mode:
147
+ lines = itertools.chain(*(json.loads(line).get('command', '').encode("utf8").splitlines(True) for line in input))
148
+ else:
149
+ lines = input
150
+ try:
151
+ output.write("[")
152
+ cr = "\n"
153
+ while 1:
154
+ log_line = lines.next()
155
+ compilation_section_re = find_compileC(log_line)
156
+ if compilation_section_re:
157
+ directory = read_directory(lines.next())
158
+ if is_excluded(directory):
159
+ continue
160
+ while 1:
161
+ log_line = lines.next()
162
+ if not find_clang_command(log_line):
163
+ continue
164
+ output_record = process_clang_command(log_line, directory)
165
+ output.write(cr)
166
+ output.write(json.dumps(output_record, indent=2))
167
+ cr = ",\n"
168
+ break
169
+ continue
170
+ compilation_section_re = find_processPCH(log_line)
171
+ if compilation_section_re:
172
+ directory = read_directory(lines.next())
173
+ if is_excluded(directory):
174
+ continue
175
+ while 1:
176
+ log_line = lines.next()
177
+ if not find_clang_command(log_line):
178
+ continue
179
+ register_source_for_pth_file(log_line, directory)
180
+ break
181
+ continue
182
+ except StopIteration:
183
+ output.write("\n]\n");
184
+
185
+ def main():
186
+ arg_parser = argparse.ArgumentParser(description='Converts xcodebuild logs or xctool-json-reporter logs to compile_commands.json')
187
+ arg_parser.add_argument("-e", "-exclude", dest="exclusion", help="Directory exclusion pattern (regular expression)")
188
+ arg_parser.add_argument("-o", "-output", dest="output_file", help="Output json file (default: ./%s)" % JSON_COMPILATION_DATABASE)
189
+ arg_parser.add_argument(metavar="FILE", nargs='?', dest="input_file", help="Input log file (default: ./%s)" % DEFAULT_INPUT_FILE)
190
+
191
+ args = arg_parser.parse_args()
192
+
193
+ if args.input_file:
194
+ input_file = args.input_file
195
+ else:
196
+ input_file = DEFAULT_INPUT_FILE
197
+
198
+ if args.output_file:
199
+ output_file = args.output_file
200
+ else:
201
+ output_file = JSON_COMPILATION_DATABASE
202
+
203
+ if not os.path.isfile(input_file):
204
+ print "Error: %s not found." % input_file
205
+ exit(1)
206
+
207
+ if args.exclusion:
208
+ is_excluded = re.compile(args.exclusion).match
209
+ else:
210
+ is_excluded = None
211
+
212
+ convert(input_file, output_file, is_excluded)
213
+
214
+
215
+ if __name__ == '__main__':
216
+ main()
Binary file
@@ -0,0 +1,27 @@
1
+ #!/bin/sh
2
+ #
3
+ # This is part of SLOCCount, a toolsuite that counts
4
+ # source lines of code (SLOC).
5
+ # Copyright (C) 2001-2004 David A. Wheeler.
6
+ #
7
+ # This program is free software; you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation; either version 2 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with this program; if not, write to the Free Software
19
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
+ #
21
+ # To contact David A. Wheeler, see his website at:
22
+ # http://www.dwheeler.com.
23
+ #
24
+ #
25
+
26
+ generic_count '--' "$@"
27
+
@@ -0,0 +1,166 @@
1
+ #!/usr/bin/perl -w
2
+ # asm_count - count physical lines of code in Assembly programs.
3
+ # Usage: asm_count [-f file] [list_of_files]
4
+ # file: file with a list of files to count (if "-", read list from stdin)
5
+ # list_of_files: list of files to count
6
+ # -f file or list_of_files can be used, or both
7
+ # This is a trivial/naive program.
8
+
9
+ # For each file, it looks at the contents to heuristically determine
10
+ # if C comments are permitted and what the "comment" character is.
11
+ # If /* and */ are in the file, then C comments are permitted.
12
+ # The punctuation mark that starts the most lines must be the comment
13
+ # character (but ignoring "/" if C comments are allowed, and
14
+ # ignoring '#' if cpp commands appear to be used)
15
+
16
+ # This is part of SLOCCount, a toolsuite that counts
17
+ # source lines of code (SLOC).
18
+ # Copyright (C) 2001-2004 David A. Wheeler.
19
+ #
20
+ # This program is free software; you can redistribute it and/or modify
21
+ # it under the terms of the GNU General Public License as published by
22
+ # the Free Software Foundation; either version 2 of the License, or
23
+ # (at your option) any later version.
24
+ #
25
+ # This program is distributed in the hope that it will be useful,
26
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
27
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28
+ # GNU General Public License for more details.
29
+ #
30
+ # You should have received a copy of the GNU General Public License
31
+ # along with this program; if not, write to the Free Software
32
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33
+ #
34
+ # To contact David A. Wheeler, see his website at:
35
+ # http://www.dwheeler.com.
36
+
37
+
38
+
39
+ $total_sloc = 0;
40
+
41
+ # Do we have "-f" (read list of files from second argument)?
42
+ if (($#ARGV >= 1) && ($ARGV[0] eq "-f")) {
43
+ # Yes, we have -f
44
+ if ($ARGV[1] eq "-") {
45
+ # The list of files is in STDIN
46
+ while (<STDIN>) {
47
+ chomp ($_);
48
+ &count_file ($_);
49
+ }
50
+ } else {
51
+ # The list of files is in the file $ARGV[1]
52
+ open (FILEWITHLIST, $ARGV[1]) || die "Error: Could not open $ARGV[1]\n";
53
+ while (<FILEWITHLIST>) {
54
+ chomp ($_);
55
+ &count_file ($_);
56
+ }
57
+ close FILEWITHLIST;
58
+ }
59
+ shift @ARGV; shift @ARGV;
60
+ }
61
+ # Process all (remaining) arguments as file names
62
+ while ($file = shift @ARGV) {
63
+ &count_file ($file);
64
+ }
65
+
66
+ print "Total:\n";
67
+ print "$total_sloc\n";
68
+
69
+ sub count_file {
70
+ my ($file) = @_;
71
+ # First, use heuristics to determine the comment char and if it uses C comments
72
+ $found_c_start = 0;
73
+ $found_c_end = 0;
74
+ $cpp_suspicious = 0;
75
+ $cpp_likely = 0;
76
+ $cpp_used = 0;
77
+ %count = ();
78
+ if ($file eq "") {
79
+ *CURRENTFILE = *STDIN
80
+ } else {
81
+ open(CURRENTFILE, "<$file");
82
+ }
83
+ while (<CURRENTFILE>) {
84
+ if (m!\/\*!) { $found_c_start++;}
85
+ if (m!\*\/!) { $found_c_end++;}
86
+ if ( (m!^#\s*define\s!) || (m!^#\s*else!)) {$cpp_suspicious++;}
87
+ if ( (m!^#\s*ifdef\s!) || (m!^#\s*endif!) || (m!#\s*include!)) {$cpp_likely++;}
88
+ if (m/^\s*([;!\/#\@\|\*])/) { $count{$1}++; } # Found a likely comment char.
89
+ }
90
+ # Done examing file, let's figure out the parameters.
91
+ if ($found_c_start && $found_c_end) {
92
+ $ccomments = 1;
93
+ $count{'/'} = 0;
94
+ # $count{'*'} = 0; # Do this to ignore '*' if C comments are used.
95
+ } else {
96
+ $ccomments = 0;
97
+ }
98
+ if (($cpp_suspicious > 2) || ($cpp_likely >= 1)) {
99
+ $cpp_used = 1;
100
+ $count{'#'} = 0;
101
+ } else {
102
+ $cpp_used = 0;
103
+ }
104
+ $likeliest = ';';
105
+ $likeliest_count = 0;
106
+ foreach $i (keys(%count)) {
107
+ # print "DEBUG: key=$i count=$count{$i}\n";
108
+ if ($count{$i} > $likeliest_count) {
109
+ $likeliest = $i;
110
+ $likeliest_count = $count{$i};
111
+ }
112
+ }
113
+ # print "DEBUG: likeliest = $likeliest\n";
114
+ $commentchar=$likeliest;
115
+ close(CURRENTFILE);
116
+
117
+ # Now count SLOC.
118
+ $sloc = 0;
119
+ $isincomment = 0;
120
+ open(CURRENTFILE, "<$file");
121
+ while (<CURRENTFILE>) {
122
+ # We handle C comments first, so that if an EOL-comment
123
+ # occurs inside a C comment, it's ignored.
124
+ if ($ccomments) {
125
+ # Handle C /* */ comments; this will get fooled if they're in strings,
126
+ # but that would be rare in assembly.
127
+ while ( (m!\/\*!) || (m!\*\/!)) { # While unprocessed C comment.
128
+ if ($isincomment) {
129
+ s!.*?\*\/.*!!;
130
+ $isincomment = 0;
131
+ } else { # Not in C comment, but have end comment marker.
132
+ if (! m/\/\*/) { # Whups, there's no starting marker!
133
+ print STDERR "Warning: file $file line $. has unmatched comment end\n";
134
+ # Get us back to a plausible state:
135
+ s/.*//; # Destroy everything
136
+ $isincomment = 0;
137
+ } else {
138
+ if (! s!\/\*.*?\*\/!!) { # Try to delete whole comment.
139
+ # We couldn't delete whole comment. Delete what's there.
140
+ s!\/\*.*!!;
141
+ $isincomment = 1;
142
+ }
143
+ }
144
+ }
145
+ }
146
+ } # End of handling C comments.
147
+ # This requires $[ be unchanged.
148
+ $locate_comment = index($_, $commentchar);
149
+ if ($locate_comment >= 0) { # We found a comment character, delete comment
150
+ $_ = substr($_, 0, $locate_comment);
151
+ # print "DEBUG New text: @",$_,"@\n";
152
+ }
153
+ # old: s/${commentchar}.*//; # Delete leading comments.
154
+
155
+ # FOR DEBUG: print "Finally isincomment=$isincomment line=$_\n";
156
+ if ((! $isincomment) && (m/\S/)) {$sloc++;}
157
+ }
158
+
159
+ # End-of-file processing
160
+ print "$sloc (commentchar=$commentchar C-comments=$ccomments) $file\n";
161
+ $total_sloc += $sloc;
162
+ $sloc = 0;
163
+ if ($isincomment) {
164
+ print STDERR "Missing comment close in file $file\n";
165
+ }
166
+ }
@@ -0,0 +1,27 @@
1
+ #!/bin/sh
2
+ #
3
+ # This is part of SLOCCount, a toolsuite that counts
4
+ # source lines of code (SLOC).
5
+ # Copyright (C) 2001-2004 David A. Wheeler.
6
+ #
7
+ # This program is free software; you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation; either version 2 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with this program; if not, write to the Free Software
19
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
+ #
21
+ # To contact David A. Wheeler, see his website at:
22
+ # http://www.dwheeler.com.
23
+ #
24
+ #
25
+
26
+ generic_count '#' $@
27
+