@@ -2,36 +2,65 @@ load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
22load ("//cc_files:get_cc_files.bzl" , "FilesInfo" , "get_cc_target_files" )
33
44def _gen_sonar_cfg_impl (ctx ):
5- all_files_bash = ""
6- all_files = []
5+ files_bash = ""
6+ files = []
77
88 for target in ctx .attr .targets :
9- for file in target [FilesInfo ].files + ctx .files .test_srcs :
10- if file .path not in all_files :
11- all_files_bash += file .path
12- all_files_bash += " "
13- all_files .append (file .path )
9+ for file in target [FilesInfo ].files :
10+ if file .path not in files :
11+ files_bash += file .path
12+ files_bash += " "
13+ files .append (file .path )
14+
15+ test_files_bash = ""
16+ test_files = []
17+
18+ for target in ctx .attr .targets :
19+ for file in target [FilesInfo ].test_files :
20+ if file .path not in test_files :
21+ test_files_bash += file .path
22+ test_files_bash += " "
23+ test_files .append (file .path )
24+
25+ for file in ctx .files .test_srcs :
26+ if file .path not in test_files :
27+ test_files_bash += file .path
28+ test_files_bash += " "
29+ test_files .append (file .path )
1430
1531 out = ctx .actions .declare_file ("sonar-project.properties" )
1632 ctx .actions .run_shell (
1733 outputs = [out ],
1834 command = """
35+ add_files () {{
36+ files=$1
37+ first=1
38+ for file in $files; do
39+ if [[ $first -eq 1 ]]
40+ then
41+ first=0
42+ else
43+ echo ',\\ ' >> {out_file}
44+ fi
45+ echo -n " {root_dir}/$file" >> {out_file}
46+ done
47+ echo '' >> {out_file}
48+ }}
49+
1950 echo 'sonar.sourceEncoding=UTF-8' >> {out_file}
20- echo 'sonar.sources=\\ ' >> {out_file}
21- first=1
22- for file in {all_files}; do
23- if [[ $first -eq 1 ]]
24- then
25- first=0
26- else
27- echo ',\\ ' >> {out_file}
28- fi
29- echo -n " {root_dir}/$file" >> {out_file}
30- done
31- echo '' >> {out_file}
51+
52+ echo 'sonar.inclusions=\\ ' >> {out_file}
53+ add_files "{inclusions}"
54+
55+ echo 'sonar.coverage.exclusions=\\ ' >> {out_file}
56+ add_files "{exclusions}"
57+
58+ echo 'sonar.cpd.exclusions=\\ ' >> {out_file}
59+ add_files "{exclusions}"
3260 """ .format (
3361 out_file = out .path ,
34- all_files = all_files_bash ,
62+ inclusions = files_bash + " " + test_files_bash ,
63+ exclusions = test_files_bash ,
3564 root_dir = ctx .attr .root_dir [BuildSettingInfo ].value ,
3665 ),
3766 )
0 commit comments