Skip to content

Commit

Permalink
Fix deduplication of -enable-experimental-feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreksh committed Apr 25, 2024
1 parent 5f56d54 commit 20f7a11
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
29 changes: 29 additions & 0 deletions swiftpkg/internal/bzl_selects.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,42 @@ No Starlark expression members were generated for {}\

return scg.new_expr(*expr_members)

def _unwrap_list(values, kind_handlers = {}):
"""Converts the provied values into unstructured types using the information in the \
kind handlers.
Args:
values: A `list` of values that are processed and added to the output.
kind_handlers: A `dict` of king handler `struct` values
(`bzl_selects.new_kind_handler`).
Returns:
A list where `struct` values are unwrapped
"""
result = []
for v in values:
v_type = type(v)
if v_type != "struct":
if v_type == "list":
result.extend(v)
else:
result.append(v)
continue

# We are assuming that the select will always result in a list.
# Hence, we wrap the transformed value in a list.
kind_handler = kind_handlers.get(v.kind, _noop_kind_handler)
result.extend(lists.flatten(kind_handler.transform(v.value)))
return result

bzl_selects = struct(
default_condition = _bazel_select_default_condition,
new = _new,
new_from_build_setting = _new_from_build_setting,
new_from_target_dependency_condition = _new_from_target_dependency_condition,
new_kind_handler = _new_kind_handler,
to_starlark = _to_starlark,
unwrap_list = _unwrap_list,
)

# NEED TO CONVERT:
Expand Down
2 changes: 1 addition & 1 deletion swiftpkg/internal/swiftpkg_build_files.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def _swift_target_build_file(pkg_ctx, target):
if len(defines) > 0:
attrs["defines"] = bzl_selects.to_starlark(defines)
if len(copts) > 0:
attrs["copts"] = bzl_selects.to_starlark(copts)
attrs["copts"] = bzl_selects.unwrap_list(copts)

res_build_file = _handle_target_resources(
pkg_ctx,
Expand Down

0 comments on commit 20f7a11

Please sign in to comment.