-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Embed cardano-cli and use it to test operation of devnet
- Loading branch information
Showing
9 changed files
with
93 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{-# LANGUAGE TemplateHaskell #-} | ||
|
||
-- | Functions to access embedded binaries. | ||
module Pegasus.Embed where | ||
|
||
import Data.Bits ((.|.)) | ||
import Data.ByteString qualified as BS | ||
import Pegasus.EmbedTH (embedExecutable) | ||
import System.Posix.Files (ownerExecuteMode, ownerReadMode, ownerWriteMode, setFileMode) | ||
|
||
-- | Write the embedded 'cardano-node' binary to a path. | ||
writeCardanoNodeTo :: FilePath -> IO () | ||
writeCardanoNodeTo fp = do | ||
BS.writeFile fp $(embedExecutable "cardano-node") | ||
setFileMode fp (ownerReadMode .|. ownerWriteMode .|. ownerExecuteMode) | ||
|
||
-- | Write the embedded 'cardano-cli' binary to a path. | ||
writeCardanoCliTo :: FilePath -> IO () | ||
writeCardanoCliTo fp = do | ||
BS.writeFile fp $(embedExecutable "cardano-cli") | ||
setFileMode fp (ownerReadMode .|. ownerWriteMode .|. ownerExecuteMode) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
-- | Template haskell expression to embed executables. | ||
module Pegasus.EmbedTH where | ||
|
||
import Data.FileEmbed (embedFile) | ||
import Language.Haskell.TH (Exp, Q, runIO) | ||
import System.Directory (findExecutable) | ||
|
||
-- | Template haskell expression to find and embed an executable with given name. | ||
embedExecutable :: String -> Q Exp | ||
embedExecutable exe = do | ||
fp <- runIO $ do | ||
findExecutable exe >>= \case | ||
Nothing -> fail $ exe <> " not found, ensure it is in PATH when compiling (and do a cabal clean)" | ||
Just fp -> do | ||
putStrLn $ "Embedding " <> exe <> " from: " <> fp | ||
pure fp | ||
embedFile fp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters