Skip to content

Commit 61e04e3

Browse files
stepanchegfabianhjr
authored andcommitted
Use gsha256sum when sha256sum doesn't exist
On my mac laptop there's no `sha256sum` command, but there's `gsha256sum`: using `g` prefix is common when GNU utilities are installed on macOS. ``` SCHEME=chez make bootstrap ``` no longer fails on my laptop. The downside is that compilation now continuously prints a warning about `sha256sum` command not found (when it is not found). And I don't know how to fix it cross-platform way. ``` 1/5: Building Network.Socket.Data (Network/Socket/Data.idr) sh: sha256sum: command not found 2/5: Building Network.FFI (Network/FFI.idr) sh: sha256sum: command not found 3/5: Building Network.Socket.Raw (Network/Socket/Raw.idr) sh: sha256sum: command not found 4/5: Building Network.Socket (Network/Socket.idr) sh: sha256sum: command not found 5/5: Building Control.Linear.Network (Control/Linear/Network.idr) sh: sha256sum: command not found ```
1 parent b8082f4 commit 61e04e3

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/Libraries/Utils/Binary.idr

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -470,11 +470,10 @@ modTime fname
470470
coreLift $ closeFile f
471471
pure t
472472

473-
export
474-
hashFile : String -> Core String
475-
hashFile fileName
473+
hashFileWith : String -> String -> Core String
474+
hashFileWith sha256Sum fileName
476475
= do Right fileHandle <- coreLift $ popen
477-
("sha256sum \"" ++ osEscape fileName ++ "\"") Read
476+
(sha256Sum ++ " \"" ++ osEscape fileName ++ "\"") Read
478477
| Left _ => coreFail $ InternalError ("Can't get sha256sum of " ++ fileName)
479478
Right hashLine <- coreLift $ fGetLine fileHandle
480479
| Left _ =>
@@ -489,3 +488,15 @@ hashFile fileName
489488
osEscape = if isWindows
490489
then id
491490
else escapeStringUnix
491+
492+
export
493+
hashFile : String -> Core String
494+
hashFile fileName =
495+
-- Note `popen` call won't fail if there's no `sha256sum` command
496+
-- so we can't just catch `popen` error.
497+
catch (hashFileWith "sha256sum" fileName)
498+
(\err =>
499+
catch (hashFileWith "gsha256sum" fileName)
500+
-- When `gsha256sum` fails as well, return the error with `sha256sum`.
501+
(\_ => coreFail err)
502+
)

0 commit comments

Comments
 (0)