Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
23 changes: 22 additions & 1 deletion src/codechecker_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 3 additions & 6 deletions test/unit/config/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand All @@ -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"""
Expand Down