Skip to content

Commit 79bce67

Browse files
committed
Add function to merge default and user defined arguments together
1 parent f496416 commit 79bce67

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/code_checker.bzl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,24 @@ def _collect_all_sources_and_headers(ctx):
297297
sources_and_headers = all_files + headers.to_list()
298298
return sources_and_headers
299299

300+
def _merge_options(default, custom):
301+
"""
302+
Merge command line arguments so that default options can be overridden
303+
"""
304+
final = []
305+
args_set = []
306+
for item in custom:
307+
args_set.append(item.split(" ")[0].split("=")[0])
308+
final.append(item)
309+
for option in default:
310+
if option.split(" ")[0].split("=")[0] not in args_set:
311+
final.append(option)
312+
return final
313+
300314
def _code_checker_impl(ctx):
301315
compile_commands_json = _compile_commands_impl(ctx)
302316
sources_and_headers = _collect_all_sources_and_headers(ctx)
303-
options = ctx.attr.default_options + ctx.attr.options
317+
options = _merge_options(ctx.attr.default_options, ctx.attr.options)
304318
all_files = [compile_commands_json]
305319
for target in ctx.attr.targets:
306320
if not CcInfo in target:

0 commit comments

Comments
 (0)