diff options
Diffstat (limited to 'lib/Distribution')
-rw-r--r-- | lib/Distribution/Helper/Discover.hs | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/lib/Distribution/Helper/Discover.hs b/lib/Distribution/Helper/Discover.hs index d4abe69..a748b25 100644 --- a/lib/Distribution/Helper/Discover.hs +++ b/lib/Distribution/Helper/Discover.hs @@ -14,6 +14,8 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see <http://www.gnu.org/licenses/>. +{-# LANGUAGE GADTs #-} + {-| Module : Distribution.Helper.Discover Description : Finding project contexts @@ -30,12 +32,44 @@ module Distribution.Helper.Discover , findDistDirsWithHints ) where +import Control.Monad.Writer +import Data.List +import System.Directory +import System.FilePath + import CabalHelper.Compiletime.Types +import CabalHelper.Compiletime.Cabal +import CabalHelper.Compiletime.Compat.Directory findProjects :: FilePath -> IO [Ex ProjLoc] findDistDirs :: ProjLoc pt -> [DistDir pt] findDistDirsWithHints :: ProjLoc pt -> [FilePath] -> [DistDir pt] -findProjects = undefined -findDistDirs = undefined +findProjects dir = execWriterT $ do + let cabalProject = dir </> "cabal.project" + whenM (liftIO $ doesFileExist cabalProject) $ + tell [Ex $ ProjLocV2File cabalProject] + let stackYaml = dir </> "stack.yaml" + whenM (liftIO $ doesFileExist stackYaml) $ + tell [Ex $ ProjLocStackYaml stackYaml] + join $ traverse (tell . pure . Ex . ProjLocV1CabalFile) <$> + liftIO (findCabalFiles dir) + +findDistDirs (ProjLocV1CabalFile cabal) = + [DistDirV1 $ replaceFileName cabal "dist/"] +findDistDirs (ProjLocV1Dir dir) = [DistDirV1 $ dir </> "dist/"] +findDistDirs (ProjLocV2File cabal) = + [DistDirV2 $ replaceFileName cabal "dist-newstyle/"] +findDistDirs (ProjLocV2Dir dir) = [DistDirV2 $ dir </> "dist-newstyle/"] +findDistDirs (ProjLocStackYaml _) = [DistDirStack Nothing] + findDistDirsWithHints = undefined + +findCabalFiles :: FilePath -> IO [FilePath] +findCabalFiles dir = do + fs <- listDirectory dir + let cs = filter (".cabal" `isSuffixOf`) fs + filterM doesFileExist cs + +whenM :: Monad m => m Bool -> m () -> m () +whenM p x = p >>= (`when` x) |