-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure Compatibility with BSD sha1sum implementation #549
Conversation
You can explicitly specify
It works on both GNU/Linux and macOS. |
Quote from Wikipedia:
Here, refer to "macOS" instead of "MacOS." |
Specifying MACOS$ echo "CONTENT" > file
MACOS$ sha1sum file
7a2ed3b06b4ecf87d3a31966d8c17a9afb6634d9 file
MACOS$ rm file
MACOS$ echo "7a2ed3b06b4ecf87d3a31966d8c17a9afb6634d9 file" | sha1sum -c -
sha1sum: file: No such file or directory LINUX$ sha1sum file
7a2ed3b06b4ecf87d3a31966d8c17a9afb6634d9 file
LINUX$ rm file
LINUX$ echo "7a2ed3b06b4ecf87d3a31966d8c17a9afb6634d9 file" | sha1sum -c
sha1sum: file: No such file or directory
file: FAILED open or read
sha1sum: WARNING: 1 listed file could not be read As shown above, when the file does not exist, |
We can always check the existence with shell commands, and that is why GNU's and FreeBSD's (which macOS takes from) implementations have different perspectives: GNU coreutils comes with various powerful features while FreeBSD's implementation takes conservative approaches and prioritizes on robustness. In this case, switching to |
Thank you for the insightful comment! diff --git a/mk/external.mk b/mk/external.mk
index 05f5576..bbf91aa 100644
--- a/mk/external.mk
+++ b/mk/external.mk
@@ -68,7 +68,7 @@ define verify
| sort \
| $(SHA1SUM) \
| cut -f 1 -d ' ' > $(SHA1_FILE2) && cmp $(SHA1_FILE1) $(SHA1_FILE2))), \
- ($(eval VERIFIER := echo "$(strip $(1)) $(strip $(2))" | $(SHA1SUM) -c)) \
+ ($(eval VERIFIER := (ls $(2) >/dev/null 2>&1 || echo FAILED) && echo "$(strip $(1)) $(strip $(2))" | $(SHA1SUM) -c -)) \
))
$(eval _ := $(shell $(VERIFIER) 2>&1)) |
Upon careful review of the rv32emu documentation, you will find that using 'brew' is optional. macOS and FreeBSD users can build from source to access minimal features. This flexibility is crucial for a small project like rv32emu, as users should not need to constantly reference documentation. Regarding |
BSD and GNU implementations have slightly different behavior, the former implementation is used in macOS, FreeBSD and similar systems. While both implementations behave identically with the -c - argument when the file exists, they differ when the file does not exist. This commit adds an 'ls' command to address this difference, ensuring consistent behavior across platforms.
Thank @otteryc for contributing! |
Recent macOS updates introduced
/sbin/sha1sum
, which is not GNU'ssha1sum
and is incompatible with its implementation. This causes the sha1sum test inmake artifact
to always pass because the test currently relies on detecting the string "FAILED" in the stderr output.Apple's
sha1sum
does not support the -c (checksum verification) option, making it unsuitable for verifying artifact integrity. Below is a demonstration of the differences between Apple's and GNU'ssha1sum
: