diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 88584f9..9754813 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -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 \ No newline at end of file + python3 ./codecheck.py diff --git a/codecheck.py b/codecheck.py index cda375a..e54a9ec 100755 --- a/codecheck.py +++ b/codecheck.py @@ -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 = {} @@ -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}") @@ -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: @@ -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()