Commit f8fd374b authored by Valentin Reis's avatar Valentin Reis

improve dev tools/add offline mode

parent 3105a555
Pipeline #6409 passed with stages
in 2 minutes and 56 seconds
eval "$(lorri direnv)"
### `argonix`
wrapper around various nix tools to override sources and provision
wrapper around nix tools to override sources and provision
dependencies for argo. supports remote target machines.
#### Install
......
{-# language NoImplicitPrelude #-}
{-# language OverloadedStrings #-}
{-|
......@@ -14,38 +13,79 @@ import Protolude
import Development.Shake.FilePath
import Control.Monad
import System.Process.Typed
import System.Posix.Process
import qualified System.IO as SIO
( hSetBuffering
, stdout
, BufferMode(..)
)
import Options.Applicative as OA
main = getArgs >>= deal
where
deal args
| "ghcid" `elem` args = void $ startProcess $ proc
"ghcid"
[ "--command"
, "cabal new-repl argonix"
, "--restart"
, "argonix.cabal"
, "--restart"
, "default.nix"
, "--restart"
, "shell.nix"
]
| otherwise = runshake
runshake = shakeArgs shakeOptions $ do
phony "clean" $ removeFilesAfter "." ["README.md"]
data GhcidTarget = Lib | App deriving (Enum,Bounded,Show,Read)
toArgs Lib = ghcidTarget "new-repl argo-nixwrap" []
toArgs App = ghcidTarget "new-repl argonix" []
want ["README.md"]
ghcidTarget :: Text -> [Text] -> [Text]
ghcidTarget target extra =
[ "--command"
, "cabal "
<> target
<> " "
<> " --ghc-options=-fno-code"
<> " --ghc-options=-fno-break-on-exception"
<> " --ghc-options=-fno-break-on-error"
<> " --ghc-options=-v1 --ghc-options=-ferror-spans"
, "--restart=dhrun.cabal"
, "--restart=default.nix"
, "--restart=shell.nix"
]
++ extra
"README.md" %> \out -> do
let template = ".README.md"
need [template, "src/Argonix.hs"]
panpipe <- toS <$> readProcessStdout_ (shell "which panpipe")
runProcess_ $ proc
"pandoc"
["--filter", take (length panpipe - 1) panpipe, template, "-o", out]
runGhcid :: GhcidTarget -> IO ()
runGhcid target = do
runProcess_ "rm -f .ghc.*"
executeFile "ghcid" True (toS <$> toArgs target) Nothing
main :: IO ()
main = SIO.hSetBuffering SIO.stdout SIO.NoBuffering
<> void (join (execParser (info (opts <**> helper) idm)))
where
opts :: Parser (IO ())
opts = hsubparser
( OA.command
"ghcid"
(info (runGhcid <$> targetParser)
(progDesc "Run an argo-compatible nix-build.")
)
<> OA.command
"shake"
(info (pure runshake)
(progDesc "run shake.")
)
<> help "Type of operation to run."
)
targetParser :: Parser GhcidTarget
targetParser = argument auto
(metavar "TARGET" <> showDefault <> help
(toS ("The ghcid target, in " <> mconcat ts))
)
where ts = intersperse " " (Prelude.show <$> [(minBound :: GhcidTarget) ..])
phony "clean" (removeFilesAfter "." ["README.md"])
runshake = shakeArgs shakeOptions $ do
phony "clean" $ removeFilesAfter "." ["README.md"]
phony "brittany" brittany
brittany = runProcess_ (shell "brittany --write-mode inplace src/*.hs")
{-want ["README.md"]-}
{-"README.md" %> \out -> do-}
{-let template = ".README.md"-}
{-need [template, "src/Dhrun.hs", "src/Dhrun/Types.hs", "src/Dhrun/Run.hs"]-}
{-panpipe <- toS <$> readProcessStdout_ "which panpipe"-}
{-runProcess_ $ proc-}
{-"pandoc"-}
{-["--filter", take (length panpipe - 1) panpipe, template, "-o", out]-}
where
brittany = runProcess_
$ shell "brittany --write-mode inplace src/*.hs src/Dhallexec/*hs"
#!/usr/bin/env bash
rm -f .ghc.env*
runhaskell shake.hs $@
......@@ -41,6 +41,7 @@ data ArgsCommon = ArgsCommon
, overrides :: [(Text, Text)]
, grafting :: Grafting
, sandboxing :: Sandboxing
, offline :: Bool
} deriving (Show)
data Verbosity = Verbose | Normal deriving (Show, Eq)
data Sandboxing = Sandbox | NoSandbox deriving (Show, Eq)
......@@ -52,15 +53,15 @@ data NixStaticInOut = Both Text
| Target Text deriving (Eq)
data NixCommand = NixBuild | NixShell
instance Default ArgsCommon where
def = ArgsCommon
{ verbosity = Normal,
argopkgs = "<argopkgs>",
run = Nothing,
overrides = [],
grafting = NoGraft,
sandboxing = NoSandbox
{ verbosity = Normal,
argopkgs = "<argopkgs>",
run = Nothing,
overrides = [],
grafting = NoGraft,
sandboxing = NoSandbox,
offline = False
}
instance Default ArgsRemote where
......@@ -95,6 +96,10 @@ commonParser = do
<> value (argopkgs def)
<> help "Nix expression that produces the argopkgs source path."
)
offline <- flag
False
True
(long "offline" <> short 'o' <> help "Do not use no binary caches.")
verbosity <- flag
Normal
Verbose
......@@ -157,12 +162,12 @@ nixStatic = src <> both <> simpletarget <> target
Both
<$> [ "aml"
, "libnrm"
, "dhrun"
, "numabench"
, "repoquality"
, "excit"
, "nrm"
, "containers"
, "argotk"
, "amg"
, "lammps"
, "qmcpack"
......
......@@ -251,6 +251,7 @@ nixArguments target ArgsCommon {..} =
++ (if grafting == Libnrm then ["--arg", "graftLibnrm", "true"] else [])
++ ["-o", "/tmp/papa"]
++ [ "--show-trace" | v ]
++ (if offline then ["--option", "binary-caches", "null"] else [])
where v = verbosity == Verbose
wrap :: NixCommand -> Text -> ArgsCommon -> IO ()
......@@ -283,7 +284,7 @@ wrap nixCommand target sa@ArgsCommon {..} = do
++ [if sandboxing == Sandbox then "true" else "false"]
remotely :: Text -> ArgsCommon -> ArgsRemote -> IO ()
remotely _ _ _ = putText "unsupported in this version" >> undefined
remotely _ _ _ = putText "unsupported in this version" <> undefined
-- no sandbox use is possible. If sandbox paths were read only we could add:
{-, "--option"-}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment