Accept depset inputs in lipo.create (#683)
diff --git a/lib/lipo.bzl b/lib/lipo.bzl index 56a4b29..1c1fee8 100644 --- a/lib/lipo.bzl +++ b/lib/lipo.bzl
@@ -47,6 +47,8 @@ xcode_config: The `apple_common.XcodeVersionConfig` provider used to configure the action environment. """ + if type(inputs) == "depset": + inputs = inputs.to_list() if not inputs: fail("lipo.create requires at least one input file.")
diff --git a/test/BUILD b/test/BUILD index 1d3a558..7439a6d 100644 --- a/test/BUILD +++ b/test/BUILD
@@ -13,6 +13,7 @@ load(":compiling_tests.bzl", "compiling_test_suite") load(":coverage_tests.bzl", "coverage_test_suite") load(":linking_tests.bzl", "linking_test_suite") +load(":lipo_test.bzl", "create_from_depset_test") load(":sanitizer_tests.bzl", "sanitizer_test_suite") load(":starlark_apple_binary.bzl", "starlark_apple_binary") load(":toolchains_test.bzl", "toolchain_config_test_suite") @@ -45,6 +46,8 @@ xcode_support_test(name = "xcode_support_test") +create_from_depset_test(name = "lipo_create_from_depset_test") + xcode_version_at_least_test(name = "xcode_version_at_least_test") xcode_version_test(name = "xcode_version_test") @@ -82,6 +85,7 @@ srcs = glob(["*.bzl"]), deps = [ "//lib:apple_support", + "//lib:lipo", "//lib:xcode_support", "//rules:apple_genrule", "//xcode:available_xcodes",
diff --git a/test/lipo_test.bzl b/test/lipo_test.bzl new file mode 100644 index 0000000..78cfef5 --- /dev/null +++ b/test/lipo_test.bzl
@@ -0,0 +1,46 @@ +# Copyright 2026 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""Tests for the lipo command construction helpers.""" + +load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest") +load("//lib:apple_support.bzl", "apple_support") +load("//lib:lipo.bzl", "lipo") + +def _create_from_depset_test_impl(ctx): + env = unittest.begin(ctx) + inputs = [ctx.actions.declare_file("first binary"), ctx.actions.declare_file("second binary")] + output = ctx.actions.declare_file("universal binary") + for file in inputs + [output]: + ctx.actions.write(file, "") + calls = [] + actions = struct(run_shell = lambda **kwargs: calls.append(kwargs)) + for files in [inputs, depset(inputs)]: + lipo.create( + actions = actions, + inputs = files, + output = output, + apple_platform_info = struct(platform = apple_common.platform.macos), + xcode_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig], + ) + asserts.equals(env, 2, len(calls)) + asserts.equals(env, calls[0]["command"], calls[1]["command"]) + asserts.equals(env, inputs, calls[1]["inputs"]) + for file in inputs + [output]: + asserts.true(env, "'" + file.path + "'" in calls[1]["command"]) + return unittest.end(env) + +create_from_depset_test = unittest.make( + _create_from_depset_test_impl, + attrs = apple_support.action_required_attrs(), +)