From 93c89381ce77f01d1b925dcd1ce0558708be4b2d Mon Sep 17 00:00:00 2001 From: sksat Date: Thu, 21 Sep 2023 13:36:37 +0900 Subject: [PATCH 1/9] check coding rule under config file path --- script/ci/check_coding_rule.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/script/ci/check_coding_rule.py b/script/ci/check_coding_rule.py index aa453975..1809fae2 100644 --- a/script/ci/check_coding_rule.py +++ b/script/ci/check_coding_rule.py @@ -59,7 +59,9 @@ def main(): print("WARNING: " + rule_name + " rule is ignored!!") settings["check_funcs"] = check_funcs # ここだけ, settings に追記している - if not check_coding_rule(settings): + check_root_dir = os.path.dirname(setting_file_path) + r"/" + + if not check_coding_rule(check_root_dir, settings): print("The above files are invalid coding rule.") sys.exit(1) print("Completed!") @@ -67,18 +69,18 @@ def main(): # True: OK, False: NG -def check_coding_rule(settings: dict) -> bool: +def check_coding_rule(check_root_dir: str, settings: dict) -> bool: flag = True target_dirs = [] for target_dir in settings["target_dirs"]: - target_dirs.append(settings["c2a_root_dir"] + target_dir) + target_dirs.append(check_root_dir + target_dir) ignore_dirs = [] for ignore_dir in settings["ignore_dirs"]: - ignore_dirs.append(settings["c2a_root_dir"] + ignore_dir) + ignore_dirs.append(check_root_dir + ignore_dir) ignore_files = [] for ignore_file in settings["ignore_files"]: - ignore_files.append(settings["c2a_root_dir"] + ignore_file) + ignore_files.append(check_root_dir + ignore_file) preprocess_(target_dirs, ignore_dirs, ignore_files, settings) From e7c2dcc7f02fe30ace6c753f39cd974996b90cec Mon Sep 17 00:00:00 2001 From: sksat Date: Thu, 21 Sep 2023 13:38:39 +0900 Subject: [PATCH 2/9] move check-coding-rule config file to C2A user top --- .../mobc}/check_coding_rule.json | 13 +++--- examples/subobc/check_coding_rule.json | 40 +++++++++++++++++++ 2 files changed, 46 insertions(+), 7 deletions(-) rename {script/ci => examples/mobc}/check_coding_rule.json (81%) create mode 100644 examples/subobc/check_coding_rule.json diff --git a/script/ci/check_coding_rule.json b/examples/mobc/check_coding_rule.json similarity index 81% rename from script/ci/check_coding_rule.json rename to examples/mobc/check_coding_rule.json index c55a06c9..5c9e1e79 100644 --- a/script/ci/check_coding_rule.json +++ b/examples/mobc/check_coding_rule.json @@ -1,17 +1,16 @@ { - "c2a_root_dir" : "./", "input_file_encoding" : "utf-8", "target_dirs" : [ - "src_core/", - "src_user/" + "src/src_core/", + "src/src_user/" ], "ignore_dirs" : [ - "src_core/examples", - "src_core/docs", - "src_core/script" + "src/src_core/examples", + "src/src_core/docs", + "src/src_core/script" ], "ignore_files" : [ - "src_user/tlm_cmd/telemetry_definitions.c" + "src/src_user/tlm_cmd/telemetry_definitions.c" ], "ignore_rules" : [ ], diff --git a/examples/subobc/check_coding_rule.json b/examples/subobc/check_coding_rule.json new file mode 100644 index 00000000..5c9e1e79 --- /dev/null +++ b/examples/subobc/check_coding_rule.json @@ -0,0 +1,40 @@ +{ + "input_file_encoding" : "utf-8", + "target_dirs" : [ + "src/src_core/", + "src/src_user/" + ], + "ignore_dirs" : [ + "src/src_core/examples", + "src/src_core/docs", + "src/src_core/script" + ], + "ignore_files" : [ + "src/src_user/tlm_cmd/telemetry_definitions.c" + ], + "ignore_rules" : [ + ], + "comment_ignore_rules" : [ + "以下を指定すると,該当ルールが無視される", + "comment", + "newline", + "eof", + "space", + "operator_space", + "preprocessor", + "include_guard" + ], + "additional_type" : [ + "TCP", + "CommonTlmCmdPacket", + "CommonTlmPacket", + "CommonCmdPacket", + "SpacePacket", + "TlmSpacePacket", + "CmdSpacePacket" + ], + "comment_additional_type" : [ + "FIXME: TCP はもう存在しないはずなので,どこかで消す", + "FIXME: CTCP, CTP, CCP については,整理が終わり次第,消して大丈夫になるはず" + ] +} From ce599384f44f919b777e3bb8d48a5d0883434dce Mon Sep 17 00:00:00 2001 From: sksat Date: Thu, 21 Sep 2023 14:40:42 +0900 Subject: [PATCH 3/9] add check-coding-rule migration guide to CHANGELOG --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d8bfdb8..3b6e99fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,11 @@ - example user についてはこの migration script のみで移行しているが,あらゆる C2A user の状況について考慮できているわけではないため,適宜対応が必要 - `hal`(旧 `IfWrapper`)のうち,古すぎるインターフェースを排除: [#23](https://github.com/arkedge/c2a-core/issues/23), [#25](https://github.com/arkedge/c2a-core/pull/25) - 既に使われてしまっているものについては,各 C2A user で一旦雑に古いヘッダファイルを各々で持って対応可能(今後再設計する予定) +- `check_coding_rule.py` の設定ファイルである `check_coding_rule.json` の場所を C2A user のトップディレクトリに変更: [#97](https://github.com/arkedge/c2a-core/pull/97) + - 対応方法 + - `Script/CI/check_coding_rule.json` ないし `script/ci/check_coding_rule.json` を C2A user のトップディレクトリに移動 + - 設定ファイルから `c2a_root_dir` を削除 + - 設定ファイル中のディレクトリの設定を C2A user のトップディレクトリからの相対パスに変更 ### Enhancements From 1eba5c660fad18f626480373d2245ed35798bc2d Mon Sep 17 00:00:00 2001 From: sksat Date: Thu, 21 Sep 2023 16:09:26 +0900 Subject: [PATCH 4/9] fix empty dirname bug --- script/ci/check_coding_rule.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/script/ci/check_coding_rule.py b/script/ci/check_coding_rule.py index 1809fae2..e1524db2 100644 --- a/script/ci/check_coding_rule.py +++ b/script/ci/check_coding_rule.py @@ -59,7 +59,10 @@ def main(): print("WARNING: " + rule_name + " rule is ignored!!") settings["check_funcs"] = check_funcs # ここだけ, settings に追記している - check_root_dir = os.path.dirname(setting_file_path) + r"/" + dname = os.path.dirname(setting_file_path) + if not dname: + dname = os.getcwd() + check_root_dir = dname + r"/" if not check_coding_rule(check_root_dir, settings): print("The above files are invalid coding rule.") From 24301d4d39751091c0ab133c090a10ae2c645a7f Mon Sep 17 00:00:00 2001 From: sksat Date: Thu, 21 Sep 2023 16:37:28 +0900 Subject: [PATCH 5/9] check coding rule by arkedge/workflows-c2a add-v4-check-coding-rule-workflow branch --- .github/workflows/check_coding_rule.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/workflows/check_coding_rule.yml b/.github/workflows/check_coding_rule.yml index 83a314e9..9669b0ed 100644 --- a/.github/workflows/check_coding_rule.yml +++ b/.github/workflows/check_coding_rule.yml @@ -8,6 +8,21 @@ on: pull_request: jobs: + check_coding_rule_v4: + strategy: + fail-fast: false + matrix: + user: + - mobc + - subobc + uses: arkedge/workflows-c2a/.github/workflows/check-coding-rule-v4.yml@add-v4-check-coding-rule-workflow + with: + c2a_dir: examples/${{ matrix.user }} + c2a_custom_setup: | + cd ../.. + pwd + ./setup.sh + check_coding_rule: runs-on: ubuntu-latest strategy: From 9422dbab016a920c0ec7efd56defb88bc6af50ef Mon Sep 17 00:00:00 2001 From: sksat Date: Thu, 21 Sep 2023 19:57:32 +0900 Subject: [PATCH 6/9] test check coding rule CI --- examples/mobc/src/src_user/c2a_main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/mobc/src/src_user/c2a_main.c b/examples/mobc/src/src_user/c2a_main.c index 17909bcf..020b1e19 100644 --- a/examples/mobc/src/src_user/c2a_main.c +++ b/examples/mobc/src/src_user/c2a_main.c @@ -9,6 +9,7 @@ #ifdef DEFINE_MAIN_ON_SILS int main(void); #endif + static void address_fixed_main_(void); static void C2A_init_(void); From e0de303922c2f341ed08d9a1eb9fc5b3a02287f8 Mon Sep 17 00:00:00 2001 From: sksat Date: Thu, 21 Sep 2023 19:58:49 +0900 Subject: [PATCH 7/9] Revert "test check coding rule CI" This reverts commit 9422dbab016a920c0ec7efd56defb88bc6af50ef. --- examples/mobc/src/src_user/c2a_main.c | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/mobc/src/src_user/c2a_main.c b/examples/mobc/src/src_user/c2a_main.c index 020b1e19..17909bcf 100644 --- a/examples/mobc/src/src_user/c2a_main.c +++ b/examples/mobc/src/src_user/c2a_main.c @@ -9,7 +9,6 @@ #ifdef DEFINE_MAIN_ON_SILS int main(void); #endif - static void address_fixed_main_(void); static void C2A_init_(void); From 9682cf9b4560631887932b49a0964bc5eb635fb5 Mon Sep 17 00:00:00 2001 From: sksat Date: Thu, 21 Sep 2023 22:40:12 +0900 Subject: [PATCH 8/9] use workflows-c2a v4 workflow to check coding rule --- .github/workflows/check_coding_rule.yml | 61 ------------------------- 1 file changed, 61 deletions(-) diff --git a/.github/workflows/check_coding_rule.yml b/.github/workflows/check_coding_rule.yml index 9669b0ed..763df9f4 100644 --- a/.github/workflows/check_coding_rule.yml +++ b/.github/workflows/check_coding_rule.yml @@ -22,64 +22,3 @@ jobs: cd ../.. pwd ./setup.sh - - check_coding_rule: - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - example: - - mobc - - subobc - - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 - with: - python-version-file: .github/workflows/.python-version - architecture: 'x64' - - name: setup - shell: bash - run: ./setup.sh - - name: check coding rule - id: check - shell: bash -e {0} - continue-on-error: true - working-directory: ./examples/${{ matrix.example }}/src - run: | - python ./src_core/script/ci/check_coding_rule.py ./src_core/script/ci/check_coding_rule.json | tee /tmp/coding-rule.log - status="${PIPESTATUS[0]}" - echo "status: ${status}" - echo "status=${status}" >> "$GITHUB_OUTPUT" - exit "${status}" - - - name: install reviewdog - uses: reviewdog/action-setup@v1.0.6 - - - name: fix error log source file path - run: | - sed 's/.\/src_core\///g' < /tmp/coding-rule.log \ - | > ./coding-rule.log \ - sed 's/.\/src_user/examples\/${{ matrix.example }}\/src\/src_user/g' - cat ./coding-rule.log - - - name: reviewdog(github-pr-review) - env: - REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - reviewdog \ - -name 'check_coding_rule' \ - -level error \ - -fail-on-error=true \ - -filter-mode=added \ - -diff="git diff FETCH_HEAD" \ - -reporter=github-pr-review \ - -efm="%-GThe above files are invalid coding rule." \ - -efm="%E%f: %l: %m" \ - -efm="%Z%s" \ - < coding-rule.log - - - name: exit - shell: bash - run: | - exit $(( "${{ steps.check.outputs.status }}" )) From 7d59b7c52afe4fcf4a973b89f6b468636e81b4d8 Mon Sep 17 00:00:00 2001 From: sksat Date: Thu, 21 Sep 2023 22:47:32 +0900 Subject: [PATCH 9/9] use released version workflows-c2a for check coding rule(v4) --- .github/workflows/check_coding_rule.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check_coding_rule.yml b/.github/workflows/check_coding_rule.yml index 763df9f4..52b73f0f 100644 --- a/.github/workflows/check_coding_rule.yml +++ b/.github/workflows/check_coding_rule.yml @@ -15,7 +15,7 @@ jobs: user: - mobc - subobc - uses: arkedge/workflows-c2a/.github/workflows/check-coding-rule-v4.yml@add-v4-check-coding-rule-workflow + uses: arkedge/workflows-c2a/.github/workflows/check-coding-rule-v4.yml@v4.3.0 with: c2a_dir: examples/${{ matrix.user }} c2a_custom_setup: |