Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add --gcc-analyzer-bin option to gcc plug-in #41

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion py/common/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def translate_one(i):
return cmd_out.lstrip()


def write_toolver(results, tool_key, ver):
kdudka marked this conversation as resolved.
Show resolved Hide resolved
results.ini_writer.append("analyzer-version-%s" % tool_key, ver)


def write_toolver_from_rpmlist(results, mock, tool, tool_key):
cmd = "grep '^%s-[0-9]' %s/rpm-list-mock.txt" % (tool, results.dbgdir)
(rc, nvr) = results.get_cmd_output(cmd)
Expand All @@ -56,7 +60,7 @@ def write_toolver_from_rpmlist(results, mock, tool, tool_key):
return rc

ver = re.sub("-[0-9].*$", "", re.sub("^%s-" % tool, "", nvr.strip()))
results.ini_writer.append("analyzer-version-%s" % tool_key, ver)
write_toolver(results, tool_key, ver)
return 0


Expand Down
23 changes: 20 additions & 3 deletions py/plugins/gcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# along with csmock. If not, see <http://www.gnu.org/licenses/>.

# standard imports
import re
kdudka marked this conversation as resolved.
Show resolved Hide resolved
import subprocess

# local imports
Expand Down Expand Up @@ -91,6 +92,11 @@ def init_parser(self, parser):
"--gcc-sanitize-undefined", action="store_true",
help="enable %%check and compile with -fsanitize=undefined")

parser.add_argument(
"--gcc-analyzer-bin", action="store",
help="use custom build of gcc to perform scan"
)

kdudka marked this conversation as resolved.
Show resolved Hide resolved
add_custom_flag_opts(parser)

def handle_args(self, parser, args, props):
Expand Down Expand Up @@ -162,13 +168,17 @@ def handle_args(self, parser, args, props):

if self.csgcca_path is not None:
def csgcca_hook(results, mock):
analyzer_bin = args.gcc_analyzer_bin if args.gcc_analyzer_bin else "gcc"
cmd = "echo 'int main() {}'"
cmd += " | gcc -xc - -c -o /dev/null"
cmd += " | %s -xc - -c -o /dev/null" % analyzer_bin
cmd += " -fanalyzer -fdiagnostics-path-format=separate-events"
if 0 != mock.exec_mockbuild_cmd(cmd):
results.error("`gcc -fanalyzer` does not seem to work, disabling the tool", ec=0)
results.error("`%s -fanalyzer` does not seem to work, "
"disabling the tool" % analyzer_bin, ec=0)
return 0

props.env["CSGCCA_ANALYZER_BIN"] = analyzer_bin
kdudka marked this conversation as resolved.
Show resolved Hide resolved

# XXX: changing props this way is extremely fragile
# insert csgcca right before cswrap to avoid chaining
# csclng/cscppc while invoking `gcc -fanalyzer`
Expand All @@ -185,7 +195,14 @@ def csgcca_hook(results, mock):
props.env["CSGCCA_ADD_OPTS"] = csmock.common.cflags.serialize_flags(args.gcc_analyze_add_flag)

# record that `gcc -fanalyzer` was used for this scan
csmock.common.util.write_toolver_from_rpmlist(results, mock, "gcc", "gcc-analyzer")
cmd = mock.get_mock_cmd(["--chroot", "%s --version" % analyzer_bin])
(rc, ver) = results.get_cmd_output(cmd, shell=False)
if rc != 0:
return rc
ver = ver.partition('\n')[0].strip()
ver = ver.split(' ')[2]
csmock.common.util.write_toolver(results, "gcc-analyzer", ver)

return 0

props.post_depinst_hooks += [csgcca_hook]