4 # Copyright (c) 2018 Vojtech Horky
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
11 # - Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # - Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in the
15 # documentation and/or other materials provided with the distribution.
16 # - The name of the author may not be used to endorse or promote products
17 # derived from this software without specific prior written permission.
19 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 from hbuild
.scheduler
import Task
34 class SycekBuildTask(Task
):
36 Task
.__init
__(self
, 'tool-build', tool
='sycek')
39 my_dir
= self
.ctl
.make_temp_dir('build/sycek')
42 res
= self
.ctl
.run_command([
47 'https://github.com/jxsvoboda/sycek',
54 res
= self
.ctl
.run_command([
61 'sycek_bin': my_dir
+ '/ccheck',
66 class SycekCheckTask(Task
):
68 Task
.__init
__(self
, 'sycek-style-check')
70 def check_one_file(self
, sycek
, root_dir
, filename
):
71 res
= self
.ctl
.run_command([ sycek
, filename
], cwd
=root_dir
, needs_output
=True)
73 self
.ctl
.append_line_to_log_file("%s: unexpected error, see above." % filename
)
75 issues_count
= len(res
['output'])
77 self
.ctl
.append_line_to_log_file("%s: no error." % filename
)
80 self
.ctl
.append_line_to_log_file("%s: there were issues, see above." % filename
)
81 return ( True, issues_count
)
84 root_dir
= self
.ctl
.get_dependency_data('dir')
85 sycek_bin
= self
.ctl
.get_dependency_data('sycek_bin')
89 top_dirs
= [ 'abi', 'kernel', 'boot', 'uspace' ]
98 for top_dir
in top_dirs
:
99 for path_prefix
, dirs_ignored
, filenames
in os
.walk(os
.path
.join(root_dir
, top_dir
)):
100 path_prefix
= os
.path
.relpath(path_prefix
, root_dir
)
101 for filename
in filenames
:
102 is_c_file
= filename
.endswith('.h') or filename
.endswith('.c')
106 res
= self
.check_one_file(sycek_bin
, root_dir
, os
.path
.join(path_prefix
, filename
))
107 all_okay
= all_okay
and res
[0]
109 files_total
= files_total
+ 1
112 files_okay
= files_okay
+ 1
114 files_failures
= files_failures
+ 1
115 issues_total
= issues_total
+ res
[1]
117 files_errors
= files_errors
+ 1
119 self
.ctl
.append_line_to_log_file("")
120 self
.ctl
.append_line_to_log_file("Sycek C style checker summary")
121 self
.ctl
.append_line_to_log_file("Files scanned: %d" % files_total
)
122 self
.ctl
.append_line_to_log_file("Files clean: %d" % files_okay
)
123 self
.ctl
.append_line_to_log_file("Files with issues: %d" % files_failures
)
124 self
.ctl
.append_line_to_log_file("Files with errors: %d" % files_errors
)
125 self
.ctl
.append_line_to_log_file("Total issues found: %d" % issues_total
)