-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for parse_headers (#337)
This feature enables bazel to validate "C++" header files through clang. Without this you only get this type of validating when you actually include the library elsewhere. Similar to layering_check we have to validate this outside of normal bazel because we are expecting build failures and need to parse the logs This mirrors bazelbuild/bazel#21560
- Loading branch information
Showing
8 changed files
with
113 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
load("@bazel_skylib//rules:build_test.bzl", "build_test") | ||
|
||
package(features = ["parse_headers"]) | ||
|
||
cc_library( | ||
name = "invalid_header", | ||
hdrs = ["invalid_header.h"], | ||
tags = ["manual"], | ||
) | ||
|
||
objc_library( | ||
name = "invalid_header_objc", | ||
hdrs = ["invalid_header.h"], | ||
tags = ["manual"], | ||
) | ||
|
||
cc_library( | ||
name = "invalid_header_feature_disabled", | ||
hdrs = ["invalid_header.h"], | ||
features = ["-parse_headers"], | ||
) | ||
|
||
cc_library( | ||
name = "valid_header", | ||
hdrs = ["valid_header.h"], | ||
) | ||
|
||
objc_library( | ||
name = "valid_header_objc", | ||
hdrs = ["valid_header.h"], | ||
) | ||
|
||
build_test( | ||
name = "test", | ||
targets = [ | ||
":invalid_header_feature_disabled", | ||
":valid_header", | ||
":valid_header_objc", | ||
], | ||
) |
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,2 @@ | ||
// Missing include of cstdint, which defines uint8_t. | ||
uint8_t foo(); |
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 @@ | ||
#include <cstdint> | ||
|
||
uint8_t foo(); |
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,24 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
script_path="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
source "$script_path"/unittest.bash | ||
|
||
bazel="${BAZEL:-bazel}" | ||
|
||
function test_good_header_parsing() { | ||
"$bazel" test --process_headers_in_dependencies -- //test/header_parsing/... &>"$TEST_log" | ||
} | ||
|
||
function test_bad_header_parsing() { | ||
! "$bazel" test --process_headers_in_dependencies -- //test/header_parsing:invalid_header &> "$TEST_log" || fail "Expected build failure" | ||
expect_log "test/header_parsing/invalid_header.h:2:1: error: unknown type name 'uint8_t'" | ||
} | ||
|
||
function test_bad_header_parsing_objc() { | ||
! "$bazel" test --process_headers_in_dependencies -- //test/header_parsing:invalid_header_objc &> "$TEST_log" || fail "Expected build failure" | ||
expect_log "test/header_parsing/invalid_header.h:2:1: error: unknown type name 'uint8_t'" | ||
} | ||
|
||
run_suite "header_parsing tests" |