Commit ed8c2813 authored by Valentin Reis's avatar Valentin Reis

argonix -> argotest, implement target_machine.

parent e2aafd1a
.argo_nodeos_config_exit_message
.direnv
*/.direnv
_output
result
.shake
......
#! /usr/bin/env nix-shell
#! nix-shell default.nix -i runhaskell -A executor
#! nix-shell default.nix -i runhaskell -A argotest
{-# language RecordWildCards #-}
{-# language TupleSections #-}
{-# language ApplicativeDo #-}
{-# language OverloadedStrings #-}
......@@ -16,6 +15,9 @@ import Prelude hiding ( FilePath )
import System.IO ( withFile )
import Debug.Trace
import Data.Text ( unpack
, pack
)
import Filesystem.Path ( (</>) )
import Control.Concurrent.Async
import System.Console.ANSI
......@@ -25,8 +27,8 @@ import System.Posix.Process
data StackArgs = StackArgs
{ verbosity :: Verbosity
, targetMachine :: Maybe FilePath
, run :: Maybe FilePath
, targetMachine :: Maybe String
, run :: Maybe String
, overrides :: [(String, FilePath)]
} deriving (Show)
data Verbosity = Verbose | Normal deriving (Show)
......@@ -50,31 +52,76 @@ executorParser = do
"Target machine to run on"
)
overrides <- catMaybes <$> truc
run <- optional $ strOption
run <- optional $ strOption
(long "run" <> metavar "COMMAND" <> help
"Command to run once in the environment"
"Command to run the environment instead of an interactive shell"
)
pure StackArgs {..}
where
truc :: Parser [Maybe (String, FilePath)]
truc = traverse optSrc [ "argotk", "argopkgs", "nrm", "containers", "libnrm", "amg", "lammps", "qmcpack", "stream" ]
truc = traverse
optSrc
[ "argotk"
, "argopkgs"
, "nrm"
, "containers"
, "libnrm"
, "amg"
, "lammps"
, "qmcpack"
, "stream"
]
optSrc :: String -> Parser (Maybe (String, FilePath))
optSrc l = do
parsed <- optional $ strOption (long l <> metavar "PATH" <> help (l <> " source folder override."))
parsed <- optional $ strOption
(long l <> metavar "PATH" <> help (l <> " source folder override."))
pure $ mapT l parsed
mapT :: String -> Maybe FilePath -> Maybe (String, FilePath)
mapT l thePath = case thePath of
Nothing -> Nothing
Just p -> Just (l,p)
Nothing -> Nothing
Just p -> Just (l, p)
main :: IO ()
main = sh $ do
a@StackArgs {..} <- liftIO $ execParser opts
let arguments = ["-A", "test"]
liftIO $ executeFile "nix-shell" True (["-A", "test"] ++ (concat [ ["--arg", (l <> "-src") , encodeString p] | (l,p) <- overrides])) Nothing
let arguments = argumentsBuilder a
case targetMachine of
Nothing -> liftIO $ executeFile "nix-shell" True arguments Nothing
Just host -> do
printf s "argotest.hs: creating a derivation in the local store:\n"
drv <- single $ inproc
"nix-instantiate"
(["default.nix", "--quiet"] ++ map pack arguments)
empty
printf (s % "\n") $ lineToText drv
printf s "argotest.hs: building the derivation's output:\n"
proc "nix-store" ["--realize", lineToText drv, "--quiet"] empty
printf s "argotest.hs: copying the derivation's closure.\n"
proc "nix-copy-closure"
["--include-outputs", "--to", pack host, lineToText drv]
empty
liftIO $ executeFile
"ssh"
True
["-t", host, "source .profile; source .bash_profile; nix-shell $drv"]
Nothing
where
argumentsBuilder :: StackArgs -> [String]
argumentsBuilder a@StackArgs {..} =
["-A", "test"]
++ concat [ ["--arg", l <> "-src", encodeString p] | (l, p) <- overrides ]
++ (case run of
Just command -> ["--run", command]
Nothing -> []
)
opts = info
(executorParser <**> helper)
(fullDesc <> progDesc "Test environment builder for argo. This is a lightweight wrapper around various nix commands." <> header
"argonix"
( fullDesc
<> progDesc
"Test environment builder for argo. This is a lightweight wrapper around various nix commands."
<> header "argonix"
)
......@@ -76,7 +76,7 @@ in
];
});
executor = argopkgs.mkShell {
argotest = argopkgs.mkShell {
name = "shake";
buildInputs = [
(argopkgs.haskellPackages.ghcWithPackages (p: with p; [
......@@ -86,5 +86,5 @@ in
];
};
executor-hack = addHackEnv executor;
argotest-hack = addHackEnv argotest;
}
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