-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8a4623e
commit 04cd254
Showing
22 changed files
with
322 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# This file is from | ||
# https://github.com/acts-project/acts/blob/main/CI/iwyu/filter.py | ||
import sys | ||
import yaml | ||
import re | ||
import argparse | ||
from collections import namedtuple | ||
|
||
|
||
Config = namedtuple( | ||
"Config", ["remove_lines", "replace_lines", "ignore_files"], defaults=[[], [], []] | ||
) | ||
|
||
|
||
class State: | ||
skip_file: bool = False | ||
|
||
|
||
def parse_config(config: Config): | ||
remove_lines = [] | ||
for s in config["remove_lines"]: | ||
remove_lines.append(re.compile(s)) | ||
|
||
replace_lines = [] | ||
for s in config["replace_lines"]: | ||
s, r = list(s.items())[0] | ||
replace_lines.append((re.compile(s), r)) | ||
|
||
ignore_files = [] | ||
for s in config["ignore_files"]: | ||
ignore_files.append(re.compile(s)) | ||
|
||
return Config( | ||
remove_lines=remove_lines, | ||
replace_lines=replace_lines, | ||
ignore_files=ignore_files, | ||
) | ||
|
||
|
||
def filter(line: str, config: Config, state: State): | ||
if state.skip_file: | ||
if line.endswith("---\n"): | ||
state.skip_file = False | ||
return None | ||
|
||
if line.endswith(" should add these lines:\n"): | ||
for s in config.ignore_files: | ||
if s.search(line): | ||
state.skip_file = True | ||
return None | ||
|
||
for s in config.remove_lines: | ||
if s.search(line): | ||
return None | ||
|
||
for s, r in config.replace_lines: | ||
if s.search(line): | ||
return s.sub(r, line) | ||
|
||
return line | ||
|
||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument("config") | ||
parser.add_argument("input") | ||
parser.add_argument("output") | ||
args = parser.parse_args() | ||
|
||
with open(args.config, "r") as config_file: | ||
try: | ||
config = yaml.safe_load(config_file) | ||
config = parse_config(config) | ||
except yaml.YAMLError as exc: | ||
print(exc) | ||
sys.exit(1) | ||
|
||
with open(args.input, "r") as input_file, open(args.output, "w") as output_file: | ||
state = State() | ||
|
||
for line in input_file: | ||
filtered_line = filter(line, config, state) | ||
if filtered_line is not None: | ||
output_file.write(filtered_line) | ||
|
||
sys.exit(0) |
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,23 @@ | ||
# This file is from | ||
# https://github.com/acts-project/acts/blob/main/CI/iwyu/filter.yaml | ||
remove_lines: | ||
# ignore pybind11 | ||
- "^(- )?#include <pybind11/" | ||
- "^(- )?#include [<\"]pybind11/" | ||
# ignore python | ||
- "^#include <abstract.h>" | ||
- "^#include <floatobject.h>" | ||
- "^#include <longobject.h>" | ||
- "^#include <pyerrors.h>" | ||
|
||
replace_lines: | ||
- "^#include <assert\\.h>": "#include <cassert>" | ||
- "^#include <stddef\\.h>": "#include <cstddef>" | ||
- "^#include <math\\.h>": "#include <cmath>" | ||
- "^#include <limits\\.h>": "#include <climits>" | ||
- "^#include <unistd\\.h>": "#include <cunistd>" | ||
- "^#include <stdint\\.h>": "#include <cstdint>" | ||
- "^#include <stdlib.h>": "#include <cstdlib>" | ||
|
||
ignore_files: | ||
- ".*_deps/" |
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,171 @@ | ||
name: iwyu | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
- iwyu-2 | ||
pull_request: | ||
branches: | ||
- master | ||
|
||
workflow_dispatch: | ||
|
||
concurrency: | ||
group: iwyu-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
# References | ||
# https://github.com/official-stockfish/Stockfish/blob/master/.github/workflows/iwyu.yml | ||
# https://github.com/acts-project/acts/actions/runs/8588671882/workflow | ||
# https://github.com/acts-project/acts/tree/main/CI/iwyu | ||
|
||
jobs: | ||
iwyu: | ||
if: github.repository_owner == 'csukuangfj' || github.repository_owner == 'k2-fsa' | ||
permissions: | ||
contents: write # for stefanzweifel/git-auto-commit-action to push code in repo | ||
name: Include what you use | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ubuntu-latest] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Download required linux packages | ||
shell: bash | ||
run: | | ||
echo "GITHUB_WORKSPACE: $GITHUB_WORKSPACE" | ||
sudo add-apt-repository 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main' | ||
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - | ||
sudo apt update | ||
sudo apt install -y libclang-17-dev clang-17 libc++-17-dev | ||
- name: Display llvm | ||
shell: bash | ||
run: | | ||
ls -lh /usr/lib/*llvm* | ||
ls -lh /usr/bin/*clang* | ||
- name: cache-iwyu | ||
id: cache-iwyu | ||
uses: actions/cache@v4 | ||
with: | ||
path: /tmp/iwyu-install | ||
key: iwyu-install-2024-04-13 | ||
|
||
- name: Get IWYU source | ||
if: steps.cache-iwyu.outputs.cache-hit != 'true' | ||
uses: actions/checkout@v4 | ||
with: | ||
repository: include-what-you-use/include-what-you-use | ||
ref: clang_17 | ||
path: iwyu | ||
|
||
- name: Build IWYU | ||
if: steps.cache-iwyu.outputs.cache-hit != 'true' | ||
shell: bash | ||
run: | | ||
mkdir iwyu-build iwyu-install | ||
cmake -B iwyu-build -S iwyu -DCMAKE_PREFIX_PATH=/usr/lib/llvm-17 -DCMAKE_INSTALL_PREFIX=/tmp/iwyu-install | ||
cmake --build iwyu-build --target install | ||
ls -lh /tmp/iwyu-install | ||
tree /tmp/iwyu-install | ||
/tmp/iwyu-install/bin/include-what-you-use --version | ||
- name: setup path | ||
shell: bash | ||
run: | | ||
echo "/tmp/iwyu-install/bin" >> "$GITHUB_PATH" | ||
- name: display include what you use version | ||
shell: bash | ||
run: | | ||
include-what-you-use --version | ||
which include-what-you-use | ||
include-what-you-use --help | ||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: iwyu-install | ||
path: /tmpiwyu-install/* | ||
|
||
- name: Check | ||
shell: bash | ||
run: | | ||
mkdir build | ||
cd build | ||
cmake \ | ||
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ | ||
.. | ||
- name: Run iwyu_tool.py | ||
shell: bash | ||
run: | | ||
python3 /tmp/iwyu-install/bin/iwyu_tool.py -p build/ -j2 | tee iwyu-output.txt | ||
- name: Filter IWYU output | ||
shell: bash | ||
run: | | ||
python3 .github/scripts/filter.py .github/scripts/filter.yaml iwyu-output.txt iwyu-filtered.txt | ||
- name: Show IWYU output | ||
shell: bash | ||
run: | | ||
cat iwyu-output.txt | ||
- name: Show filtered IWYU output | ||
shell: bash | ||
run: | | ||
cat iwyu-filtered.txt | ||
- name: Upload IWYU output | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: iwyu | ||
path: | | ||
iwyu-output.txt | ||
iwyu-filtered.txt | ||
- name: Apply iwyu | ||
shell: bash | ||
run: | | ||
git status | ||
python3 /tmp/iwyu-install/bin/fix_includes.py < iwyu-filtered.txt | ||
rm -rf iwyu* | ||
- name: Show diff | ||
shell: bash | ||
run: | | ||
git status | ||
git diff | ||
git diff > a.diff | ||
# Download a.diff | ||
# Run | ||
# git apply a.diff | ||
- name: Upload IWYU output | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: diff | ||
path: | | ||
a.diff | ||
# https://github.com/stefanzweifel/git-auto-commit-action | ||
- uses: stefanzweifel/git-auto-commit-action@v5 | ||
if: false | ||
with: | ||
file_pattern: '*.h *.cc' | ||
commit_message: "apply iwyu changes" |
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
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
Oops, something went wrong.