dependencies :: FilePath -> IO [Dep]
dependencies = fmap (reverse . nub) . go mempty <=< canonicalizePath
  where
    go memo dir = do
        let path = dir </> "Intfile"
        if not (path `Set.member` memo)
            then do
                logDebug $ "Loading " ++ dir ++ " ..."
                p <- doesFileExist path
                with dir $
                    load memo path p
            else do
                logDebug $ "Already loaded " ++ dir ++ ", skipping."
                return []

    with path f =
        bracket getCurrentDirectory setCurrentDirectory
            (const $ setCurrentDirectory path >> f)

    load _    _    False = return []
    load memo path True  = do
        logDebug $ "Reading " ++ path ++ " ..."
        xs <- decodeYAML path >>= mapM canonicalise
        ys <- concat <$> mapM (go (Set.insert path memo) . depPath) xs
        return $! xs ++ ys

    canonicalise d = (\p -> d { depPath = p }) <$> canonicalizePath (depPath d)
dependencies :: FilePath -> IO [Dep]
dependencies = fmap (reverse . nub) . go mempty <=< canonicalizePath
  where
    go memo dir = do
        let path = dir </> "Intfile"
        if not (path `Set.member` memo)
            then do
                logDebug $ "Loading " ++ dir ++ " ..."
                p <- doesFileExist path
                with dir $
                    load memo path p
            else do
                logDebug $ "Already loaded " ++ dir ++ ", skipping."
                return []

    with path f =
        bracket getCurrentDirectory setCurrentDirectory
            (const $ setCurrentDirectory path >> f)

    load _    _    False = return []
    load memo path True  = do
        logDebug $ "Reading " ++ path ++ " ..."
        xs <- decodeYAML path >>= mapM canonicalise
        ys <- concat <$> mapM (go (Set.insert path memo) . depPath) xs
        return $! xs ++ ys

    canonicalise d = (\p -> d { depPath = p }) <$> canonicalizePath (depPath d)
dependencies = fmap (reverse . nub) . go mempty <=< canonicalizePath
  where
    go memo dir = do
        let path = dir </> "Intfile"
        if not (path `Set.member` memo)
            then do
                logDebug $ "Loading " ++ dir ++ " ..."
                p <- doesFileExist path
                with dir $
                    load memo path p
            else do
                logDebug $ "Already loaded " ++ dir ++ ", skipping."
                return []

    with path f =
        bracket getCurrentDirectory setCurrentDirectory
            (const $ setCurrentDirectory path >> f)

    load _    _    False = return []
    load memo path True  = do
        logDebug $ "Reading " ++ path ++ " ..."
        xs <- decodeYAML path >>= mapM canonicalise
        ys <- concat <$> mapM (go (Set.insert path memo) . depPath) xs
        return $! xs ++ ys

    canonicalise d = (\p -> d { depPath = p }) <$> canonicalizePath (depPath d)