diff --git a/src/codechecker_config.bzl b/src/codechecker_config.bzl index 3fdd324a..7a0939c6 100644 --- a/src/codechecker_config.bzl +++ b/src/codechecker_config.bzl @@ -12,12 +12,33 @@ # See the License for the specific language governing permissions and # limitations under the License. +def _get_config_file_name(ctx): + """ + 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. + """ + 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: + 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 """ - config_file_name = ctx.attr.name + "/config.json" + + # 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) # Create CodeChecker JSON config file and env vars 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"""