Skip to content

Commit d296e13

Browse files
authored
Add test for swift_binary transitive runfiles (#1507)
Add coverage that makes sure that transitive runfiles from swift_libraries are pulled into swift_binary rules --------- Signed-off-by: Maxwell Elliott <[email protected]>
1 parent 60a34df commit d296e13

File tree

7 files changed

+88
-0
lines changed

7 files changed

+88
-0
lines changed

test/BUILD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ load(":output_file_map_tests.bzl", "output_file_map_test_suite")
1818
load(":pch_output_dir_tests.bzl", "pch_output_dir_test_suite")
1919
load(":private_deps_tests.bzl", "private_deps_test_suite")
2020
load(":private_swiftinterface_tests.bzl", "private_swiftinterface_test_suite")
21+
load(":runtime_deps_tests.bzl", "runtime_deps_test_suite")
2122
load(":split_derived_files_tests.bzl", "split_derived_files_test_suite")
2223
load(":swift_binary_linking_tests.bzl", "swift_binary_linking_test_suite")
2324
load(":swift_through_non_swift_tests.bzl", "swift_through_non_swift_test_suite")
@@ -75,6 +76,8 @@ utils_test_suite(name = "utils")
7576

7677
xctest_runner_test_suite(name = "xctest_runner")
7778

79+
runtime_deps_test_suite(name = "runtime_deps")
80+
7881
test_suite(
7982
name = "all_tests",
8083
)

test/fixtures/runtime_deps/BUILD

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
load("//swift:swift_binary.bzl", "swift_binary")
2+
load("//swift:swift_library.bzl", "swift_library")
3+
load("//test/fixtures:common.bzl", "FIXTURE_TAGS")
4+
5+
package(
6+
default_visibility = ["//test:__subpackages__"],
7+
)
8+
9+
exports_files(["transitive_data.txt"])
10+
11+
swift_library(
12+
name = "transitive_library",
13+
srcs = ["transitive_library.swift"],
14+
data = [":transitive_data.txt"],
15+
tags = FIXTURE_TAGS,
16+
)
17+
18+
swift_library(
19+
name = "direct_library",
20+
srcs = ["direct_library.swift"],
21+
tags = FIXTURE_TAGS,
22+
deps = [":transitive_library"],
23+
)
24+
25+
swift_binary(
26+
name = "runtime_deps",
27+
srcs = ["main.swift"],
28+
module_name = "binary",
29+
tags = FIXTURE_TAGS,
30+
deps = [":direct_library"],
31+
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public func foo() -> String {
2+
return "foo"
3+
}

test/fixtures/runtime_deps/main.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("hi")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Its some data
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public func foo() -> String {
2+
return "foo"
3+
}

test/runtime_deps_tests.bzl

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright 2020 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Tests for `swift_library.generated_header`."""
16+
17+
load(
18+
"//test/rules:provider_test.bzl",
19+
"provider_test",
20+
)
21+
22+
def runtime_deps_test_suite(name, tags = []):
23+
"""Test suite for `swift_binary` runtime deps.
24+
25+
Args:
26+
name: The base name to be used in targets created by this macro.
27+
tags: Additional tags to apply to each test.
28+
"""
29+
all_tags = [name] + tags
30+
31+
provider_test(
32+
name = "{}_swift_binary_runtime_deps".format(name),
33+
expected_files = [
34+
"test/fixtures/runtime_deps/transitive_data.txt",
35+
"*",
36+
],
37+
field = "default_runfiles.files",
38+
provider = "DefaultInfo",
39+
tags = all_tags,
40+
target_under_test = "//test/fixtures/runtime_deps",
41+
)
42+
43+
native.test_suite(
44+
name = name,
45+
tags = all_tags,
46+
)

0 commit comments

Comments
 (0)