Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

Improve codecheck.py to only look for the src folder of the project and use it on the CI #49

Merged
merged 6 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ jobs:
target: x86_64-unknown-none
- name: Cargo check
run:
cd charlotte_core && cargo check --target x86_64-unknown-none
python3 ./codecheck.py
29 changes: 25 additions & 4 deletions codecheck.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Code sanity checker for charlotte_core"""

import os
import sys
import subprocess
import sys

# When adding a new target, add the target to the TARGETS list
TARGETS = ["x86_64-unknown-none", "aarch64-unknown-none", "riscv64gc-unknown-none-elf"]
# a target set as "core" will cause the script to raise an error if the target fails
TARGETS = {
"x86_64-unknown-none": "core",
"aarch64-unknown-none": "secondary",
"riscv64gc-unknown-none-elf": "secondary",
}
TARGET_RESULTS = {}


Expand All @@ -24,7 +30,7 @@ def run_grep(lookup, filename) -> str:

def check_code():
"""Check the project"""
grep_res = run_grep("allow(unused)", "./charlotte_core")
grep_res = run_grep("allow(unused)", "./charlotte_core/src")

for target in TARGETS:
print(f"Checking target: {target}")
Expand All @@ -46,7 +52,7 @@ def check_code():
subprocess.run(
[
"cargo",
"doc",
"build",
"--target",
target,
"--manifest-path",
Expand Down Expand Up @@ -74,6 +80,21 @@ def check_code():
for target, result in TARGET_RESULTS.items():
print(f"{target}: {result}")

if "Failed" in TARGET_RESULTS.values():
for target, result in TARGET_RESULTS.items():
if result == "Failed" and TARGETS[target] == "core":
print(
f"Core target {target} failed to build, please fix the build errors before opening a PR"
)
sys.exit(1)
print(
"WARN: Some non core target failed to build"
)
sys.exit(0)

print("All checks passed!")
sys.exit(0)


if __name__ == "__main__":
check_code()