Skip to content

Commit 11d0603

Browse files
committed
Support FreeBSD SHA-256
Use [autodetect_system_binaries] so [awk] is not from PATH. Add test.
1 parent 91b289d commit 11d0603

File tree

5 files changed

+38
-9
lines changed

5 files changed

+38
-9
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ opam text
2222
*.ml text eol=lf
2323
*.opam text eol=lf
2424
*.opam.template text eol=lf
25+
*.txt text eol=lf
2526

2627
# Declare files that will always have CRLF line endings on checkout.
2728
*.sln text eol=crlf

dkml-runtime-common-native.opam

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ dev-repo: "git+https://github.com/diskuv/dkml-runtime-common.git"
1919
# Must not rely on OCaml (ex. diskuvbox or dune) because this
2020
# package is a dependency of OCaml compilers like dkml-base-compiler!
2121
depends: []
22+
build: [
23+
["sh" "tests/crossplatform-tests.sh"] { with-test & !(os = "win32") }
24+
]
2225
install: [
23-
# TODO: opam does not quote when there is a space in the _:lib
24-
# so we have to avoid the (correct) Command Prompt shell. Needs a bug
25-
# report. (jonahbeckford@ 2023-01-11)
26+
# TODO: opam does not pass to Command Prompt correctly when there is a
27+
# space in the _:lib so we have to avoid the (correct) Command Prompt
28+
# shell. https://github.com/ocaml/opam/issues/5673
2629
#[".\\install.cmd" "\"%{_:lib}%\""] { os = "win32"}
2730
["sh" "./install.sh" "%{_:lib}%"] # {!(os = "win32")}
2831
]

tests/crossplatform-tests.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
# shellcheck disable=SC1091
4+
. unix/crossplatform-functions.sh
5+
6+
# Test Vectors
7+
# NIST.1
8+
sha256check tests/nist.1.txt ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad

tests/nist.1.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
abc

unix/crossplatform-functions.sh

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2832,10 +2832,16 @@ sha256compute() {
28322832
sha256compute_FILE=$(/usr/bin/cygpath -a "$sha256compute_FILE")
28332833
fi
28342834

2835-
if [ -x /usr/bin/shasum ]; then
2836-
/usr/bin/shasum -a 256 "$sha256compute_FILE" | awk '{print $1}'
2837-
elif [ -x /usr/bin/sha256sum ]; then
2838-
/usr/bin/sha256sum "$sha256compute_FILE" | awk '{print $1}'
2835+
autodetect_system_binaries
2836+
if [ -x /usr/bin/shasum ]; then # macOS, OpenBSD
2837+
# shellcheck disable=SC2016
2838+
/usr/bin/shasum -a 256 "$sha256compute_FILE" | "$DKMLSYS_AWK" '{print $1}'
2839+
elif [ -x /usr/bin/sha256sum ]; then # Linux, MSYS2
2840+
# shellcheck disable=SC2016
2841+
/usr/bin/sha256sum "$sha256compute_FILE" | "$DKMLSYS_AWK" '{print $1}'
2842+
elif [ -x /sbin/sha256 ]; then # FreeBSD
2843+
# shellcheck disable=SC2016
2844+
/sbin/sha256 -r "$sha256compute_FILE" | "$DKMLSYS_AWK" '{print $1}'
28392845
else
28402846
printf "FATAL: %s\n" "No sha256 checksum utility found" >&2
28412847
exit 107
@@ -2849,12 +2855,22 @@ sha256check() {
28492855
shift
28502856
sha256check_SUM="$1"
28512857
shift
2852-
if [ -x /usr/bin/shasum ]; then
2858+
2859+
if [ -x /usr/bin/shasum ]; then # macOS, OpenBSD
28532860
printf "%s %s" "$sha256check_SUM" "$sha256check_FILE" | /usr/bin/shasum -a 256 -c >&2
2854-
elif [ -x /usr/bin/sha256sum ]; then
2861+
elif [ -x /usr/bin/sha256sum ]; then # Linux, MSYS2
28552862
printf "%s %s" "$sha256check_SUM" "$sha256check_FILE" | /usr/bin/sha256sum -c >&2
2863+
elif [ -x /sbin/sha256 ]; then # FreeBSD
2864+
/sbin/sha256 -c "$sha256check_SUM" "$sha256check_FILE" >&2
28562865
else
28572866
printf "FATAL: %s\n" "No sha256 checksum utility found" >&2
2867+
2868+
# REMOVEME!
2869+
if [ -d /sbin ]; then printf "/sbin:\n" >&2; ls /sbin >&2; fi
2870+
if [ -d /usr/sbin ]; then printf "/usr/sbin:\n" >&2; ls /usr/sbin >&2; fi
2871+
if [ -d /bin ]; then printf "/bin:\n" >&2; ls /bin >&2; fi
2872+
if [ -d /usr/bin ]; then printf "/usr/bin:\n" >&2; ls /usr/bin >&2; fi
2873+
28582874
exit 107
28592875
fi
28602876
}

0 commit comments

Comments
 (0)