Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

Commit

Permalink
Clean up some old TODOs.
Browse files Browse the repository at this point in the history
- Remove some deprecated fields.
- Assert that atleast one module is provided.

RELNOTES: None
PiperOrigin-RevId: 344261262
  • Loading branch information
thomasvl authored and swiple-rules-gardener committed Nov 25, 2020
1 parent 72f5759 commit eefede5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 93 deletions.
91 changes: 3 additions & 88 deletions swift/internal/providers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"""Defines Starlark providers that propagated by the Swift BUILD rules."""

load("@bazel_skylib//lib:sets.bzl", "sets")
load("@bazel_skylib//lib:types.bzl", "types")

SwiftInfo = provider(
doc = """\
Expand All @@ -34,18 +33,6 @@ library that directly propagated this provider.
"direct_modules": """\
`List` of values returned from `swift_common.create_module`. The modules (both
Swift and C/Objective-C) emitted by the library that propagated this provider.
""",
"direct_swiftdocs": """\
`List` of `File`s. The Swift documentation (`.swiftdoc`) files for the library
that directly propagated this provider.
This field is deprecated; use `direct_modules` instead.
""",
"direct_swiftmodules": """\
`List` of `File`s. The Swift modules (`.swiftmodule`) for the library that
directly propagated this provider.
This field is deprecated; use `direct_modules` instead.
""",
"module_name": """\
`String`. The name of the Swift module represented by the target that directly
Expand All @@ -71,37 +58,11 @@ propagated this provider and all of its dependencies.
"transitive_generated_headers": """\
`Depset` of `File`s. The transitive generated header files that can be used by
Objective-C sources to interop with the transitive Swift libraries.
""",
"transitive_modulemaps": """\
`Depset` of `File`s. The transitive module map files that will be passed to
Clang using the `-fmodule-map-file` option.
This field is deprecated; use `transitive_modules` instead.
""",
"transitive_modules": """\
`Depset` of values returned from `swift_common.create_module`. The transitive
modules (both Swift and C/Objective-C) emitted by the library that propagated
this provider and all of its dependencies.
""",
"transitive_swiftdocs": """\
`Depset` of `File`s. The transitive Swift documentation (`.swiftdoc`) files
emitted by the library that propagated this provider and all of its
dependencies.
This field is deprecated; use `transitive_modules` instead.
""",
"transitive_swiftinterfaces": """\
`Depset` of `File`s. The transitive Swift interface (`.swiftinterface`) files
emitted by the library that propagated this provider and all of its
dependencies.
This field is deprecated; use `transitive_modules` instead.
""",
"transitive_swiftmodules": """\
`Depset` of `File`s. The transitive Swift modules (`.swiftmodule`) emitted by
the library that propagated this provider and all of its dependencies.
This field is deprecated; use `transitive_modules` instead.
""",
},
)
Expand Down Expand Up @@ -265,9 +226,8 @@ def create_module(name, *, clang = None, swift = None):
A `struct` containing the `name`, `clang`, and `swift` fields provided
as arguments.
"""

# TODO(b/149999519): Once Swift module artifacts have migrated to this API,
# fail if both `clang` and `swift` are `None`.
if clang == None and swift == None:
fail("Must provide atleast a clang or swift module.")
return struct(
clang = clang,
name = name,
Expand Down Expand Up @@ -370,13 +330,8 @@ def create_swift_info(
A new `SwiftInfo` provider with the given values.
"""

# TODO(b/149999519): Remove the legacy direct/transitive fields and this
# transitional code.
defines_set = sets.make()
generated_headers = []
swiftdocs = []
swiftinterfaces = []
swiftmodules = []
for module in modules:
swift_module = module.swift
if not swift_module:
Expand All @@ -387,12 +342,6 @@ def create_swift_info(
defines_set,
sets.make(swift_module.defines),
)
if swift_module.swiftdoc:
swiftdocs.append(swift_module.swiftdoc)
if swift_module.swiftinterface:
swiftinterfaces.append(swift_module.swiftinterface)
if swift_module.swiftmodule:
swiftmodules.append(swift_module.swiftmodule)

# If this is both a Swift and a Clang module, then the header in its
# compilation context is its Swift generated header.
Expand All @@ -404,8 +353,7 @@ def create_swift_info(

defines = sets.to_list(defines_set)

# TODO(b/149999519): Remove the legacy `module_name` field and this
# transitional code.
# TODO(b/149999519): Remove the legacy `module_name`.
if not module_name and len(modules) == 1:
# Populate the module name based on the single module provided, if there
# was one, and if the legacy `module_name` parameter wasn't already
Expand All @@ -414,56 +362,23 @@ def create_swift_info(

transitive_defines = []
transitive_generated_headers = []
transitive_modulemaps = []
transitive_modules = []
transitive_swiftdocs = []
transitive_swiftinterfaces = []
transitive_swiftmodules = []
for swift_info in swift_infos:
transitive_defines.append(swift_info.transitive_defines)
transitive_generated_headers.append(
swift_info.transitive_generated_headers,
)
transitive_modulemaps.append(swift_info.transitive_modulemaps)
transitive_modules.append(swift_info.transitive_modules)
transitive_swiftdocs.append(swift_info.transitive_swiftdocs)
transitive_swiftinterfaces.append(swift_info.transitive_swiftinterfaces)
transitive_swiftmodules.append(swift_info.transitive_swiftmodules)

# TODO(b/149999519): Remove `transitive_modulemaps`,
# `(direct|transitive)_swift*` fields, `module_name`, and `swift_version`
# after Tulsi is migrated.
return SwiftInfo(
direct_defines = defines,
direct_modules = modules,
direct_swiftdocs = swiftdocs,
direct_swiftmodules = swiftmodules,
module_name = module_name,
swift_version = swift_version,
transitive_defines = depset(defines, transitive = transitive_defines),
transitive_generated_headers = depset(
generated_headers,
transitive = transitive_generated_headers,
),
transitive_modulemaps = depset(
[
m.clang.module_map
for m in modules
if m.clang and not types.is_string(m.clang.module_map)
],
transitive = transitive_modulemaps,
),
transitive_modules = depset(modules, transitive = transitive_modules),
transitive_swiftdocs = depset(
swiftdocs,
transitive = transitive_swiftdocs,
),
transitive_swiftinterfaces = depset(
swiftinterfaces,
transitive = transitive_swiftinterfaces,
),
transitive_swiftmodules = depset(
swiftmodules,
transitive = transitive_swiftmodules,
),
)
8 changes: 4 additions & 4 deletions test/private_deps_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def private_deps_test_suite():
expected_files = [
"test_fixtures_private_deps_private_swift.swiftmodule",
],
field = "transitive_swiftmodules",
field = "transitive_modules.swift!.swiftmodule",
provider = "SwiftInfo",
tags = [name],
target_under_test = "@build_bazel_rules_swift//test/fixtures/private_deps:private_swift",
Expand All @@ -48,7 +48,7 @@ def private_deps_test_suite():
expected_files = [
"test_fixtures_private_deps_public_swift.swiftmodule",
],
field = "transitive_swiftmodules",
field = "transitive_modules.swift!.swiftmodule",
provider = "SwiftInfo",
tags = [name],
target_under_test = "@build_bazel_rules_swift//test/fixtures/private_deps:public_swift",
Expand All @@ -63,7 +63,7 @@ def private_deps_test_suite():
"test_fixtures_private_deps_public_swift.swiftmodule",
"-test_fixtures_private_deps_private_swift.swiftmodule",
],
field = "transitive_swiftmodules",
field = "transitive_modules.swift!.swiftmodule",
provider = "SwiftInfo",
tags = [name],
target_under_test = "@build_bazel_rules_swift//test/fixtures/private_deps:client_swift_deps",
Expand Down Expand Up @@ -94,7 +94,7 @@ def private_deps_test_suite():
"/test/fixtures/private_deps/public_cc.modulemaps/module.modulemap",
"-/test/fixtures/private_deps/private_cc.modulemaps/module.modulemap",
],
field = "transitive_modulemaps",
field = "transitive_modules.clang!.module_map",
provider = "SwiftInfo",
tags = [name],
target_under_test = "@build_bazel_rules_swift//test/fixtures/private_deps:client_cc_deps",
Expand Down
2 changes: 1 addition & 1 deletion test/swift_through_non_swift_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def swift_through_non_swift_test_suite():
"test_fixtures_swift_through_non_swift_lower.swiftmodule",
"test_fixtures_swift_through_non_swift_upper.swiftmodule",
],
field = "transitive_swiftmodules",
field = "transitive_modules.swift!.swiftmodule",
provider = "SwiftInfo",
tags = [name],
target_under_test = "@build_bazel_rules_swift//test/fixtures/swift_through_non_swift:upper",
Expand Down

0 comments on commit eefede5

Please sign in to comment.