From cde681e2d40a71cc06a294d347a32cf35785143d Mon Sep 17 00:00:00 2001 From: Reiko Asakura Date: Sun, 14 Feb 2021 10:51:17 -0500 Subject: Add lint workflow --- .github/workflows/lint.yml | 64 ++++++++++++++++++++++++++++++++++++++++++++++ iwyu.imp | 8 ++++++ scripts/nids-check-sort.py | 61 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 133 insertions(+) create mode 100644 .github/workflows/lint.yml create mode 100644 iwyu.imp create mode 100644 scripts/nids-check-sort.py diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..4dc2171 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,64 @@ +# +# Copyright (C) 2021 Reiko Asakura. All Rights Reserved. +# +# Vita Development Suite Libraries +# + +name: Lint + +on: + push: + schedule: + - cron: '0 10 * * *' + +env: + SCE_ROOT_DIR: ${{ github.workspace }}/ci-base/SCE + SCE_PSP2_SDK_DIR: ${{ github.workspace }}/ci-base/sdk + +jobs: + + lint: + name: Lint + runs-on: ubuntu-latest + steps: + + - name: Checkout + uses: actions/checkout@v2 + + - name: Checkout CI base + uses: actions/checkout@v2 + with: + repository: Vita-Development-Suite/ci-base + path: ci-base + token: ${{ secrets.PRIVATE_REPO_TOKEN }} + + - name: Check NIDs sort + run: | + python3 scripts/nids-check-sort.py + + - name: Check IWYU + run: | + sudo apt-get -qy install iwyu + python3 scripts/gen-test-compile.py + IWYU_COMMON_OPTS=" \ + -Xiwyu --mapping_file=iwyu.imp \ + -Xiwyu --no_comment \ + -Xiwyu --verbose=1 \ + -isystem ${{ env.SCE_PSP2_SDK_DIR }}/target/include \ + -isystem ${{ env.SCE_PSP2_SDK_DIR }}/target/include_common \ + -isystem ${{ env.SCE_PSP2_SDK_DIR }}/host_tools/build/include \ + --target=armv7a-none-eabi \ + -D __builtin_scei_arm_mrc(...)=0 \ + -D __builtin_scei_arm_mcr(...)=0 \ + -D __builtin_scei_arm_mcrr(...)=0 \ + -D __builtin_scei_arm_dsb_sy(...)=0 \ + -D __builtin_scei_arm_dmb_sy(...)=0" + find include/common -type f -exec \ + iwyu -Xiwyu --check_also='{}' all-common.cpp \ + -isystem include/common $IWYU_COMMON_OPTS ';' + find include/user -type f -exec \ + iwyu -Xiwyu --check_also='{}' all-user.cpp \ + -isystem include/user -isystem include/common $IWYU_COMMON_OPTS ';' + find include/kernel -type f -exec \ + iwyu -Xiwyu --check_also='{}' all-kernel.cpp \ + -isystem include/kernel -isystem include/common $IWYU_COMMON_OPTS ';' diff --git a/iwyu.imp b/iwyu.imp new file mode 100644 index 0000000..d45f709 --- /dev/null +++ b/iwyu.imp @@ -0,0 +1,8 @@ +[ + { include: ["@", "private", "", "public"] }, + { include: ["@", "private", "", "public"] }, + { include: ["@", "private", "", "public"] }, + { include: ["@", "private", "", "public"] }, + { include: ["@", "private", "", "public"] }, + { symbol: ["SceSize", "private", "", "public"]}, +] diff --git a/scripts/nids-check-sort.py b/scripts/nids-check-sort.py new file mode 100644 index 0000000..e125d6b --- /dev/null +++ b/scripts/nids-check-sort.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 + +# +# Copyright (C) 2021 Reiko Asakura. All Rights Reserved. +# +# Vita Development Suite Libraries +# + +import sys +from pathlib import Path + +from yaml import load +try: + from yaml import CLoader as Loader +except ImportError: + from yaml import SafeLoader as Loader + +def write_export_syms(syms): + out = '' + for name, nid in sorted(syms.items()): + out += f' {name}: 0x{nid:08X}\n' + return out + +def write_export_libs(exports): + out = '' + for libname, library in sorted(exports.items()): + out += f' {libname}:\n' + out += f' nid: 0x{library["nid"]:08X}\n' + if 'functions' in library and library['functions']: + out += ' functions:\n' + out += write_export_syms(library['functions']) + if 'variables' in library and library['variables']: + out += ' variables:\n' + out += write_export_syms(library['variables']) + return out + +def write_nids(nids): + out = 'modules:\n' + for modname, module in sorted(nids['modules'].items()): + out += f' {modname}:\n' + out += f' nid: 0x{module["nid"]:08X}\n' + if 'libraries' in module and module['libraries']: + out += ' libraries:\n' + out += write_export_libs(module['libraries']) + return out + +def check_sort(d): + for c in d.iterdir(): + if c.is_file(): + c_text = c.read_text() + c_sorted = write_nids(load(c_text, Loader=Loader)) + if c_text != c_sorted: + print(f'{c} is not sorted') + print(c_sorted) + sys.exit(1) + elif c.is_dir(): + check_sort(c) + else: + sys.exit("Unexpected file type") + +check_sort(Path('nids')) -- cgit v1.2.3