Skip to content

Commit d9d7798

Browse files
keithcopybara-github
authored andcommitted
Add strip_include_prefix textual_hdrs test
Copybara Import from #634 BEGIN_PUBLIC Add strip_include_prefix textual_hdrs test (#634) This is a test case for 1212a51 that didn't merge with that PR because of the tests living in bazel vs here. Closes #634 END_PUBLIC COPYBARA_INTEGRATE_REVIEW=#634 from keith:ks/add-strip_include_prefix-textual_hdrs-test 81a12a5 PiperOrigin-RevId: 884321378 Change-Id: Ia914af93349ad9c1a152de3f68dfe51eff5f7c7c
1 parent 748fbdf commit d9d7798

5 files changed

Lines changed: 122 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Copyright 2025 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+
load("@bazel_features//private:util.bzl", _bazel_version_ge = "ge")
16+
load("//cc:cc_library.bzl", "cc_library")
17+
load("//cc:cc_test.bzl", "cc_test")
18+
load("//cc/common:semantics.bzl", "STRIP_INCLUDE_PREFIX_APPLIES_TO_TEXTUAL_HEADERS")
19+
20+
licenses(["notice"])
21+
22+
_SUPPORTED = _bazel_version_ge("9.0.0-pre.20250911") and STRIP_INCLUDE_PREFIX_APPLIES_TO_TEXTUAL_HEADERS
23+
24+
cc_library(
25+
name = "lib",
26+
srcs = ["nested/lib.cc"],
27+
strip_include_prefix = "nested",
28+
target_compatible_with = ["@platforms//:incompatible"] if not _SUPPORTED else [],
29+
textual_hdrs = [
30+
"nested/lib.h",
31+
"not_nested.h",
32+
],
33+
)
34+
35+
cc_test(
36+
name = "test_include_textual",
37+
srcs = ["test_include_textual.cc"],
38+
deps = [":lib"],
39+
)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2025 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+
#include "lib.h"
16+
17+
int foo() { return 42; }
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2025 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+
#ifndef TESTS_STRIP_INCLUDE_PREFIX_LIB_H
16+
#define TESTS_STRIP_INCLUDE_PREFIX_LIB_H
17+
18+
int foo();
19+
20+
#endif // TESTS_STRIP_INCLUDE_PREFIX_LIB_H
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2025 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+
#ifndef TESTS_STRIP_INCLUDE_PREFIX_NOT_NESTED_H
16+
#define TESTS_STRIP_INCLUDE_PREFIX_NOT_NESTED_H
17+
18+
#define NOT_NESTED 42
19+
20+
#endif // TESTS_STRIP_INCLUDE_PREFIX_NOT_NESTED_H
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2025 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+
#include "lib.h"
16+
#include "not_nested.h"
17+
18+
int main() {
19+
if (foo() != 42) {
20+
return 1;
21+
}
22+
if (NOT_NESTED != 42) {
23+
return 2;
24+
}
25+
return 0;
26+
}

0 commit comments

Comments
 (0)