summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/util
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/tools/clippy/util
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rwxr-xr-xsrc/tools/clippy/util/etc/pre-commit.sh22
-rw-r--r--src/tools/clippy/util/etc/vscode-tasks.json57
-rwxr-xr-xsrc/tools/clippy/util/fetch_prs_between.sh27
-rwxr-xr-xsrc/tools/clippy/util/versions.py44
4 files changed, 150 insertions, 0 deletions
diff --git a/src/tools/clippy/util/etc/pre-commit.sh b/src/tools/clippy/util/etc/pre-commit.sh
new file mode 100755
index 000000000..5dd2ba3d5
--- /dev/null
+++ b/src/tools/clippy/util/etc/pre-commit.sh
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+# hide output
+set -e
+
+# Update lints
+cargo dev update_lints
+git add clippy_lints/src/lib.rs
+git add clippy_lints/src/lib.*.rs
+
+# Formatting:
+# Git will not automatically add the formatted code to the staged changes once
+# fmt was executed. This collects all staged files rs files that are currently staged.
+# They will later be added back.
+#
+# This was proudly stolen and adjusted from here:
+# https://medium.com/@harshitbangar/automatic-code-formatting-with-git-66c3c5c26798
+files=$( (git diff --cached --name-only --diff-filter=ACMR | grep -Ei "\.rs$") || true)
+if [ ! -z "${files}" ]; then
+ cargo dev fmt
+ git add $(echo "$files" | paste -s -d " " -)
+fi
diff --git a/src/tools/clippy/util/etc/vscode-tasks.json b/src/tools/clippy/util/etc/vscode-tasks.json
new file mode 100644
index 000000000..ab98f9b41
--- /dev/null
+++ b/src/tools/clippy/util/etc/vscode-tasks.json
@@ -0,0 +1,57 @@
+{
+ "version": "2.0.0",
+ "tasks": [
+ {
+ "label": "cargo check",
+ "type": "shell",
+ "command": "cargo check",
+ "problemMatcher": [],
+ "group": {
+ "kind": "build",
+ "isDefault": true
+ }
+ },
+ {
+ "label": "cargo dev fmt",
+ "type": "shell",
+ "command": "cargo dev fmt",
+ "problemMatcher": [],
+ "group": "none"
+ },
+ {
+ "label": "cargo uitest",
+ "type": "shell",
+ "command": "cargo uitest",
+ "options": {
+ "env": {
+ // This task will usually execute all UI tests inside `tests/ui` you can
+ // optionally uncomment the line below and only run a specific test.
+ //
+ // See: https://github.com/rust-lang/rust-clippy/blob/master/book/src/development/adding_lints.md#testing
+ //
+ // "TESTNAME": "<TODO>",
+ "RUST_BACKTRACE": "1"
+ }
+ },
+ "problemMatcher": [],
+ "group": {
+ "kind": "test",
+ "isDefault": true
+ }
+ },
+ {
+ "label": "cargo test",
+ "type": "shell",
+ "command": "cargo test",
+ "problemMatcher": [],
+ "group": "test"
+ },
+ {
+ "label": "cargo dev bless",
+ "type": "shell",
+ "command": "cargo dev bless",
+ "problemMatcher": [],
+ "group": "none"
+ }
+ ]
+}
diff --git a/src/tools/clippy/util/fetch_prs_between.sh b/src/tools/clippy/util/fetch_prs_between.sh
new file mode 100755
index 000000000..6865abf97
--- /dev/null
+++ b/src/tools/clippy/util/fetch_prs_between.sh
@@ -0,0 +1,27 @@
+#!/bin/bash
+
+# Fetches the merge commits between two git commits and prints the PR URL
+# together with the full commit message
+#
+# If you want to use this to update the Clippy changelog, be sure to manually
+# exclude the non-user facing changes like 'rustup' PRs, typo fixes, etc.
+
+first=$1
+last=$2
+
+IFS='
+'
+for pr in $(git log --oneline --grep "Merge #" --grep "Merge pull request" --grep "Auto merge of" --grep "Rollup merge of" "$first...$last" | sort -rn | uniq); do
+ id=$(echo "$pr" | rg -o '#[0-9]{3,5}' | cut -c 2-)
+ commit=$(echo "$pr" | cut -d' ' -f 1)
+ message=$(git --no-pager show --pretty=medium "$commit")
+ if [[ -n $(echo "$message" | rg "^[\s]{4}changelog: [nN]one\.*$") ]]; then
+ continue
+ fi
+
+ echo "URL: https://github.com/rust-lang/rust-clippy/pull/$id"
+ echo "Markdown URL: [#$id](https://github.com/rust-lang/rust-clippy/pull/$id)"
+ echo "$message"
+ echo "---------------------------------------------------------"
+ echo
+done
diff --git a/src/tools/clippy/util/versions.py b/src/tools/clippy/util/versions.py
new file mode 100755
index 000000000..0cfa007d1
--- /dev/null
+++ b/src/tools/clippy/util/versions.py
@@ -0,0 +1,44 @@
+#!/usr/bin/env python
+
+import json
+import os
+import sys
+import logging as log
+log.basicConfig(level=log.INFO, format='%(levelname)s: %(message)s')
+
+
+def key(v):
+ if v == 'master':
+ return float('inf')
+ if v == 'stable':
+ return sys.maxsize
+ if v == 'beta':
+ return sys.maxsize - 1
+
+ v = v.replace('v', '').replace('rust-', '')
+
+ s = 0
+ for i, val in enumerate(v.split('.')[::-1]):
+ s += int(val) * 100**i
+
+ return s
+
+
+def main():
+ if len(sys.argv) < 2:
+ log.error("specify output directory")
+ return
+
+ outdir = sys.argv[1]
+ versions = [
+ dir for dir in os.listdir(outdir) if not dir.startswith(".") and os.path.isdir(os.path.join(outdir, dir))
+ ]
+ versions.sort(key=key)
+
+ with open(os.path.join(outdir, "versions.json"), "w") as fp:
+ json.dump(versions, fp, indent=2)
+ log.info("wrote JSON for great justice")
+
+
+if __name__ == "__main__":
+ main()