From 401324bf6cec4ef6f912b146a98387a38bff29db Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 1 Dec 2025 13:32:53 +0100 Subject: [PATCH 1/5] Add YAML config file support --- src/codechecker_config.bzl | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/codechecker_config.bzl b/src/codechecker_config.bzl index 3fdd324a..b115dde3 100644 --- a/src/codechecker_config.bzl +++ b/src/codechecker_config.bzl @@ -17,7 +17,20 @@ def get_config_file(ctx): Returns (config_file, environment_variables) config_file is a file object that is readable during Codechecker execution """ + + # Decide whether to use json or yaml for configuration config_file_name = ctx.attr.name + "/config.json" + if ctx.attr.config: + if type(ctx.attr.config) == "list": + config_info = ctx.attr.config[0][CodeCheckerConfigInfo] + else: + config_info = ctx.attr.config[CodeCheckerConfigInfo] + if config_info.config_file: + # Create a copy of CodeChecker configuration file + # provided via codechecker_config(config_file) + config_file = config_info.config_file.files.to_list()[0] + config_file_name = ctx.attr.name + \ + "/config." + config_file.extension ctx_config_file = ctx.actions.declare_file(config_file_name) # Create CodeChecker JSON config file and env vars From fa70fafd9434f4e3f467be6c370f531d7b08554e Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 1 Dec 2025 14:51:31 +0100 Subject: [PATCH 2/5] Remove duplicate code --- src/codechecker_config.bzl | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/codechecker_config.bzl b/src/codechecker_config.bzl index b115dde3..4e810187 100644 --- a/src/codechecker_config.bzl +++ b/src/codechecker_config.bzl @@ -35,14 +35,9 @@ def get_config_file(ctx): # Create CodeChecker JSON config file and env vars if ctx.attr.config: - if type(ctx.attr.config) == "list": - config_info = ctx.attr.config[0][CodeCheckerConfigInfo] - else: - config_info = ctx.attr.config[CodeCheckerConfigInfo] if config_info.config_file: # Create a copy of CodeChecker configuration file # provided via codechecker_config(config_file) - config_file = config_info.config_file.files.to_list()[0] ctx.actions.run( inputs = [config_file], outputs = [ctx_config_file], From f54692c4d26b40ad54e4790e00693afedf5fbb79 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Tue, 2 Dec 2025 12:25:42 +0100 Subject: [PATCH 3/5] Activate relevant tests --- test/unit/config/test_config.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/test/unit/config/test_config.py b/test/unit/config/test_config.py index 133db19b..145bcf59 100644 --- a/test/unit/config/test_config.py +++ b/test/unit/config/test_config.py @@ -57,8 +57,7 @@ def test_codechecker_yaml(self): "codechecker_yaml", "config.yaml" ) - self.assertFalse(os.path.exists(copied_config)) # TODO: Set to True - # Before the patch config.yaml won't be generated + self.assertTrue(os.path.exists(copied_config)) def test_codechecker_test_json(self): """Test: bazel test //test/unit/config:codechecker_test_json""" @@ -82,15 +81,13 @@ def test_codechecker_test_yaml(self): "bazel test //test/unit/config:codechecker_test_yaml" ) # Should not find the division by zero bug - self.assertEqual(ret, 3) # TODO: Set to 0, - # based on the config file won't find the division by zero bug + self.assertEqual(ret, 0) copied_config = os.path.join( self.BAZEL_BIN_DIR, # type: ignore "codechecker_test_yaml", "config.yaml" ) - self.assertFalse(os.path.exists(copied_config)) # TODO: Set to True - # Before the patch config.yaml won't be generated + self.assertTrue(os.path.exists(copied_config)) def test_per_file_test_json(self): """Test: bazel test //test/unit/config:per_file_test_json""" From e349e71d45e403a52c4964aa05caaa548a597b46 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Tue, 2 Dec 2025 12:46:07 +0100 Subject: [PATCH 4/5] Write function for getting config file name --- src/codechecker_config.bzl | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/codechecker_config.bzl b/src/codechecker_config.bzl index 4e810187..4d3600d1 100644 --- a/src/codechecker_config.bzl +++ b/src/codechecker_config.bzl @@ -12,13 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -def get_config_file(ctx): +def _get_config_file_name(ctx): """ - Returns (config_file, environment_variables) - config_file is a file object that is readable during Codechecker execution + Returns the name of the config file to be used, with correct extension + If no config file is given, we write the configuration options into a + config.json file. """ - - # Decide whether to use json or yaml for configuration config_file_name = ctx.attr.name + "/config.json" if ctx.attr.config: if type(ctx.attr.config) == "list": @@ -31,13 +30,29 @@ def get_config_file(ctx): config_file = config_info.config_file.files.to_list()[0] config_file_name = ctx.attr.name + \ "/config." + config_file.extension + return config_file_name + + +def get_config_file(ctx): + """ + Returns (config_file, environment_variables) + config_file is a file object that is readable during Codechecker execution + """ + + # Decide whether to use json or yaml for configuration + config_file_name = _get_config_file_name(ctx) ctx_config_file = ctx.actions.declare_file(config_file_name) # Create CodeChecker JSON config file and env vars if ctx.attr.config: + if type(ctx.attr.config) == "list": + config_info = ctx.attr.config[0][CodeCheckerConfigInfo] + else: + config_info = ctx.attr.config[CodeCheckerConfigInfo] if config_info.config_file: # Create a copy of CodeChecker configuration file # provided via codechecker_config(config_file) + config_file = config_info.config_file.files.to_list()[0] ctx.actions.run( inputs = [config_file], outputs = [ctx_config_file], From 3b86bcfaf20d5ef30ca33abd46b4ad088c5e4a20 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Tue, 2 Dec 2025 14:11:25 +0100 Subject: [PATCH 5/5] Fix Nits --- src/codechecker_config.bzl | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/codechecker_config.bzl b/src/codechecker_config.bzl index 4d3600d1..7a0939c6 100644 --- a/src/codechecker_config.bzl +++ b/src/codechecker_config.bzl @@ -18,28 +18,26 @@ def _get_config_file_name(ctx): If no config file is given, we write the configuration options into a config.json file. """ - config_file_name = ctx.attr.name + "/config.json" if ctx.attr.config: if type(ctx.attr.config) == "list": config_info = ctx.attr.config[0][CodeCheckerConfigInfo] else: config_info = ctx.attr.config[CodeCheckerConfigInfo] if config_info.config_file: - # Create a copy of CodeChecker configuration file - # provided via codechecker_config(config_file) config_file = config_info.config_file.files.to_list()[0] config_file_name = ctx.attr.name + \ "/config." + config_file.extension + return config_file_name + config_file_name = ctx.attr.name + "/config.json" return config_file_name - def get_config_file(ctx): """ Returns (config_file, environment_variables) config_file is a file object that is readable during Codechecker execution """ - # Decide whether to use json or yaml for configuration + # Declare config file to use during analysis config_file_name = _get_config_file_name(ctx) ctx_config_file = ctx.actions.declare_file(config_file_name)