-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[clang-tidy] Move fuchsia-restrict-system-includes to portability mod…
…ule for general use. Summary: Created a general check for restrict-system-includes under portability as recommend in the comments under D75332. I also fleshed out the user facing documentation to show examples for common use-cases such as allow-list, block-list, and wild carding. Removed fuchsia's check as per phosek sugguestion. Reviewers: aaron.ballman, phosek, alexfh, hokein, njames93 Reviewed By: phosek Subscribers: Eugene.Zelenko, mgorny, xazax.hun, phosek, cfe-commits, MaskRay Tags: #clang-tools-extra, #clang Differential Revision: https://reviews.llvm.org/D75786
- Loading branch information
1 parent
5b0c60c
commit ebdb98f
Showing
26 changed files
with
103 additions
and
96 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
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
32 changes: 0 additions & 32 deletions
32
clang-tools-extra/docs/clang-tidy/checks/fuchsia-restrict-system-includes.rst
This file was deleted.
Oops, something went wrong.
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
51 changes: 51 additions & 0 deletions
51
clang-tools-extra/docs/clang-tidy/checks/portability-restrict-system-includes.rst
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,51 @@ | ||
.. title:: clang-tidy - portability-restrict-system-includes | ||
|
||
portability-restrict-system-includes | ||
==================================== | ||
|
||
Checks to selectively allow or disallow a configurable list of system headers. | ||
|
||
For example: | ||
|
||
In order to **only** allow `zlib.h` from the system you would set the options | ||
to `-*,zlib.h`. | ||
|
||
.. code-block:: c++ | ||
|
||
#include <curses.h> // Bad: disallowed system header. | ||
#include <openssl/ssl.h> // Bad: disallowed system header. | ||
#include <zlib.h> // Good: allowed system header. | ||
#include "src/myfile.h" // Good: non-system header always allowed. | ||
|
||
In order to allow everything **except** `zlib.h` from the system you would set | ||
the options to `*,-zlib.h`. | ||
|
||
.. code-block:: c++ | ||
|
||
#include <curses.h> // Good: allowed system header. | ||
#include <openssl/ssl.h> // Good: allowed system header. | ||
#include <zlib.h> // Bad: disallowed system header. | ||
#include "src/myfile.h" // Good: non-system header always allowed. | ||
|
||
Since the opions support globbing you can use wildcarding to allow groups of | ||
headers. | ||
|
||
`-*,openssl/*.h` will allow all openssl headers but disallow any others. | ||
|
||
.. code-block:: c++ | ||
|
||
#include <curses.h> // Bad: disallowed system header. | ||
#include <openssl/ssl.h> // Good: allowed system header. | ||
#include <openssl/rsa.h> // Good: allowed system header. | ||
#include <zlib.h> // Bad: disallowed system header. | ||
#include "src/myfile.h" // Good: non-system header always allowed. | ||
|
||
Options | ||
------- | ||
|
||
.. option:: Includes | ||
|
||
A string containing a comma separated glob list of allowed include | ||
filenames. Similar to the -checks glob list for running clang-tidy itself, | ||
the two wildcard characters are `*` and `-`, to include and exclude globs, | ||
respectively. The default is `*`, which allows all includes. |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 0 additions & 10 deletions
10
clang-tools-extra/test/clang-tidy/checkers/fuchsia-restrict-system-includes-all.cpp
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
clang-tools-extra/test/clang-tidy/checkers/fuchsia-restrict-system-includes-glob.cpp
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
clang-tools-extra/test/clang-tidy/checkers/fuchsia-restrict-system-includes.cpp
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
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,9 @@ | ||
// RUN: %check_clang_tidy %s portability-restrict-system-includes %t \ | ||
// RUN: -- -config="{CheckOptions: [{key: portability-restrict-system-includes.Includes, value: '*,-stdio.h'}]}" | ||
|
||
// Test block-list functionality: allow all but stdio.h. | ||
|
||
#include <stdio.h> | ||
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include stdio.h not allowed | ||
#include <stdlib.h> | ||
#include <string.h> |
10 changes: 10 additions & 0 deletions
10
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
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,10 @@ | ||
// RUN: %check_clang_tidy %s portability-restrict-system-includes %t \ | ||
// RUN: -- -config="{CheckOptions: [{key: portability-restrict-system-includes.Includes, value: '-*,stdio.h'}]}" | ||
|
||
// Test allow-list functionality: disallow all but stdio.h. | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include stdlib.h not allowed | ||
#include <string.h> | ||
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include string.h not allowed |
10 changes: 10 additions & 0 deletions
10
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-glob.cpp
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,10 @@ | ||
// RUN: %check_clang_tidy %s portability-restrict-system-includes %t \ | ||
// RUN: -- -config="{CheckOptions: [{key: portability-restrict-system-includes.Includes, value: '-*,std*.h'}]}" | ||
|
||
// Test glob functionality: disallow all headers except those that match | ||
// pattern "std*.h". | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include string.h not allowed |
10 changes: 5 additions & 5 deletions
10
...hsia-restrict-system-includes-headers.cpp → ...y-restrict-system-includes-transitive.cpp
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