@@ -15,7 +15,6 @@ import Control.Monad.Reader (MonadIO)
1515import Data.Coerce (coerce)
1616import Data.Either
1717import Data.Foldable (for_, toList)
18−import Data.List.Extra (dropPrefix)
1918import qualified Data.List.NonEmpty as NE
2019import Data.Map (Map)
2120import qualified Data.Map as Map
@@ -48,8 +47,7 @@ import System.IO.Temp (withSystemTempDirectory)
4847
4948import Obelisk.App (MonadObelisk)
5049import Obelisk.CliApp (Severity (..) , failWith, putLog, proc, readCreateProcessWithExitCode, readProcessAndLogStderr)
51−import Obelisk.Command.Project (obeliskDirName, toObeliskDir, withProjectRoot, nixShellWithPkgs, toNixPath)
52−import Obelisk.Command.Thunk (attrCacheFileName)
50+import Obelisk.Command.Project (withProjectRoot, nixShellWithPkgs, toNixPath)
5351import Obelisk.Command.Utils (findExePath, ghcidExePath, nixBuildExePath, nixExePath)
5452
5553data CabalPackageInfo = CabalPackageInfo
@@ -125,20 +123,19 @@ runWatch = withProjectRoot "." $ \root -> do
125123-- to the Nix @project@ function.
126124getLocalPkgs :: MonadObelisk m => FilePath -> m [FilePath]
127125getLocalPkgs root = do
128− (_exitCode, out, err) <- readCreateProcessWithExitCode $
129− proc findExePath ["-L", root, "(", "-name", "*.cabal", "-o", "-name", Hpack.packageConfig, ")", "-a", "-type", "f"]
130− putLog Debug $ T.strip $ T.pack err
126+ obeliskPaths <- runFind ["-L", root, "-name", ".obelisk", "-type", "d"]
131127
132− let
133− -- We ignore any path that has ".obelisk" in it, but keep the root ".obelisk" paths
134− packagePaths = filter (not . isIgnored) $ map T.unpack $ T.lines $ T.strip $ T.pack out
135− isIgnored path =
136− obeliskDirName `elem` dropPrefix (splitPath $ toObeliskDir root) pathSegments
137− && attrCacheFileName `notElem` pathSegments
138− where
139− pathSegments = splitPath path
140−
141− pure packagePaths
128+ -- We do not want to find packages that are embedded inside other obelisk projects, unless that
129+ -- obelisk project is our own.
130+ let exclusions = filter (/= root) $ map takeDirectory obeliskPaths
131+ runFind $
132+ ["-L", root, "(", "-name", "*.cabal", "-o", "-name", Hpack.packageConfig, ")", "-a", "-type", "f"]
133+ <> concat [["-not", "-path", p </> "*"] | p <- exclusions]
134+ where
135+ runFind args = do
136+ (_exitCode, out, err) <- readCreateProcessWithExitCode $ proc findExePath args
137+ putLog Debug $ T.strip $ T.pack err
138+ pure $ map T.unpack $ T.lines $ T.strip $ T.pack out
142139
143140data GuessPackageFileError = GuessPackageFileError_Ambiguous [FilePath] | GuessPackageFileError_NotFound
144141 deriving (Eq, Ord, Show)