Commit 11debf01 authored by Valentin Reis's avatar Valentin Reis

Refactored "argostack" as a library

parent f8bd219e
Pipeline #4612 failed with stage
in 0 seconds
# Revision history for argotest
## 0.1.0.0 -- YYYY-mm-dd
* First version. Released on an unsuspecting world.
Copyright (c) 2018 Valentin Reis
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import Distribution.Simple
main = defaultMain
-- Initial argotest.cabal generated by cabal init. For further
-- documentation, see http://haskell.org/cabal/users-guide/
name: argotest
version: 0.1.0.0
-- synopsis:
-- description:
license: MIT
license-file: LICENSE
author: Valentin Reis
maintainer: fre@freux.fr
-- copyright:
-- category:
build-type: Simple
extra-source-files: ChangeLog.md
cabal-version: >=1.10
library
exposed-modules: Argotest
-- other-modules:
-- other-extensions:
build-depends: base >=4 && <=8, turtle, data-default, managed, ansi-terminal, unix, system-filepath, async
hs-source-dirs: src
default-language: Haskell2010
{-# LANGUAGE
RecordWildCards
, LambdaCase
, OverloadedStrings
, DataKinds
, DeriveGeneric
, FlexibleInstances
, TypeOperators #-}
LambdaCase
, OverloadedStrings
, DataKinds
, FlexibleInstances
, TypeOperators #-}
module Argotest where
......@@ -53,9 +51,9 @@ printInfo :: Text -> Shell ()
printError :: Text -> Shell ()
printWarning :: Text -> Shell ()
printInfo str = printf ("Info:"%s) str
printWarning str = colorShell Yellow $ printf ("Warning:"%s) str
printError str = colorShell Red $ printf ("Error:"%s) str
printInfo = printf ("Info:"%s)
printWarning = colorShell Yellow . printf ("Warning:"%s)
printError = colorShell Red . printf ("Error:"%s)
myWhich str = which str >>= \case
(Just p) -> printInfo ( format ("Found "%fp%" at "%fp%"\n") str p ) >> return p
......@@ -63,13 +61,13 @@ myWhich str = which str >>= \case
sudoRemoveFile :: (Text -> Shell ()) -> Text -> FilePath -> Shell ()
sudoRemoveFile printer desc filePath = do
foundSocket <- (testfile filePath)
foundSocket <- testfile filePath
when foundSocket $ go False
printInfo $ format ("OK: "%s%" "%fp%"\n") desc filePath
where go useSudo = do
printer $ format ("found stale " %s%" at "%fp%"..") desc filePath
printer $ format ("found stale " %s%" at "%fp%".. ") desc filePath
shell (format ((if useSudo then "sudo " else "")%"rm -f "%fp) filePath) empty >>= \case
ExitSuccess -> colorShell Green $ printf (" Successfully removed.\n")
ExitSuccess -> colorShell Green $ printf " Successfully removed.\n"
ExitFailure n -> if useSudo
then printer $ format ("Failed to remove stale "%s%", even with sudo.") desc
else do
......@@ -94,7 +92,7 @@ prepareDaemonShell dargs daemon_out daemon_err nrm_log = do
let confPath' = tempDirPath </> "argo_nodeos_config"
cp confPath confPath'
printInfo $ format ("Copied the configurator to "%fp%"\n") confPath'
printInfo $ format ("Trying to sudo chown and chmod argo_nodeos_config\n")
printInfo $ format "Trying to sudo chown and chmod argo_nodeos_config\n"
shell (format ("sudo chown root:root "%fp) confPath') empty >>= \case
ExitSuccess -> printInfo "Chowned argo_nodeos_config to root:root.\n"
ExitFailure n -> die ("Failed to set argo_nodeos_config permissions " <> repr n)
......
......@@ -3,42 +3,36 @@
nrm-src ? (builtins.fetchGit https://xgitlab.cels.anl.gov/argo/nrm.git)
}:
let
argopkgs = import argopkgs-src {};
pkgs = import argopkgs-src {};
nrm = argopkgs.nodelevel.nrm.overrideAttrs (old: { src = nrm-src; });
containers = argopkgs.nodelevel.containers;
amg = argopkgs.applications.nrm.amg;
nrm = pkgs.nodelevel.nrm.overrideAttrs (old: { src = nrm-src; });
containers = pkgs.nodelevel.containers;
amg = pkgs.applications.nrm.amg;
hpkgs = (p: with p;[
turtle optparse-generic data-default interpolatedstring-perl6 managed
]);
hpkgs-dev = (p: with p;[
turtle optparse-generic data-default interpolatedstring-perl6 managed
(argopkgs.haskell.lib.doJailbreak panpipe) ghcid
]);
hpkgs = pkgs.haskellPackages.override {
overrides = self: super: rec {
argotest = self.callCabal2nix "argotest" ./argotest {};
};
};
in rec
{
env = argopkgs.stdenv.mkDerivation {
src=./.;
name="nrm-experimental-dev-environment";
buildInputs = [
containers
amg
nrm
];
dev-beforelib = hpkgs.shellFor {
packages = p: with p; [ argotest ];
withHoogle = true;
buildInputs = with hpkgs; with pkgs; [ cabal-install ghcid
hlint sysstat hdevtools];
};
test = pkgs.stdenv.mkDerivation rec {
name = "env";
env = pkgs.buildEnv { name = name; paths = buildInputs; };
buildInputs = [
(hpkgs.ghcWithPackages (p: [p.argotest]))
containers
amg
nrm
];
};
test = env.overrideAttrs(old: {
src = ./.;
buildInputs = old.buildInputs ++ [ (argopkgs.haskellPackages.ghcWithPackages hpkgs) ];
buildPhase = "runhaskell integration.hs";
installPhase = ''
mkdir -p $out/bin
cp cmd_out.log cmd_err.log daemon_out.log daemon_err.log progress.log hardwareprogress.log power.log time.log $out/bin
'';
});
dev = env.overrideAttrs(old: {
buildInputs = old.buildInputs ++ [ (argopkgs.haskellPackages.ghcWithHoogle hpkgs-dev) ];
});
}
#! /usr/bin/env bash
nix-shell -A test --command "./argotk helloworld"
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