-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement compilation support for
swift_module_mapping
PiperOrigin-RevId: 486694413 (cherry picked from commit ba41644) Signed-off-by: Brentley Jones <github@brentleyjones.com>
- Loading branch information
1 parent
c6d8d84
commit 149e554
Showing
10 changed files
with
268 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
load("//swift:swift_library.bzl", "swift_library") | ||
load("//swift:swift_module_mapping.bzl", "swift_module_mapping") | ||
load( | ||
"//test/fixtures:common.bzl", | ||
"FIXTURE_TAGS", | ||
) | ||
load(":apply_mapping.bzl", "apply_mapping") | ||
|
||
package( | ||
default_testonly = True, | ||
default_visibility = ["//test:__subpackages__"], | ||
) | ||
|
||
licenses(["notice"]) | ||
|
||
swift_library( | ||
name = "Common", | ||
srcs = ["Common.swift"], | ||
module_name = "Common", | ||
tags = FIXTURE_TAGS, | ||
) | ||
|
||
swift_library( | ||
name = "MySDK", | ||
srcs = ["MySDK.swift"], | ||
module_name = "MySDK", | ||
tags = FIXTURE_TAGS, | ||
deps = [":Common"], | ||
) | ||
|
||
swift_module_mapping( | ||
name = "MySDK_module_mapping", | ||
# This must not be testonly because it is used by the toolchain through the | ||
# `:module_mapping` label flag. | ||
testonly = False, | ||
aliases = { | ||
"Common": "MySDKInternal_Common", | ||
}, | ||
) | ||
|
||
# This is the target that will be tested in `module_mapping.bzl`, to force the | ||
# `MySDK` target to build in a configuration that sets the flag. | ||
apply_mapping( | ||
name = "MySDK_with_mapping", | ||
mapping = ":MySDK_module_mapping", | ||
target = ":MySDK", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2022 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. | ||
|
||
public final class Cat { | ||
public class var standardIssue: Common.Cat { Common.Cat() } | ||
|
||
public init() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2022 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. | ||
|
||
import Common | ||
|
||
public func makeStandardIssueCat() -> Common.Cat { | ||
return Common.Cat.standardIssue | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Copyright 2022 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. | ||
|
||
"""Rule and transition to force a specific module mapping in tests.""" | ||
|
||
def _apply_mapping_transition_impl(settings, attr): | ||
settings = dict(settings) | ||
settings["@build_bazel_rules_swift//swift:module_mapping"] = attr.mapping | ||
return settings | ||
|
||
apply_mapping_transition = transition( | ||
implementation = _apply_mapping_transition_impl, | ||
inputs = [], | ||
outputs = ["@build_bazel_rules_swift//swift:module_mapping"], | ||
) | ||
|
||
def _apply_mapping_impl(ctx): | ||
return [ctx.attr.target[0][DefaultInfo]] | ||
|
||
apply_mapping = rule( | ||
attrs = { | ||
"mapping": attr.label(), | ||
"target": attr.label(cfg = apply_mapping_transition), | ||
"_allowlist_function_transition": attr.label( | ||
default = "@bazel_tools//tools/allowlists/function_transition_allowlist", | ||
), | ||
}, | ||
implementation = _apply_mapping_impl, | ||
) |
Oops, something went wrong.