Skip to content

Commit 654ffc5

Browse files
committed
Add function to merge default and user defined arguments together
1 parent fc02241 commit 654ffc5

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/per_file.bzl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,24 @@ def _collect_all_sources_and_headers(ctx):
314314
sources_and_headers = all_files + headers.to_list()
315315
return sources_and_headers
316316

317+
def _merge_options(default, custom):
318+
"""
319+
Merge command line arguments so that default options can be overridden
320+
"""
321+
final = []
322+
args_set = []
323+
for item in custom:
324+
args_set.append(item.split(" ")[0].split("=")[0])
325+
final.append(item)
326+
for option in default:
327+
if option.split(" ")[0].split("=")[0] not in args_set:
328+
final.append(option)
329+
return final
330+
317331
def _per_file_impl(ctx):
318332
compile_commands_json = _compile_commands_impl(ctx)
319333
sources_and_headers = _collect_all_sources_and_headers(ctx)
320-
options = ctx.attr.default_options + ctx.attr.options
334+
options = _merge_options(ctx.attr.default_options, ctx.attr.options)
321335
all_files = [compile_commands_json]
322336
for target in ctx.attr.targets:
323337
if not CcInfo in target:

0 commit comments

Comments
 (0)