-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correctly exclude both the actual and virtual header when using `swif…
…t_interop_hint.exclude_hdrs` on a `cc_library` that has `include_prefix` and/or `strip_include_prefix` set. PiperOrigin-RevId: 412917671
- Loading branch information
1 parent
c8b58b5
commit 6b13232
Showing
13 changed files
with
253 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Copyright 2021 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 interoperability with `cc_library`-specific features.""" | ||
|
||
load( | ||
"@bazel_skylib//rules:build_test.bzl", | ||
"build_test", | ||
) | ||
|
||
def cc_library_test_suite(): | ||
"""Test suite for interoperability with `cc_library`-specific features.""" | ||
name = "cc_library" | ||
|
||
# Verify that Swift can import a `cc_library` that uses `include_prefix`, | ||
# `strip_include_prefix`, or both. | ||
build_test( | ||
name = "{}_swift_imports_cc_library_with_include_prefix_manipulation".format(name), | ||
targets = [ | ||
"@build_bazel_rules_swift//test/fixtures/cc_library:import_prefix_and_strip_prefix", | ||
"@build_bazel_rules_swift//test/fixtures/cc_library:import_prefix_only", | ||
"@build_bazel_rules_swift//test/fixtures/cc_library:import_strip_prefix_only", | ||
], | ||
tags = [name], | ||
) | ||
|
||
# Verify that `swift_interop_hint.exclude_hdrs` correctly excludes headers | ||
# from a `cc_library` that uses `include_prefix` and/or | ||
# `strip_include_prefix` (i.e., both the real header and the virtual header | ||
# are excluded). | ||
build_test( | ||
name = "{}_swift_interop_hint_excludes_headers_with_include_prefix_manipulation".format(name), | ||
targets = [ | ||
"@build_bazel_rules_swift//test/fixtures/cc_library:import_prefix_and_strip_prefix_with_exclusion", | ||
], | ||
tags = [name], | ||
) | ||
|
||
native.test_suite( | ||
name = name, | ||
tags = [name], | ||
) |
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,95 @@ | ||
load( | ||
"//swift:swift.bzl", | ||
"swift_interop_hint", | ||
"swift_library", | ||
) | ||
load("//test/fixtures:common.bzl", "FIXTURE_TAGS") | ||
|
||
package( | ||
default_visibility = ["//test:__subpackages__"], | ||
) | ||
|
||
licenses(["notice"]) | ||
|
||
############################################################################### | ||
# Fixtures for testing complex `cc_library` interop cases. | ||
|
||
cc_library( | ||
name = "prefix_only", | ||
hdrs = [ | ||
"header.h", | ||
"header_prefix_only.h", | ||
], | ||
aspect_hints = ["//swift:auto_module"], | ||
include_prefix = "some/prefix", | ||
tags = FIXTURE_TAGS, | ||
) | ||
|
||
cc_library( | ||
name = "strip_prefix_only", | ||
hdrs = [ | ||
"header.h", | ||
"header_strip_prefix_only.h", | ||
], | ||
aspect_hints = ["//swift:auto_module"], | ||
strip_include_prefix = "//test", | ||
tags = FIXTURE_TAGS, | ||
) | ||
|
||
cc_library( | ||
name = "prefix_and_strip_prefix", | ||
hdrs = [ | ||
"header.h", | ||
"header_prefix_and_strip_prefix.h", | ||
], | ||
aspect_hints = ["//swift:auto_module"], | ||
include_prefix = "some/prefix", | ||
strip_include_prefix = "//test", | ||
tags = FIXTURE_TAGS, | ||
) | ||
|
||
cc_library( | ||
name = "prefix_and_strip_prefix_with_exclusion", | ||
hdrs = [ | ||
"header.h", | ||
"header_with_error.h", | ||
], | ||
aspect_hints = [":prefix_and_strip_prefix_with_exclusion_swift_hint"], | ||
include_prefix = "some/prefix", | ||
strip_include_prefix = "//test", | ||
tags = FIXTURE_TAGS, | ||
) | ||
|
||
swift_interop_hint( | ||
name = "prefix_and_strip_prefix_with_exclusion_swift_hint", | ||
exclude_hdrs = ["header_with_error.h"], | ||
tags = FIXTURE_TAGS, | ||
) | ||
|
||
swift_library( | ||
name = "import_prefix_only", | ||
srcs = ["ImportPrefixOnly.swift"], | ||
tags = FIXTURE_TAGS, | ||
deps = [":prefix_only"], | ||
) | ||
|
||
swift_library( | ||
name = "import_strip_prefix_only", | ||
srcs = ["ImportStripPrefixOnly.swift"], | ||
tags = FIXTURE_TAGS, | ||
deps = [":strip_prefix_only"], | ||
) | ||
|
||
swift_library( | ||
name = "import_prefix_and_strip_prefix", | ||
srcs = ["ImportPrefixAndStripPrefix.swift"], | ||
tags = FIXTURE_TAGS, | ||
deps = [":prefix_and_strip_prefix"], | ||
) | ||
|
||
swift_library( | ||
name = "import_prefix_and_strip_prefix_with_exclusion", | ||
srcs = ["ImportPrefixAndStripPrefixWithExclusion.swift"], | ||
tags = FIXTURE_TAGS, | ||
deps = [":prefix_and_strip_prefix_with_exclusion"], | ||
) |
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,3 @@ | ||
import test_fixtures_cc_library_prefix_and_strip_prefix | ||
|
||
func f(_ x: some_structure) {} |
3 changes: 3 additions & 0 deletions
3
test/fixtures/cc_library/ImportPrefixAndStripPrefixWithExclusion.swift
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,3 @@ | ||
import test_fixtures_cc_library_prefix_and_strip_prefix_with_exclusion | ||
|
||
func f(_ x: some_structure) {} |
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,3 @@ | ||
import test_fixtures_cc_library_prefix_only | ||
|
||
func f(_ x: some_structure) {} |
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,3 @@ | ||
import test_fixtures_cc_library_strip_prefix_only | ||
|
||
func f(_ x: some_structure) {} |
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,8 @@ | ||
#ifndef RULES_SWIFT_TEST_FIXTURES_CC_LIBRARY_HEADER_H_ | ||
#define RULES_SWIFT_TEST_FIXTURES_CC_LIBRARY_HEADER_H_ | ||
|
||
typedef struct { | ||
int field; | ||
} some_structure; | ||
|
||
#endif // RULES_SWIFT_TEST_FIXTURES_CC_LIBRARY_HEADER_H_ |
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,6 @@ | ||
#ifndef RULES_SWIFT_TEST_FIXTURES_CC_LIBRARY_HEADER_PREFIX_AND_STRIP_PREFIX_H_ | ||
#define RULES_SWIFT_TEST_FIXTURES_CC_LIBRARY_HEADER_PREFIX_AND_STRIP_PREFIX_H_ | ||
|
||
#include "some/prefix/fixtures/cc_library/header.h" | ||
|
||
#endif // RULES_SWIFT_TEST_FIXTURES_CC_LIBRARY_HEADER_PREFIX_AND_STRIP_PREFIX_H_ |
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,6 @@ | ||
#ifndef RULES_SWIFT_TEST_FIXTURES_CC_LIBRARY_HEADER_PREFIX_ONLY_H_ | ||
#define RULES_SWIFT_TEST_FIXTURES_CC_LIBRARY_HEADER_PREFIX_ONLY_H_ | ||
|
||
#include "some/prefix/header.h" | ||
|
||
#endif // RULES_SWIFT_TEST_FIXTURES_CC_LIBRARY_HEADER_PREFIX_ONLY_H_ |
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,6 @@ | ||
#ifndef RULES_SWIFT_TEST_FIXTURES_CC_LIBRARY_HEADER_STRIP_PREFIX_ONLY_H_ | ||
#define RULES_SWIFT_TEST_FIXTURES_CC_LIBRARY_HEADER_STRIP_PREFIX_ONLY_H_ | ||
|
||
#include "fixtures/cc_library/header.h" | ||
|
||
#endif // RULES_SWIFT_TEST_FIXTURES_CC_LIBRARY_HEADER_STRIP_PREFIX_ONLY_H_ |
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,6 @@ | ||
#ifndef RULES_SWIFT_TEST_FIXTURES_CC_LIBRARY_HEADER_WITH_ERROR_H_ | ||
#define RULES_SWIFT_TEST_FIXTURES_CC_LIBRARY_HEADER_WITH_ERROR_H_ | ||
|
||
#error This should never get processed. | ||
|
||
#endif // RULES_SWIFT_TEST_FIXTURES_CC_LIBRARY_HEADER_WITH_ERROR_H_ |
6b13232
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#691
6b13232
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#1191