Skip to content

Commit

Permalink
Enable warnings for the native cc rules & symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
hvadehra committed Jan 22, 2025
1 parent 54b4ddb commit f18e593
Show file tree
Hide file tree
Showing 8 changed files with 501 additions and 85 deletions.
200 changes: 191 additions & 9 deletions WARNINGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,25 @@ Warning categories supported by buildifier's linter:
* [`name-conventions`](#name-conventions)
* [`native-android`](#native-android)
* [`native-build`](#native-build)
* [`native-cc`](#native-cc)
* [`native-cc-binary`](#native-cc-binary)
* [`native-cc-common`](#native-cc-common)
* [`native-cc-debug-package-info`](#native-cc-debug-package-info)
* [`native-cc-fdo-prefetch-hints`](#native-cc-fdo-prefetch-hints)
* [`native-cc-fdo-profile`](#native-cc-fdo-profile)
* [`native-cc-import`](#native-cc-import)
* [`native-cc-info`](#native-cc-info)
* [`native-cc-library`](#native-cc-library)
* [`native-cc-memprof-profile`](#native-cc-memprof-profile)
* [`native-cc-objc-import`](#native-cc-objc-import)
* [`native-cc-objc-library`](#native-cc-objc-library)
* [`native-cc-propeller-optimize`](#native-cc-propeller-optimize)
* [`native-cc-proto`](#native-cc-proto)
* [`native-cc-shared-library`](#native-cc-shared-library)
* [`native-cc-shared-library-hint-info`](#native-cc-shared-library-hint-info)
* [`native-cc-shared-library-info`](#native-cc-shared-library-info)
* [`native-cc-test`](#native-cc-test)
* [`native-cc-toolchain`](#native-cc-toolchain)
* [`native-cc-toolchain-suite`](#native-cc-toolchain-suite)
* [`native-java-binary`](#native-java-binary)
* [`native-java-common`](#native-java-common)
* [`native-java-import`](#native-java-import)
Expand Down Expand Up @@ -698,18 +715,123 @@ as global symbols there.

--------------------------------------------------------------------------------

## <a name="native-cc"></a>All C++ build rules should be loaded from Starlark
## <a name="native-cc-binary"></a>All C++ build rules should be loaded from Starlark

* Category name: `native-cc`
* Flag in Bazel: [`--incompatible_load_cc_rules_from_bzl`](https://github.com/bazelbuild/bazel/issues/8743)
* Category name: `native-cc-binary`
* Automatic fix: yes
* [Suppress the warning](#suppress): `# buildifier: disable=native-cc`
* [Suppress the warning](#suppress): `# buildifier: disable=native-cc-binary`

The CC build rules should be loaded from Starlark.
The CC build rules should be loaded from @rules_cc.

Update: the plans for disabling native rules
[have been postponed](https://groups.google.com/g/bazel-discuss/c/XNvpWcge4AE/m/aJ-aQzszAwAJ),
at the moment it's not required to load Starlark rules.
--------------------------------------------------------------------------------

## <a name="native-cc-common"></a>All C++ build rules should be loaded from Starlark

* Category name: `native-cc-common`
* Automatic fix: yes
* [Suppress the warning](#suppress): `# buildifier: disable=native-cc-common`

The CC build rules should be loaded from @rules_cc.

--------------------------------------------------------------------------------

## <a name="native-cc-debug-package-info"></a>All C++ build rules should be loaded from Starlark

* Category name: `native-cc-debug-package-info`
* Automatic fix: yes
* [Suppress the warning](#suppress): `# buildifier: disable=native-cc-debug-package-info`

The CC build rules should be loaded from @rules_cc.

--------------------------------------------------------------------------------

## <a name="native-cc-fdo-prefetch-hints"></a>All C++ build rules should be loaded from Starlark

* Category name: `native-cc-fdo-prefetch-hints`
* Automatic fix: yes
* [Suppress the warning](#suppress): `# buildifier: disable=native-cc-fdo-prefetch-hints`

The CC build rules should be loaded from @rules_cc.

--------------------------------------------------------------------------------

## <a name="native-cc-fdo-profile"></a>All C++ build rules should be loaded from Starlark

* Category name: `native-cc-fdo-profile`
* Automatic fix: yes
* [Suppress the warning](#suppress): `# buildifier: disable=native-cc-fdo-profile`

The CC build rules should be loaded from @rules_cc.

--------------------------------------------------------------------------------

## <a name="native-cc-import"></a>All C++ build rules should be loaded from Starlark

* Category name: `native-cc-import`
* Automatic fix: yes
* [Suppress the warning](#suppress): `# buildifier: disable=native-cc-import`

The CC build rules should be loaded from @rules_cc.

--------------------------------------------------------------------------------

## <a name="native-cc-info"></a>All C++ build rules should be loaded from Starlark

* Category name: `native-cc-info`
* Automatic fix: yes
* [Suppress the warning](#suppress): `# buildifier: disable=native-cc-info`

The CC build rules should be loaded from @rules_cc.

--------------------------------------------------------------------------------

## <a name="native-cc-library"></a>All C++ build rules should be loaded from Starlark

* Category name: `native-cc-library`
* Automatic fix: yes
* [Suppress the warning](#suppress): `# buildifier: disable=native-cc-library`

The CC build rules should be loaded from @rules_cc.

--------------------------------------------------------------------------------

## <a name="native-cc-memprof-profile"></a>All C++ build rules should be loaded from Starlark

* Category name: `native-cc-memprof-profile`
* Automatic fix: yes
* [Suppress the warning](#suppress): `# buildifier: disable=native-cc-memprof-profile`

The CC build rules should be loaded from @rules_cc.

--------------------------------------------------------------------------------

## <a name="native-cc-objc-import"></a>All C++ build rules should be loaded from Starlark

* Category name: `native-cc-objc-import`
* Automatic fix: yes
* [Suppress the warning](#suppress): `# buildifier: disable=native-cc-objc-import`

The CC build rules should be loaded from @rules_cc.

--------------------------------------------------------------------------------

## <a name="native-cc-objc-library"></a>All C++ build rules should be loaded from Starlark

* Category name: `native-cc-objc-library`
* Automatic fix: yes
* [Suppress the warning](#suppress): `# buildifier: disable=native-cc-objc-library`

The CC build rules should be loaded from @rules_cc.

--------------------------------------------------------------------------------

## <a name="native-cc-propeller-optimize"></a>All C++ build rules should be loaded from Starlark

* Category name: `native-cc-propeller-optimize`
* Automatic fix: yes
* [Suppress the warning](#suppress): `# buildifier: disable=native-cc-propeller-optimize`

The CC build rules should be loaded from @rules_cc.

--------------------------------------------------------------------------------

Expand All @@ -724,6 +846,66 @@ The cc_proto_library rule should be loaded from Starlark.

--------------------------------------------------------------------------------

## <a name="native-cc-shared-library"></a>All C++ build rules should be loaded from Starlark

* Category name: `native-cc-shared-library`
* Automatic fix: yes
* [Suppress the warning](#suppress): `# buildifier: disable=native-cc-shared-library`

The CC build rules should be loaded from @rules_cc.

--------------------------------------------------------------------------------

## <a name="native-cc-shared-library-hint-info"></a>All C++ build rules should be loaded from Starlark

* Category name: `native-cc-shared-library-hint-info`
* Automatic fix: yes
* [Suppress the warning](#suppress): `# buildifier: disable=native-cc-shared-library-hint-info`

The CC build rules should be loaded from @rules_cc.

--------------------------------------------------------------------------------

## <a name="native-cc-shared-library-info"></a>All C++ build rules should be loaded from Starlark

* Category name: `native-cc-shared-library-info`
* Automatic fix: yes
* [Suppress the warning](#suppress): `# buildifier: disable=native-cc-shared-library-info`

The CC build rules should be loaded from @rules_cc.

--------------------------------------------------------------------------------

## <a name="native-cc-test"></a>All C++ build rules should be loaded from Starlark

* Category name: `native-cc-test`
* Automatic fix: yes
* [Suppress the warning](#suppress): `# buildifier: disable=native-cc-test`

The CC build rules should be loaded from @rules_cc.

--------------------------------------------------------------------------------

## <a name="native-cc-toolchain"></a>All C++ build rules should be loaded from Starlark

* Category name: `native-cc-toolchain`
* Automatic fix: yes
* [Suppress the warning](#suppress): `# buildifier: disable=native-cc-toolchain`

The CC build rules should be loaded from @rules_cc.

--------------------------------------------------------------------------------

## <a name="native-cc-toolchain-suite"></a>All C++ build rules should be loaded from Starlark

* Category name: `native-cc-toolchain-suite`
* Automatic fix: yes
* [Suppress the warning](#suppress): `# buildifier: disable=native-cc-toolchain-suite`

The CC build rules should be loaded from @rules_cc.

--------------------------------------------------------------------------------

## <a name="native-java-binary"></a>All Java build rules should be loaded from Starlark

* Category name: `native-java-binary`
Expand Down
78 changes: 73 additions & 5 deletions buildifier/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,25 @@ func ExampleExample() {
// "name-conventions",
// "native-android",
// "native-build",
// "native-cc",
// "native-cc-binary",
// "native-cc-common",
// "native-cc-debug-package-info",
// "native-cc-fdo-prefetch-hints",
// "native-cc-fdo-profile",
// "native-cc-import",
// "native-cc-info",
// "native-cc-library",
// "native-cc-memprof-profile",
// "native-cc-objc-import",
// "native-cc-objc-library",
// "native-cc-propeller-optimize",
// "native-cc-proto",
// "native-cc-shared-library",
// "native-cc-shared-library-hint-info",
// "native-cc-shared-library-info",
// "native-cc-test",
// "native-cc-toolchain",
// "native-cc-toolchain-suite",
// "native-java-binary",
// "native-java-common",
// "native-java-import",
Expand Down Expand Up @@ -279,8 +296,25 @@ func TestValidate(t *testing.T) {
"name-conventions",
"native-android",
"native-build",
"native-cc",
"native-cc-binary",
"native-cc-common",
"native-cc-debug-package-info",
"native-cc-fdo-prefetch-hints",
"native-cc-fdo-profile",
"native-cc-import",
"native-cc-info",
"native-cc-library",
"native-cc-memprof-profile",
"native-cc-objc-import",
"native-cc-objc-library",
"native-cc-propeller-optimize",
"native-cc-proto",
"native-cc-shared-library",
"native-cc-shared-library-hint-info",
"native-cc-shared-library-info",
"native-cc-test",
"native-cc-toolchain",
"native-cc-toolchain-suite",
"native-java-binary",
"native-java-common",
"native-java-import",
Expand Down Expand Up @@ -361,8 +395,25 @@ func TestValidate(t *testing.T) {
"name-conventions",
"native-android",
"native-build",
"native-cc",
"native-cc-binary",
"native-cc-common",
"native-cc-debug-package-info",
"native-cc-fdo-prefetch-hints",
"native-cc-fdo-profile",
"native-cc-import",
"native-cc-info",
"native-cc-library",
"native-cc-memprof-profile",
"native-cc-objc-import",
"native-cc-objc-library",
"native-cc-propeller-optimize",
"native-cc-proto",
"native-cc-shared-library",
"native-cc-shared-library-hint-info",
"native-cc-shared-library-info",
"native-cc-test",
"native-cc-toolchain",
"native-cc-toolchain-suite",
"native-java-binary",
"native-java-common",
"native-java-import",
Expand Down Expand Up @@ -443,8 +494,25 @@ func TestValidate(t *testing.T) {
"name-conventions",
"native-android",
"native-build",
"native-cc",
"native-cc-binary",
"native-cc-common",
"native-cc-debug-package-info",
"native-cc-fdo-prefetch-hints",
"native-cc-fdo-profile",
"native-cc-import",
"native-cc-info",
"native-cc-library",
"native-cc-memprof-profile",
"native-cc-objc-import",
"native-cc-objc-library",
"native-cc-propeller-optimize",
"native-cc-proto",
"native-cc-shared-library",
"native-cc-shared-library-hint-info",
"native-cc-shared-library-info",
"native-cc-test",
"native-cc-toolchain",
"native-cc-toolchain-suite",
"native-java-binary",
"native-java-common",
"native-java-import",
Expand Down Expand Up @@ -490,7 +558,7 @@ func TestValidate(t *testing.T) {
"unused-variable",
"unsorted-dict-items",
}},
"warnings error": {options: "--warnings=native-cc,-print,-deprecated-function", wantErr: fmt.Errorf(`warning categories with modifiers ("+" or "-") can't be mixed with raw warning categories`)},
"warnings error": {options: "--warnings=native-py,-print,-deprecated-function", wantErr: fmt.Errorf(`warning categories with modifiers ("+" or "-") can't be mixed with raw warning categories`)},
} {
t.Run(name, func(t *testing.T) {
c := New()
Expand Down
19 changes: 18 additions & 1 deletion buildifier/integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,25 @@ cat > golden/.buildifier.example.json <<EOF
"name-conventions",
"native-android",
"native-build",
"native-cc",
"native-cc-binary",
"native-cc-common",
"native-cc-debug-package-info",
"native-cc-fdo-prefetch-hints",
"native-cc-fdo-profile",
"native-cc-import",
"native-cc-info",
"native-cc-library",
"native-cc-memprof-profile",
"native-cc-objc-import",
"native-cc-objc-library",
"native-cc-propeller-optimize",
"native-cc-proto",
"native-cc-shared-library",
"native-cc-shared-library-hint-info",
"native-cc-shared-library-info",
"native-cc-test",
"native-cc-toolchain",
"native-cc-toolchain-suite",
"native-java-binary",
"native-java-common",
"native-java-import",
Expand Down
18 changes: 2 additions & 16 deletions tables/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,22 +228,8 @@ var AndroidNativeRules = []string{
// AndroidLoadPath is the load path for the Starlark Android Rules.
var AndroidLoadPath = "@rules_android//android:rules.bzl"

// CcNativeRules lists all C++ rules that are being migrated from Native to Starlark.
var CcNativeRules = []string{
"cc_binary",
"cc_test",
"cc_library",
"cc_import",
"fdo_prefetch_hints",
"fdo_profile",
"cc_toolchain",
"cc_toolchain_suite",
"objc_library",
"objc_import",
}

// CcLoadPath is the load path for the Starlark C++ Rules.
var CcLoadPath = "@rules_cc//cc:defs.bzl"
// CcLoadPathPrefix is the load path for the Starlark C++ Rules.
var CcLoadPathPrefix = "@rules_cc//cc"

// JavaLoadPathPrefix is the load package for the Starlark Java Rules.
var JavaLoadPathPrefix = "@rules_java//java"
Expand Down
Loading

0 comments on commit f18e593

Please sign in to comment.