Skip to content

Commit

Permalink
[chore] replace local format check with CI format check
Browse files Browse the repository at this point in the history
Signed-off-by: Avimitin <[email protected]>
  • Loading branch information
Avimitin committed Oct 21, 2024
1 parent 12f0855 commit 5bcfa4e
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 50 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Code format check
on:
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
- labeled

# Cancel the current workflow when new commit pushed
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true

jobs:
check-format:
if: '! github.event.pull_request.draft'
name: "Check code format"
runs-on: [self-hosted, linux, nixos]
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: "Check Scala code format"
run: nix run ".#t1.elaborator.format" check
- name: "Check difftest code format"
run: |
nix shell '.#cargo' '.#rustfmt' -c bash -c 'cd difftest && cargo fmt --check'
12 changes: 0 additions & 12 deletions difftest/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{ lib
, rustPlatform
, rustfmt
, libspike
, libspike_interfaces
, rtlDesignMetadata
Expand Down Expand Up @@ -36,17 +35,6 @@ rustPlatform.buildRustPackage {
];
};

nativeBuildInputs = [
rustfmt
];

postConfigure = ''
if ! cargo fmt --check; then
echo "Please run 'cd difftest && cargo fmt' before building emulator!" >&2
exit 1
fi
'';

buildFeatures = [ ] ++ lib.optionals (lib.hasPrefix "dpi" moduleType) [ "dpi_common/${emuType}" ] ++ lib.optionals enableTrace [ "dpi_common/trace" ];
buildAndTestSubdir = "./${moduleType}";

Expand Down
86 changes: 48 additions & 38 deletions nix/t1/mill-modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
, circt-full
, jextract-21
, add-determinism
, writeShellApplication

, dependencies
}:
Expand Down Expand Up @@ -80,47 +81,10 @@ let
CIRCT_INSTALL_PATH = circt-full;
JEXTRACT_INSTALL_PATH = jextract-21;
JAVA_TOOL_OPTIONS = "--enable-preview";
formatHook = ''
targets=( $(mill -i resolve _.reformat) )
localTargets=()
for t in ''${targets[@]}; do
if ! mill -i show "''${t//reformat/sources}" | grep -q dependencies; then
localTargets+=($t)
fi
done
for t in ''${localTargets[@]}; do
mill -i "$t"
done
'';
};

outputs = [ "out" "omreader" "elaborator" "t1package" ];

# Check code format before starting build, so that we can enforce all developer run reformat before build.
configurePhase = ''
runHook preConfigure
_targetsToCheck=(
"elaborator"
"omreader"
"omreaderlib"
"rocketemu"
"rocketv"
"t1"
"t1emu"
"t1rocket"
"t1rocketemu"
)
for _t in ''${_targetsToCheck[@]}; do
if ! mill -i "$_t".checkFormat; then
echo "[ERROR] Please run 'mill -i $_t.reformat' before elaborate!" >&2
exit 1
fi
done
unset _targetsToCheck
runHook postConfigure
'';
outputs = [ "out" "omreader" "elaborator" "t1package" ];

buildPhase = ''
runHook preBuild
Expand Down Expand Up @@ -165,6 +129,52 @@ let
--add-flags "-Djava.library.path=${circt-full}/lib" \
--add-flags "-cp $out/share/java/omreader.jar"
'';

passthru.format = writeShellApplication {
name = "mill-format-for-t1";
runtimeInputs = [ mill ];
text = ''
# shellcheck disable=SC1091
source ${dependencies.setupHook}/nix-support/setup-hook
setupSubmodules
subcmd="''${1:-}"
[[ -z "$subcmd" ]] && \
echo "no subcmd specify, available: (check, run)" >&2 && exit 1
_targetsToCheck=(
"elaborator"
"omreader"
"omreaderlib"
"rocketemu"
"rocketv"
"t1"
"t1emu"
"t1rocket"
"t1rocketemu"
)
case "$subcmd" in
check)
for _t in "''${_targetsToCheck[@]}"; do
if ! mill -i "$_t".checkFormat; then
echo "[ERROR] Please run 'mill -i $_t.reformat' before elaborate!" >&2
exit 1
fi
done
;;
run)
for _t in "''${_targetsToCheck[@]}"; do
mill -i "$_t".reformat || true
done
;;
*)
echo "Invalid subcmd $subcmd, available: (check, run)" >&2
exit 1
;;
esac
'';
};
};
in
self

0 comments on commit 5bcfa4e

Please sign in to comment.