@@ -14,7 +14,7 @@ module Obelisk.Command.Run where
1414import Control.Arrow ((&&&))
1515import Control.Exception (Exception, bracket)
1616import Control.Lens (ifor, (.~), (&))
17−import Control.Monad (filterM, unless)
17+import Control.Monad (filterM)
1818import Control.Monad.Except (runExceptT, throwError)
1919import Control.Monad.IO.Class (liftIO)
2020import Control.Monad.Reader (MonadIO)
@@ -304,15 +304,16 @@ parseCabalPackage
304304 -> m (Maybe CabalPackageInfo)
305305parseCabalPackage dir = parseCabalPackage' dir >>= \case
306306 Left err -> Nothing <$ putLog Error err
307− Right (warnings, pkgInfo) -> do
307+ Right (Just (warnings, pkgInfo)) -> do
308308 for_ warnings $ putLog Warning . T.pack . show
309309 pure $ Just pkgInfo
310+ Right Nothing -> pure Nothing
310311
311312-- | Like 'parseCabalPackage' but returns errors and warnings directly so as to avoid 'MonadObelisk'.
312313parseCabalPackage'
313314 :: (MonadIO m)
314315 => FilePath -- ^ Package directory
315− -> m (Either T.Text ([Dist.PWarning], CabalPackageInfo))
316+ -> m (Either T.Text (Maybe ([Dist.PWarning], CabalPackageInfo)))
316317parseCabalPackage' pkg = runExceptT $ do
317318 (cabalContents, packageFile, packageName) <- guessCabalPackageFile pkg >>= \case
318319 Left GuessPackageFileError_NotFound -> throwError $ "No .cabal or package.yaml file found in " <> T.pack pkg
@@ -340,7 +341,7 @@ parseCabalPackage' pkg = runExceptT $ do
340341 case condLibrary <$> result of
341342 Right (Just condLib) -> do
342343 let (_, lib) = simplifyCondTree evalConfVar condLib
343− pure $ (warnings,) $ CabalPackageInfo
344+ pure $ Just $ (warnings,) $ CabalPackageInfo
344345 { _cabalPackageInfo_packageName = T.pack packageName
345346 , _cabalPackageInfo_packageFile = packageFile
346347 , _cabalPackageInfo_packageRoot = takeDirectory packageFile
@@ -354,17 +355,17 @@ parseCabalPackage' pkg = runExceptT $ do
354355 , _cabalPackageInfo_compilerOptions = options $ libBuildInfo lib
355356 , _cabalPackageInfo_cppOptions = cppOptions $ libBuildInfo lib
356357 }
357− Right Nothing -> throwError "Haskell package has no library component"
358+ Right Nothing -> pure Nothing
358359 Left (_, errors) ->
359360 throwError $ T.pack $ "Failed to parse " <> packageFile <> ":\n" <> unlines (map show errors)
360361
361362parsePackagesOrFail :: (MonadObelisk m, Foldable f) => f FilePath -> m (NE.NonEmpty CabalPackageInfo)
362363parsePackagesOrFail dirs' = do
363− (pkgDirErrs, packageInfos') <- fmap partitionEithers $ for dirs $ \dir -> do
364+ packageInfos' <- fmap catMaybes $ for dirs $ \dir -> do
364365 flip fmap (parseCabalPackage dir) $ \case
365366 Just packageInfo
366− | _cabalPackageInfo_buildable packageInfo -> Right packageInfo
367− _ -> Left dir
367+ | _cabalPackageInfo_buildable packageInfo -> Just packageInfo
368+ _ -> Nothing
368369
369370 -- Sort duplicate packages such that we prefer shorter paths, but fall back to alphabetical ordering.
370371 let packagesByName = Map.map (NE.sortBy $ comparing $ \p -> let n = _cabalPackageInfo_packageFile p in (length n, n))
@@ -386,9 +387,6 @@ parsePackagesOrFail dirs' = do
386387 "No valid, buildable packages found" <> (if null dirs then "" else " in " <> intercalate ", " dirs)
387388 Just xs -> pure xs
388389
389− unless (null pkgDirErrs) $
390− putLog Warning $ T.pack $ "Failed to find buildable packages in " <> intercalate ", " pkgDirErrs
391−
392390 pure packageInfos
393391 where
394392 dirs = toList dirs'