Skip to content

Commit

Permalink
Replace all Perl scripts with Rust
Browse files Browse the repository at this point in the history
  • Loading branch information
autarch committed Dec 15, 2024
1 parent 088d375 commit 70a59eb
Show file tree
Hide file tree
Showing 12 changed files with 608 additions and 5,162 deletions.
51 changes: 28 additions & 23 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ jobs:
cache-cross-binary: true
expect_file_re: "x86-64.+FreeBSD"
expect_cross: "--expect-cross"
expect_stripped: "--no-expect-stripped"
expect_stripped: ""
can_execute: false

- platform_name: Linux-x86_64
os: ubuntu-22.04
target: x86_64-unknown-linux-musl
cache-cross-binary: true
expect_file_re: "ELF.+x86-64"
expect_cross: "--no-expect-cross"
expect_cross: ""
expect_stripped: "--expect-stripped"
can_execute: true

Expand All @@ -35,7 +35,7 @@ jobs:
cache-cross-binary: true
expect_file_re: "aarch64"
expect_cross: "--expect-cross"
expect_stripped: "--no-expect-stripped"
expect_stripped: ""
can_execute: true

- platform_name: Linux-aarch64 (no cache)
Expand All @@ -44,7 +44,7 @@ jobs:
cache-cross-binary: false
expect_file_re: "aarch64"
expect_cross: "--expect-cross"
expect_stripped: "--no-expect-stripped"
expect_stripped: ""
can_execute: true

- platform_name: Linux-aarch64 with cross v0.2.3
Expand All @@ -55,7 +55,7 @@ jobs:
expect_file_re: "aarch64"
expect_cross: "--expect-cross"
expect_cross_version: "0.2.3"
expect_stripped: "--no-expect-stripped"
expect_stripped: ""
can_execute: true

- platform_name: Linux-aarch64 with cross v0.2.3 (no cache)
Expand All @@ -66,7 +66,7 @@ jobs:
expect_file_re: "aarch64"
expect_cross: "--expect-cross"
expect_cross_version: "0.2.3"
expect_stripped: "--no-expect-stripped"
expect_stripped: ""
can_execute: true

- platform_name: Linux-aarch64 with cross 19be834
Expand All @@ -77,7 +77,7 @@ jobs:
expect_file_re: "aarch64"
expect_cross: "--expect-cross"
expect_cross_version: "19be834"
expect_stripped: "--no-expect-stripped"
expect_stripped: ""
can_execute: true

- platform_name: Linux-aarch64 with cross 19be834
Expand All @@ -88,7 +88,7 @@ jobs:
expect_file_re: "aarch64"
expect_cross: "--expect-cross"
expect_cross_version: "19be834"
expect_stripped: "--no-expect-stripped"
expect_stripped: ""
can_execute: true

- platform_name: Linux-arm
Expand All @@ -97,7 +97,7 @@ jobs:
cache-cross-binary: true
expect_file_re: "32.+ARM"
expect_cross: "--expect-cross"
expect_stripped: "--no-expect-stripped"
expect_stripped: ""
can_execute: true

- platform_name: Linux-i586
Expand All @@ -106,7 +106,7 @@ jobs:
cache-cross-binary: true
expect_file_re: "ELF.+80386"
expect_cross: "--expect-cross"
expect_stripped: "--no-expect-stripped"
expect_stripped: ""
can_execute: true

- platform_name: Linux-i686
Expand All @@ -115,7 +115,7 @@ jobs:
cache-cross-binary: true
expect_file_re: "ELF.+80386"
expect_cross: "--expect-cross"
expect_stripped: "--no-expect-stripped"
expect_stripped: ""
can_execute: true

- platform_name: Linux-powerpc
Expand All @@ -124,7 +124,7 @@ jobs:
cache-cross-binary: true
expect_file_re: "32.+PowerPC"
expect_cross: "--expect-cross"
expect_stripped: "--no-expect-stripped"
expect_stripped: ""
can_execute: true

- platform_name: Linux-powerpc64
Expand All @@ -133,7 +133,7 @@ jobs:
cache-cross-binary: true
expect_file_re: "64.+PowerPC"
expect_cross: "--expect-cross"
expect_stripped: "--no-expect-stripped"
expect_stripped: ""
can_execute: true

- platform_name: Linux-powerpc64le
Expand All @@ -142,7 +142,7 @@ jobs:
cache-cross-binary: true
expect_file_re: "64.+PowerPC"
expect_cross: "--expect-cross"
expect_stripped: "--no-expect-stripped"
expect_stripped: ""
can_execute: true

- platform_name: Linux-riscv64
Expand All @@ -151,7 +151,7 @@ jobs:
cache-cross-binary: true
expect_file_re: "64.+RISC-V"
expect_cross: "--expect-cross"
expect_stripped: "--no-expect-stripped"
expect_stripped: ""
can_execute: true

- platform_name: Linux-s390x
Expand All @@ -160,7 +160,7 @@ jobs:
cache-cross-binary: true
expect_file_re: "64.+S/390"
expect_cross: "--expect-cross"
expect_stripped: "--no-expect-stripped"
expect_stripped: ""
can_execute: true

- platform_name: NetBSD-x86_64
Expand All @@ -169,24 +169,24 @@ jobs:
cache-cross-binary: true
expect_file_re: "x86-64.+NetBSD"
expect_cross: "--expect-cross"
expect_stripped: "--no-expect-stripped"
expect_stripped: ""
can_execute: false

- platform_name: Windows-aarch64
os: windows-latest
target: aarch64-pc-windows-msvc
cache-cross-binary: true
expect_file_re: "Aarch64.+Windows"
expect_cross: "--no-expect-cross"
expect_stripped: "--no-expect-stripped"
expect_cross: ""
expect_stripped: ""
can_execute: false

- platform_name: Windows-i686
os: windows-latest
target: i686-pc-windows-msvc
cache-cross-binary: true
expect_file_re: "80386.+Windows"
expect_cross: "--no-expect-cross"
expect_cross: ""
expect_stripped: "--expect-stripped"
can_execute: true

Expand All @@ -203,7 +203,7 @@ jobs:
target: x86_64-apple-darwin
cache-cross-binary: true
expect_file_re: "Mach-O.+x86_64"
expect_cross: "--no-expect-cross"
expect_cross: ""
expect_stripped: "--expect-stripped"
can_execute: true

Expand All @@ -212,7 +212,7 @@ jobs:
target: aarch64-apple-darwin
cache-cross-binary: true
expect_file_re: "Mach-O.+arm64"
expect_cross: "--no-expect-cross"
expect_cross: ""
expect_stripped: "--expect-stripped"
can_execute: false

Expand Down Expand Up @@ -285,7 +285,12 @@ jobs:
- name: Check binary and cross on ${{ matrix.platform.platform_name }}
shell: bash
run: |
tests/check-binary.pl \
set -e
set -x
export pwd="$PWD"
cd run-tests
cargo run -- \
--checkout-root "$pwd" \
--target "${{ matrix.platform.target }}" \
--expect-file-re "${{ matrix.platform.expect_file_re }}" \
--expect-cross-version "${{ matrix.platform.expect_cross_version }}" \
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
/package.json
.\#*
\#*\#
run-tests/**/target/**
test-project/**/target/**
52 changes: 52 additions & 0 deletions git/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env python3

# This code was mostly written by Claude.ai.

import os
import sys


def main() -> None:
"""
Main entry point to create a pre-commit hook symlink.
"""
symlink_hook("pre-commit")


def symlink_hook(hook: str) -> None:
"""
Create a symlink for a Git hook if it doesn't already exist.
Args:
hook: Name of the Git hook (e.g., 'pre-commit')
"""
# Path to the hook in .git/hooks
dot_hook_path = os.path.join(".git", "hooks", hook)

# Path to the actual hook script
file_hook_path = os.path.join("git", "hooks", f"{hook}.sh")

# Relative symlink path
link_path = os.path.join("..", "..", file_hook_path)

# Check if the hook already exists
if os.path.exists(dot_hook_path):
# If it's already a symlink, check if it points to the correct location
if os.path.islink(dot_hook_path):
# If the existing symlink is correct, do nothing
if os.readlink(dot_hook_path) == link_path:
return

# If a hook exists and is not the expected symlink, warn and exit
print(f"You already have a hook at {dot_hook_path}!", file=sys.stderr)
return

# Create the symlink
try:
os.symlink(link_path, dot_hook_path)
except OSError as e:
print(f"Error creating symlink: {e}", file=sys.stderr)


if __name__ == "__main__":
main()
85 changes: 56 additions & 29 deletions precious.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,62 @@ exclude = [
"tests/lib/**/*",
]

[commands.clippy]
type = "lint"
include = "**/*.rs"
invoke = "once"
path-args = "none"
working-dir.chdir-to = "run-tests"
cmd = [
"cargo",
"clippy",
"--color",
"always",
"--locked",
"--all-targets",
"--all-features",
"--",
"-D",
"clippy::pedantic",
]
ok_exit_codes = 0
lint_failure_exit_codes = 101
expect_stderr = true
labels = ["default"]

[commands."clippy --fix"]
type = "tidy"
include = "**/*.rs"
invoke = "once"
path-args = "none"
working-dir.chdir-to = "run-tests"
cmd = [
"cargo",
"clippy",
"--fix",
"--allow-dirty",
"--locked",
"--all-targets",
"--all-features",
"--",
"-D",
"clippy::pedantic",
]
ok_exit_codes = 0
lint_failure_exit_codes = 101
expect_stderr = true
labels = ["default"]

[commands.rustfmt]
type = "both"
include = "**/*.rs"
working-dir.chdir-to = "run-tests"
cmd = ["rustfmt", "--edition", "2021"]
lint_flags = "--check"
ok_exit_codes = [0]
lint_failure_exit_codes = [1]
labels = ["default", "fast-tidy"]

[commands.typos]
type = "both"
include = "**/*"
Expand All @@ -13,35 +69,6 @@ tidy_flags = "--write-changes"
ok-exit-codes = 0
lint-failure-exit-codes = 2

[commands.perltidy]
type = "both"
include = [ "**/*.{pl,pm,t,psgi}" ]
exclude = "tests/lib/**"
cmd = [ "perltidy", "--profile=$PRECIOUS_ROOT/perltidyrc" ]
lint_flags = [ "--assert-tidy", "--no-standard-output", "--outfile=/dev/null" ]
tidy_flags = [ "--backup-and-modify-in-place", "--backup-file-extension=/" ]
ok_exit_codes = 0
lint_failure_exit_codes = 2
ignore_stderr = "Begin Error Output Stream"

[commands."ruff for linting"]
type = "both"
include = [ "**/*.py" ]
cmd = "ruff"
lint_flags = [ "check" ]
tidy_flags = [ "check", "--fix" ]
ok_exit_codes = 0
lint_failure_exit_codes = 1

[commands."ruff for tidying"]
type = "both"
include = [ "**/*.py" ]
cmd = "ruff"
lint_flags = [ "format", "--check" ]
tidy_flags = [ "format" ]
ok_exit_codes = 0
lint_failure_exit_codes = 1

[commands.prettier-md]
type = "both"
include = [ "**/*.md" ]
Expand Down
Loading

0 comments on commit 70a59eb

Please sign in to comment.