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
Changes from 2 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
33 changes: 29 additions & 4 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
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 DTS build of gcc to perform scan"
)

add_custom_flag_opts(parser)

def handle_args(self, parser, args, props):
Expand Down Expand Up @@ -158,15 +164,32 @@ def handle_args(self, parser, args, props):
# write all compiler flags to the environment
self.flags.write_to_env(props.env)

csmock.common.util.install_default_toolver_hook(props, "gcc")
analyzer_bin = args.gcc_analyzer_bin if args.gcc_analyzer_bin else "gcc"

def get_gcc_version_writer(prefix, analyzer_bin):
def store_gcc_analyzer_version(results, mock):
cmd = mock.get_mock_cmd(["--chroot", "%s --version" % analyzer_bin])
(rc, verstr) = results.get_cmd_output(cmd, shell=False)
if rc != 0:
return rc
verstr = verstr.partition('\n')[0]
ver = re.sub("^gcc \(GCC\) ", "", verstr.strip())
results.ini_writer.append(prefix, ver)
return 0

return store_gcc_analyzer_version

props.post_depinst_hooks += \
[get_gcc_version_writer("analyzer-version-gcc", analyzer_bin)]

if self.csgcca_path is not None:
def csgcca_hook(results, mock):
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

# XXX: changing props this way is extremely fragile
Expand All @@ -185,7 +208,9 @@ 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")
gcc_version_writer = get_gcc_version_writer("gcc-analyzer", analyzer_bin)
gcc_version_writer(results, mock)

return 0

props.post_depinst_hooks += [csgcca_hook]