...
 
Commits (4)
.argo_nodeos_config_exit_message
.direnv
*/.direnv
_output
result
.shake
......
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
#! /usr/bin/env nix-shell
#! nix-shell default.nix -i runhaskell -A executor
{-# language RecordWildCards #-}
{-# language TupleSections #-}
{-# language ApplicativeDo #-}
{-# language OverloadedStrings #-}
module Argotest where
module Main where
import Data.Default
import Turtle hiding ( header )
import Turtle hiding ( header
, arguments
)
import Options.Applicative
import Data.Maybe
import Prelude hiding ( FilePath )
import System.IO ( withFile )
import Debug.Trace
import Filesystem.Path ( (</>) )
import Control.Concurrent.Async
import System.Console.ANSI
import System.Console.ANSI.Types ( Color )
import System.Posix.Signals
import Data.Text ( pack )
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)
......@@ -47,34 +39,84 @@ executorParser = do
(long "verbose" <> short 'v' <> help "Enable verbose mode")
targetMachine <- optional $ strOption
(long "target_machine" <> metavar "USER@HOST" <> help
"Target machine to run on"
"Target machine. defaults to localhost via forking."
)
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."))
pure $ mapT l parsed
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 l thePath = case thePath of
Nothing -> Nothing
Just p -> Just (l,p)
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 = ["-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 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 "Test environment builder for argo. This is a lightweight wrapper around various nix commands." <> header
"argonix"
( 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
......@@ -14,17 +14,25 @@ in
dgemm_randomwalk-src ? argopkgs.applications.nrm.dgemm_randomwalk.src,
}:
let
filterHdevTools = builtins.filterSource (path: type:
(baseNameOf path != ".hdevtools.sock") &&
(baseNameOf path != ".ghc.environment.x86_64-linux-8.4.4") &&
(baseNameOf path != "dist"));
addHackEnv = package : package.overrideAttrs (old: {
hack = argopkgs.haskellPackages.shellFor {
packages = p: [package];
withHoogle = true;
buildInputs = devInputs ++ devHPackages;
};
});
cabalDevLoader = self: path: set: addHackEnv
(self.callCabal2nix (baseNameOf path) (filterHdevTools path) set);
devInputs = with argopkgs.haskellPackages; with argopkgs; [
sysstat jq
sysstat jq cabal-install
];
devHPackages = with argopkgs.haskellPackages; [
hdevtools hlint brittany ghcid
hdevtools hlint brittany ghcid Cabal
];
addHackEnv = package : package.overrideAttrs (old: {
buildInputs = old.buildInputs ++ devInputs ++ devHPackages;
});
in rec {
argotk = argopkgs.argotk.overrideAttrs (old: {src = argotk-src;} );
nrm = argopkgs.nodelevel.nrm.overrideAttrs (old: {src = nrm-src;} );
......@@ -76,15 +84,13 @@ in
];
});
executor = argopkgs.mkShell {
name = "shake";
buildInputs = [
(argopkgs.haskellPackages.ghcWithPackages (p: with p; [
argotk
turtle data-default optparse-generic unix
]))
];
hpkgs = argopkgs.haskellPackages.override {
overrides = self: super:
let
loader = cabalDevLoader self;
in rec {
argotest = loader ./argotest {};
};
};
executor-hack = addHackEnv executor;
argotest = hpkgs.argotest;
}
......@@ -44,49 +44,49 @@ nrm.build:
extends: .nix-integration
script:
- CACHE=$(mktemp -d --suffix=nixcache /tmp/deletable-nix-cache-XXXX)
- XDG_CACHE_HOME=$CACHE nix-shell -A test --run "cp $MANIFESTS/* _output/ ;argotk TestPower --verbose"
- XDG_CACHE_HOME=$CACHE nix-shell -A test --run "cp $MANIFESTS/* _output/ ;argotk TestPower --verbose" --pure
- rm -rf $CACHE
.TestHello.test:
extends: .nix-integration
script:
- CACHE=$(mktemp -d --suffix=nixcache /tmp/deletable-nix-cache-XXXX)
- XDG_CACHE_HOME=$CACHE nix-shell -A test --run "argotk TestHello --verbose"
- XDG_CACHE_HOME=$CACHE nix-shell -A test --run "argotk TestHello --verbose" --pure
- rm -rf $CACHE
.TestListen.test:
extends: .nix-integration
script:
- CACHE=$(mktemp -d --suffix=nixcache /tmp/deletable-nix-cache-XXXX)
- XDG_CACHE_HOME=$CACHE nix-shell -A test --run "argotk TestListen --verbose"
- XDG_CACHE_HOME=$CACHE nix-shell -A test --run "argotk TestListen --verbose" --pure
- rm -rf $CACHE
.TestPerfwrapper.test:
extends: .nix-integration
script:
- CACHE=$(mktemp -d --suffix=nixcache /tmp/deletable-nix-cache-XXXX)
- XDG_CACHE_HOME=$CACHE nix-shell -A test --run "argotk TestPerfwrapper --verbose"
- XDG_CACHE_HOME=$CACHE nix-shell -A test --run "argotk TestPerfwrapper --verbose" --pure
- rm -rf $CACHE
.TestSTREAM.test:
extends: .nix-integration
script:
- CACHE=$(mktemp -d --suffix=nixcache /tmp/deletable-nix-cache-XXXX)
- XDG_CACHE_HOME=$CACHE nix-shell -A test --run "argotk TestSTREAM --verbose"
- XDG_CACHE_HOME=$CACHE nix-shell -A test --run "argotk TestSTREAM --verbose" --pure
- rm -rf $CACHE
.TestAMG.test:
extends: .nix-integration
script:
- CACHE=$(mktemp -d --suffix=nixcache /tmp/deletable-nix-cache-XXXX)
- XDG_CACHE_HOME=$CACHE nix-shell -A test --run "argotk TestAMG"
- XDG_CACHE_HOME=$CACHE nix-shell -A test --run "argotk TestAMG" --pure
- rm -rf $CACHE
.TestSTREAM.test:
extends: .nix-integration
script:
- CACHE=$(mktemp -d --suffix=nixcache /tmp/deletable-nix-cache-XXXX)
- XDG_CACHE_HOME=$CACHE nix-shell -A test --run "argotk TestSTREAM"
- XDG_CACHE_HOME=$CACHE nix-shell -A test --run "argotk TestSTREAM" --pure
- rm -rf $CACHE
KNL-Power.test:
......