Skip to content

Commit

Permalink
Update x.py to run fmt/clippy in all workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
fpoli committed Sep 27, 2023
1 parent f06d119 commit dd13d6c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
shared-key: "shared"
- name: Check and report Clippy errors
run: |
python ./x.py clippy -- -D warnings
python ./x.py clippy-all
# Detect missing dependencies in workspace packages
# See: https://stackoverflow.com/a/74293494/2491528
Expand Down
1 change: 1 addition & 0 deletions jni-gen/systest/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[rustfmt::skip]
#[path = "../gen/mod.rs"]
pub mod wrappers;

Expand Down
107 changes: 32 additions & 75 deletions x.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,48 +34,9 @@

dry_run = False

RUSTFMT_CRATES = [
'analysis',
'jni-gen',
'prusti',
'prusti-common',
'prusti-contracts/prusti-contracts',
'prusti-contracts/prusti-contracts-proc-macros',
'prusti-contracts/prusti-specs',
'prusti-contracts/prusti-std',
'prusti-contracts-build',
'prusti-interface',
'prusti-launch',
'prusti-rustc-interface',
'prusti-server',
'prusti-smt-solver',
'prusti-tests',
'prusti-utils',
#'prusti-viper',
'smt-log-analyzer',
#'test-crates',
'viper',
'viper-sys',
'vir',
'vir-gen',
]

RUSTFMT_PATHS = [
'prusti-common/src/report/mod.rs',
'prusti-common/src/utils/mod.rs',
'prusti-common/src/vir/to_viper.rs',
'prusti-common/src/vir/low_to_viper/mod.rs',
'prusti-common/src/vir/optimizations/mod.rs',
'prusti-viper/src/encoder/foldunfold/mod.rs',
'prusti-viper/src/encoder/mir/mod.rs',
'prusti-viper/src/encoder/high/mod.rs',
'prusti-viper/src/encoder/typed/mod.rs',
'prusti-viper/src/encoder/middle/mod.rs',
'prusti-viper/src/encoder/snapshot/mod.rs',
'prusti-viper/src/encoder/lifetimes/mod.rs',
'prusti-viper/src/encoder/definition_collector.rs',
'prusti-viper/src/encoder/counterexamples/mod.rs',
'vir/defs/mod.rs',
PRUSTI_WORKSPACES = [
'.',
'prusti-contracts',
]


Expand Down Expand Up @@ -208,33 +169,23 @@ def run_viper_server(port=None):
run_command(command)


def clippy_in(cwd):
"""Run cargo clippy in given subproject."""
run_command(['cargo', 'clippy', '--', '-D', 'warnings'], cwd=cwd)
def clippy_all():
"""Run clippy in all workspaces."""
for workspace_path in PRUSTI_WORKSPACES:
run_command(['cargo', 'clippy', '--', '-D', 'warnings'], cwd=workspace_path)

def fmt_in(cwd):
"""Run cargo fmt in given subproject."""
run_command(['cargo', 'fmt'], cwd=cwd)

def fmt_all():
"""Run rustfmt on all formatted files."""
for crate in RUSTFMT_CRATES:
fmt_in(crate)
for path in RUSTFMT_PATHS:
for file in glob.glob(path, recursive=True):
run_command(['rustfmt', file])
"""Run rustfmt in all workspaces."""
for workspace_path in PRUSTI_WORKSPACES:
run_command(['cargo', 'fmt', '--all'], cwd=workspace_path)

def fmt_check_in(cwd):
"""Run cargo fmt check in the given subproject."""
run_command(['cargo', 'fmt', '--', '--check'], cwd=cwd)

def fmt_check_all():
"""Run rustfmt check on all formatted files."""
for crate in RUSTFMT_CRATES:
fmt_check_in(crate)
for path in RUSTFMT_PATHS:
for file in glob.glob(path, recursive=True):
run_command(['rustfmt', '--check', file])
"""Run rustfmt check in all workspaces."""
for workspace_path in PRUSTI_WORKSPACES:
run_command(['cargo', 'fmt', '--all', '--', '--check'], cwd=workspace_path)


def check_smir():
"""Check that `extern crate` is used only in `prusti_rustc_interface` (TODO: `prusti_interface` is also ignored for now)."""
Expand All @@ -258,6 +209,7 @@ def check_smir():
)
)


def package(mode: str, package_path: str):
"""Packages Prusti artifacts in the `package_path` folder.
Expand Down Expand Up @@ -359,6 +311,11 @@ def test_package(package_path: str):

def main(argv):
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)

# Check the working directory, because this script uses a lot of relative paths.
if os.path.abspath(os.getcwd()) != os.path.abspath(os.path.dirname(__file__)):
error(f'Please run this script from the root folder of the repository.')

for i, arg in enumerate(argv):
if arg.startswith('+'):
if arg == '+v' or arg == '++verbose':
Expand All @@ -385,30 +342,30 @@ def main(argv):
elif arg == 'exec':
run_command(argv[i+1:])
break
elif arg == 'clippy-in':
clippy_in(*argv[i+1:])
break
elif arg == 'fmt-check':
fmt_check_in(*argv[i+1:])
# Run `cargo clippy --all` in all workspaces.
elif arg == 'clippy-all':
clippy_all()
break
# Check `cargo fmt --all` in all workspaces.
elif arg == 'fmt-check-all':
fmt_check_all(*argv[i+1:])
break
elif arg == 'fmt':
fmt_in(*argv[i+1:])
break
elif arg == 'fmt-all':
fmt_all(*argv[i+1:])
fmt_check_all()
break
elif arg == 'check-smir':
check_smir(*argv[i+1:])
break
# Run `cargo fmt --all` in all workspaces.
elif arg == 'fmt-all':
fmt_all()
break
# Packages Prusti artifacts in the given folder.
elif arg == 'package':
package(*argv[i+1:])
break
# Quickly test that a Prusti release has been packaged correctly in the given folder.
elif arg == 'test-package':
test_package(*argv[i+1:])
break
# Run whatever is left as a cargo command.
else:
cargo(argv[i:])
break
Expand Down

0 comments on commit dd13d6c

Please sign in to comment.