From 0f7eaaba7956154c0a6c7f0b2b41cbf72b959fda Mon Sep 17 00:00:00 2001 From: Krzysztof Naglik Date: Wed, 12 Oct 2022 15:21:17 +0200 Subject: [PATCH 1/4] Add qac compile commands script --- BUILD.bazel | 4 ++++ qac_compile_commands.sh | 4 ++++ 2 files changed, 8 insertions(+) create mode 100755 qac_compile_commands.sh diff --git a/BUILD.bazel b/BUILD.bazel index e69de29b..29c82a38 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -0,0 +1,4 @@ +sh_binary( + name = "qac_compile_commands", + srcs = ["qac_compile_commands.sh"], +) diff --git a/qac_compile_commands.sh b/qac_compile_commands.sh new file mode 100755 index 00000000..a1630ebe --- /dev/null +++ b/qac_compile_commands.sh @@ -0,0 +1,4 @@ +#! /bin/bash +# This one-line script turns the -isystem flag into the -I flag. This is needed for Helix QAC to work properly. + +sed -i 's/-isystem/-I/' $BUILD_WORKSPACE_DIRECTORY/compile_commands.json From ccce4e50b346a97aa5ffb0f8bad941791d498de0 Mon Sep 17 00:00:00 2001 From: Krzysztof Naglik Date: Fri, 14 Oct 2022 10:19:54 +0200 Subject: [PATCH 2/4] Use refresh_compile_commands from the script --- BUILD.bazel | 2 ++ qac_compile_commands.sh | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/BUILD.bazel b/BUILD.bazel index 29c82a38..85bd5b43 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,4 +1,6 @@ sh_binary( name = "qac_compile_commands", srcs = ["qac_compile_commands.sh"], + args = ["$(location //:refresh_compile_commands)"], + data = ["//:refresh_compile_commands"], ) diff --git a/qac_compile_commands.sh b/qac_compile_commands.sh index a1630ebe..b1aec9f4 100755 --- a/qac_compile_commands.sh +++ b/qac_compile_commands.sh @@ -1,4 +1,9 @@ #! /bin/bash -# This one-line script turns the -isystem flag into the -I flag. This is needed for Helix QAC to work properly. +# This script turns the -isystem flag into the -I flag. +# This is needed for Helix QAC to work properly. +# Usage: qac_compile_commands +REFRESH_COMPILE_COMMANDS=$(realpath $1) + +$REFRESH_COMPILE_COMMANDS sed -i 's/-isystem/-I/' $BUILD_WORKSPACE_DIRECTORY/compile_commands.json From b07a76b58b9119bee6ac96e8a04b926e45115f2f Mon Sep 17 00:00:00 2001 From: Isaac Torres Date: Tue, 18 Oct 2022 01:52:20 -0600 Subject: [PATCH 3/4] Wrap sh_binary in macro (#8) * Wrap sh_binary in macro * Add kwargs parameter * Run buildifier --- BUILD.bazel | 7 +------ qac_compile_commands.bzl | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 qac_compile_commands.bzl diff --git a/BUILD.bazel b/BUILD.bazel index 85bd5b43..f3982a2b 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,6 +1 @@ -sh_binary( - name = "qac_compile_commands", - srcs = ["qac_compile_commands.sh"], - args = ["$(location //:refresh_compile_commands)"], - data = ["//:refresh_compile_commands"], -) +exports_files(["qac_compile_commands.sh"]) diff --git a/qac_compile_commands.bzl b/qac_compile_commands.bzl new file mode 100644 index 00000000..3c2b8977 --- /dev/null +++ b/qac_compile_commands.bzl @@ -0,0 +1,19 @@ +def qac_compile_commands(name, tool, **kwargs): + """Replaces -isystem with -I in a compile_commands.json file. + + This is necessary to get Helix QAC to work correctly. + + Args: + name: A unique label for this rule. + tool: A label refrencing a @hedron_compile_commands:refresh_compile_commands target. + + """ + arg = "$(location {})".format(tool) + native.sh_binary( + name = name, + # FIXME: Assumes //bazel is a valid label in the consuming workspace. + srcs = ["//bazel:qac_compile_commands.sh"], + args = [arg], + data = [tool], + **kwargs + ) From 83560b2cf5f3b5e7a481841e7a8b1055c7e85ecc Mon Sep 17 00:00:00 2001 From: Krzysztof Naglik Date: Tue, 18 Oct 2022 21:07:59 +0200 Subject: [PATCH 4/4] Remove realpath --- qac_compile_commands.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qac_compile_commands.sh b/qac_compile_commands.sh index b1aec9f4..fc54110d 100755 --- a/qac_compile_commands.sh +++ b/qac_compile_commands.sh @@ -3,7 +3,7 @@ # This is needed for Helix QAC to work properly. # Usage: qac_compile_commands -REFRESH_COMPILE_COMMANDS=$(realpath $1) +REFRESH_COMPILE_COMMANDS=$1 $REFRESH_COMPILE_COMMANDS sed -i 's/-isystem/-I/' $BUILD_WORKSPACE_DIRECTORY/compile_commands.json