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 all 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
4 changes: 2 additions & 2 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ jobs:
uses: dtolnay/rust-toolchain@stable
with:
target: x86_64-unknown-none
- name: Cargo check
- name: Code checks
run:
cd charlotte_core && cargo check --target x86_64-unknown-none
python3 ./codecheck.py
40 changes: 24 additions & 16 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 @@ -43,19 +49,6 @@ def check_code():
stderr=subprocess.PIPE,
stdout=subprocess.PIPE,
)
subprocess.run(
[
"cargo",
"doc",
"--target",
target,
"--manifest-path",
"charlotte_core/Cargo.toml",
],
check=True,
stderr=subprocess.PIPE,
stdout=subprocess.PIPE,
)
except subprocess.CalledProcessError:
target_result = "Failed"
else:
Expand All @@ -74,6 +67,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()