Commit 9957d2fc authored by Valentin Reis's avatar Valentin Reis

updates the test logic.

parent 32416bf0
Pipeline #5158 passed with stage
in 58 seconds
......@@ -2,8 +2,8 @@
"fetch": {
"args": {
"fetchSubmodules": false,
"rev": "e3c993484d35b13149b30610132589ac2074652d",
"sha256": "1pf3xlysdkljg2v29rckzbay3fw17yvp64a7hbbl0kjvx5d0q1yw",
"rev": "c14f0f26b69f8b38875278c7cc5c597137c2a29a",
"sha256": "0y5q5np5wag0zvz7wm7k3wg7nyz2iwzqswnpwxz74ihlycklmb83",
"url": "https://xgitlab.cels.anl.gov/argo/argopkgs.git"
},
"fn": "fetchgit"
......
name: argotest
version: 0.1.0.0
license: MIT
license-file: LICENSE
author: Valentin Reis
maintainer: fre@freux.fr
build-type: Simple
extra-source-files: ChangeLog.md
cabal-version: >=1.10
executable argotest
main-is: argotest.hs
build-depends:
base,
turtle,
data-default,
optparse-applicative,
unix,
text,
system-filepath
default-language: Haskell2010
ghc-options:
-threaded
-Wall
-Wincomplete-uni-patterns
-Wincomplete-record-updates
-Wmissing-home-modules
-Widentities
-Wredundant-constraints
-Wcpp-undef
-fwarn-tabs
-fwarn-unused-imports
-fwarn-missing-signatures
-fwarn-name-shadowing
-fprint-potential-instances
-Wmissing-export-list
-fwarn-incomplete-patterns
{-# language RecordWildCards #-}
{-# language ApplicativeDo #-}
{-# language OverloadedStrings #-}
module Main where
import Data.Default
import Turtle hiding ( header
, arguments
)
import Options.Applicative
import Data.Maybe
import Prelude hiding ( FilePath )
import Data.Text ( pack )
import System.Posix.Process
data StackArgs = StackArgs
{ verbosity :: Verbosity
, targetMachine :: Maybe String
, run :: Maybe String
, overrides :: [(String, FilePath)]
} deriving (Show)
data Verbosity = Verbose | Normal deriving (Show)
instance Default StackArgs where
def = StackArgs
{ verbosity = Normal,
run = Nothing,
targetMachine = Nothing,
overrides = []
}
executorParser :: Parser StackArgs
executorParser = do
verbosity <- flag
Normal
Verbose
(long "verbose" <> short 'v' <> help "Enable verbose mode")
targetMachine <- optional $ strOption
(long "target_machine" <> metavar "USER@HOST" <> help
"Target machine. defaults to localhost via forking."
)
overrides <- catMaybes <$> truc
run <- optional $ strOption
(long "run" <> metavar "COMMAND" <> help
"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"
]
optSrc :: String -> Parser (Maybe (String, FilePath))
optSrc longform = do
parsed <- optional $ strOption
(long longform <> metavar "PATH" <> help
(longform <> " source folder override.")
)
pure $ mapT longform parsed
mapT :: String -> Maybe FilePath -> Maybe (String, FilePath)
mapT longform thePath = case thePath of
Nothing -> Nothing
Just p -> Just (longform, p)
main :: IO ()
main = sh $ do
a@StackArgs {..} <- liftIO $ execParser opts
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 StackArgs {..} =
["-A", "test"]
++ concat
[ ["--arg", longform <> "-src", encodeString p]
| (longform, p) <- overrides
]
++ (case run of
Just cmd -> ["--run", cmd]
Nothing -> []
)
opts = info
(executorParser <**> helper)
( fullDesc
<> progDesc
"Argo test environment manager. This uses various nix tools to provision a local or remote environment with source overrides."
<> header "argotest"
)
(import ../default.nix {}).argotest.hack
......@@ -61,7 +61,7 @@ in
source ${argotk}/share/argotk.sh
echo "Installed bash completion."
'';
MANIFESTS = ./manifests;
MANIFESTS = "${argopkgs.argonix}/share/manifests";
};
hack = test.overrideAttrs (old:{
......@@ -83,14 +83,4 @@ in
]))
];
});
hpkgs = argopkgs.haskellPackages.override {
overrides = self: super:
let
loader = cabalDevLoader self;
in rec {
argotest = loader ./argotest {};
};
};
argotest = hpkgs.argotest;
}
#!/usr/bin/env sh
export NIX_SSHOPTS="source .profile; source .bash_profile;"
host=$1;shift
echo "remote-nix-shell.sh: creating a derivation in the local store."
drv=$(nix-instantiate $@ --quiet)
echo "the derivation has store path: $drv"
echo "remote-nix-shell.sh: building this derivation's output locally."
nix-store --realize $drv --quiet > /dev/null
echo "remote-nix-shell.sh: copying the derivation and its output to the host."
nix-copy-closure --include-outputs --to $host $drv
echo "remote-nix-shell.sh: entering a remote shell."
ssh -t $host "source .profile; source .bash_profile; nix-shell $drv"
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