From 064e1f7db66db4bfa0cbcc8b3326cc05733e56fd Mon Sep 17 00:00:00 2001 From: Nick Dunets Date: Tue, 7 Jul 2020 15:59:47 +1200 Subject: [PATCH 1/2] - added --cabal and --stack switches to command line, - generated sample hie.yaml for this project both for Stack and Cabal --- app/Main.hs | 25 ++++++++++++++++++------- hie.yaml.cabal | 12 ++++++++++++ hie.yaml.stack | 12 ++++++++++++ 3 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 hie.yaml.cabal create mode 100644 hie.yaml.stack diff --git a/app/Main.hs b/app/Main.hs index 361e09e..713ccb1 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -15,17 +15,12 @@ import Hie.Yaml import System.Directory import System.Directory.Internal import System.FilePath.Posix +import System.Environment main :: IO () main = do pwd <- getCurrentDirectory - files <- listDirectory pwd - let name = - if | any (("dist-newstyle" ==) . takeFileName) files -> "cabal" - | any ((".stack-work" ==) . takeFileName) files -> "stack" - | any (("cabal.project" ==) . takeFileName) files -> "cabal" - | any (("stack.yaml" ==) . takeFileName) files -> "stack" - | otherwise -> "cabal" + name <- resolveName pwd cfs <- runMaybeT $ case name of "cabal" -> cabalPkgs pwd _ -> stackYamlPkgs pwd @@ -35,3 +30,19 @@ main = do <> "\n You may need to run stack build." pkgs <- catMaybes <$> mapM (nestedPkg pwd) (concat cfs) putStr <$> hieYaml name $ fmtPkgs name pkgs + +resolveName :: FilePath -> IO String +resolveName pwd = do + args <- getArgs + files <- listDirectory pwd + let fileNames = map takeFileName files + name = + if | "--cabal" `elem` args -> "cabal" + | "--stack" `elem` args -> "stack" + | "dist-newstyle" `elem` fileNames -> "cabal" + | ".stack-work" `elem` fileNames -> "stack" + | "cabal.project" `elem` fileNames -> "cabal" + | "stack.yaml" `elem` fileNames -> "stack" + | otherwise -> "cabal" + return name + diff --git a/hie.yaml.cabal b/hie.yaml.cabal new file mode 100644 index 0000000..37e56b2 --- /dev/null +++ b/hie.yaml.cabal @@ -0,0 +1,12 @@ +# Rename this file to hie.yaml to open this project in HIE and use Cabal as build system + +cradle: + cabal: + - path: "src" + component: "lib:implicit-hie" + + - path: "app/Main.hs" + component: "implicit-hie:exe:gen-hie" + + - path: "test" + component: "implicit-hie:test:implicit-hie-test" diff --git a/hie.yaml.stack b/hie.yaml.stack new file mode 100644 index 0000000..3edc328 --- /dev/null +++ b/hie.yaml.stack @@ -0,0 +1,12 @@ +# Rename this file to hie.yaml to open this project in HIE and use Stack as build system + +cradle: + stack: + - path: "./src" + component: "implicit-hie:lib" + + - path: "./app/Main.hs" + component: "implicit-hie:exe:gen-hie" + + - path: "./test" + component: "implicit-hie:test:implicit-hie-test" From a6c91a83b61ecfc3d36460a089ae50981f711506 Mon Sep 17 00:00:00 2001 From: Nick Dunets Date: Tue, 7 Jul 2020 16:16:12 +1200 Subject: [PATCH 2/2] change extension of sample hie cabal file --- hie.yaml.cabal => hie.yaml.cbl | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename hie.yaml.cabal => hie.yaml.cbl (100%) diff --git a/hie.yaml.cabal b/hie.yaml.cbl similarity index 100% rename from hie.yaml.cabal rename to hie.yaml.cbl