diff --git a/swiftpkg/internal/bzl_selects.bzl b/swiftpkg/internal/bzl_selects.bzl index dad167f33..b0dcddb90 100644 --- a/swiftpkg/internal/bzl_selects.bzl +++ b/swiftpkg/internal/bzl_selects.bzl @@ -201,6 +201,34 @@ 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, @@ -208,6 +236,7 @@ bzl_selects = struct( 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: diff --git a/swiftpkg/internal/swiftpkg_build_files.bzl b/swiftpkg/internal/swiftpkg_build_files.bzl index 3696caf63..0c03c2bd3 100644 --- a/swiftpkg/internal/swiftpkg_build_files.bzl +++ b/swiftpkg/internal/swiftpkg_build_files.bzl @@ -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,