Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Replace GNU-specific commands with more portable alternatives #682

Merged
merged 4 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,9 @@ expected output files to include the new items, and you can get back on track.
## Development Environment

While cargo-semver-checks is cross platform, the development task automation scripts in the scripts
directory are not. In particular, they require
directory are not. In particular, a relatively modern `bash` (at least version 4.0) is required.

- GNU command line tools (coreutils, grep, sed, etc.)
- a relatively modern `bash` (at least version 4.0)
- `curl`
- [`jq`](https://jqlang.github.io/jq/)

Linux users likely have all of these already installed or available via their package manager.
Linux users likely have bash 5+ already installed or available via their package manager.
Windows users can get a bash + GNU command line environment via WSL or git bash.
Mac users can install GNU tools via homebrew. The scripts will not work
correctly using the default bash and BSD command line utilities that come with
Mac OS.
Mac users can install an updated bash via homebrew. The scripts will not work
correctly using the default version of bash that comes with Mac OS.
26 changes: 14 additions & 12 deletions scripts/make_new_lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,21 @@ fi

# Add the new lint to the `add_lints!()` macro.
echo -n "Registering lint in src/query.rs ..."
set +e
# -E = extended regex mode, which behaves more similarly to regex in most programming languages.
# -z = use \0 as separators instead of \n, so that we can do multi-line matches.
grep -Ez --regexp "add_lints\!\\([^)]+[ ]+$NEW_LINT_NAME," "$SRC_QUERY_FILE" >/dev/null
OUTPUT="$?"
set -e
if [[ "$OUTPUT" == "0" ]]; then
echo ' already exists.'
if awk -v lint_name="$NEW_LINT_NAME" '
/^add_lints!\(/ { searching = 1 }
searching && $0 ~ "[[:space:]]" lint_name "," { found = 1; exit }
END { if (found) { exit 0 } else { exit 1 } }
' "$SRC_QUERY_FILE"; then
printf ' already exists.\n'
else
# -E = extended regex mode, which behaves more similarly to regex in most programming languages.
# -z = use \0 as separators instead of \n, so that we can do multi-line matches.
sed -i'' -Ez "s/add_lints\!\\(([^)]+)\\)/add_lints\!(\\1 $NEW_LINT_NAME,\n)/" "$SRC_QUERY_FILE"
echo ' done!'
tmp="${SRC_QUERY_FILE}.tmp"
sed -e '/^add_lints!($/ a\'"
$NEW_LINT_NAME," "$SRC_QUERY_FILE" > "$tmp" && mv -- "$tmp" "$SRC_QUERY_FILE" || {
code=$?
rm -f "$tmp"
exit "$code"
}
printf ' done!\n'
fi

echo ''
Expand Down
4 changes: 2 additions & 2 deletions scripts/make_new_test_crate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ if [[ -d "$NEW_LINT_TEST_CRATES_DIR" ]]; then
echo ' already exists.'
else
cp -R "$TEST_CRATES_DIR/template" "$NEW_LINT_TEST_CRATES_DIR"
sed -i'' "s/template/$NEW_TEST_CRATE/g" "$NEW_LINT_TEST_CRATES_DIR/old/Cargo.toml"
sed -i'' "s/template/$NEW_TEST_CRATE/g" "$NEW_LINT_TEST_CRATES_DIR/new/Cargo.toml"
sed -e "s/template/$NEW_TEST_CRATE/g" "$TEST_CRATES_DIR/template/old/Cargo.toml" > "$NEW_LINT_TEST_CRATES_DIR/old/Cargo.toml"
sed -e "s/template/$NEW_TEST_CRATE/g" "$TEST_CRATES_DIR/template/new/Cargo.toml" > "$NEW_LINT_TEST_CRATES_DIR/new/Cargo.toml"
echo ' done!'
fi
Loading