on master help sign in
Ignore .attr-cache symlinks when searching for packages in ob run
commit24df4b577a09969edb4640bf304bb5901951328f authorElliot Cameron <eacameron@gmail.com> dateFri 31 Jan 2020, 15:18 (7 years ago) parenta019483
2 files changed+15−5
lib/command/src/Obelisk/Command/Run.hs+7−1 lib/command/src/Obelisk/Command/Thunk.hs+8−4
lib/command/src/Obelisk/Command/Run.hs+7−1
@@ -49,6 +49,7 @@ import System.IO.Temp (withSystemTempDirectory)
4949import Obelisk.App (MonadObelisk)
5050import Obelisk.CliApp (Severity (..) , failWith, putLog, proc, readCreateProcessWithExitCode, readProcessAndLogStderr)
5151import Obelisk.Command.Project (obeliskDirName, toObeliskDir, withProjectRoot, nixShellWithPkgs, toNixPath)
52+import Obelisk.Command.Thunk (attrCacheFileName)
5253import Obelisk.Command.Utils (findExePath, ghcidExePath, nixBuildExePath, nixExePath)
5354
5455data CabalPackageInfo = CabalPackageInfo
@@ -131,7 +132,12 @@ getLocalPkgs root = do
131132 let
132133 -- We ignore any path that has ".obelisk" in it, but keep the root ".obelisk" paths
133134 packagePaths = filter (not . isIgnored) $ map T.unpack $ T.lines $ T.strip $ T.pack out
134− isIgnored path = obeliskDirName `elem` dropPrefix (splitPath $ toObeliskDir root) (splitPath path)
135+ isIgnored path =
136+ obeliskDirName `elem` dropPrefix (splitPath $ toObeliskDir root) pathSegments
137+ && attrCacheFileName `notElem` pathSegments
138+ where
139+ pathSegments = splitPath path
140+
135141 pure packagePaths
136142
137143data GuessPackageFileError = GuessPackageFileError_Ambiguous [FilePath] | GuessPackageFileError_NotFound
lib/command/src/Obelisk/Command/Thunk.hs+8−4
@@ -18,6 +18,7 @@ module Obelisk.Command.Thunk
1818 , ThunkRev (..)
1919 , ThunkSource (..)
2020 , ThunkUpdateConfig (..)
21+ , attrCacheFileName
2122 , createThunk
2223 , createThunkWithLatest
2324 , getLatestRev
@@ -231,6 +232,9 @@ readThunk thunkDir = do
231232 False -> return $ return Nothing
232233 False -> liftIO $ fmap ThunkData_Packed <$> readPackedThunk thunkDir
233234
235+attrCacheFileName :: FilePath
236+attrCacheFileName = ".attr-cache"
237+
234238data ThunkType = ThunkType
235239 { _thunkType_loader :: FilePath
236240 , _thunkType_json :: FilePath
@@ -243,7 +247,7 @@ gitHubThunkType :: ThunkType
243247gitHubThunkType = ThunkType
244248 { _thunkType_loader = "default.nix"
245249 , _thunkType_json = "github.json"
246− , _thunkType_optional = Set.fromList [".attr-cache"]
250+ , _thunkType_optional = Set.fromList [attrCacheFileName]
247251 , _thunkType_loaderVersions = gitHubStandaloneLoaders
248252 , _thunkType_parser = parseThunkPtr $ \v ->
249253 ThunkSource_GitHub <$> parseGitHubSource v <|> ThunkSource_Git <$> parseGitSource v
@@ -253,7 +257,7 @@ gitThunkType :: ThunkType
253257gitThunkType = ThunkType
254258 { _thunkType_loader = "default.nix"
255259 , _thunkType_json = "git.json"
256− , _thunkType_optional = Set.fromList [".attr-cache"]
260+ , _thunkType_optional = Set.fromList [attrCacheFileName]
257261 , _thunkType_loaderVersions = plainGitStandaloneLoaders
258262 , _thunkType_parser = parseThunkPtr $ fmap ThunkSource_Git . parseGitSource
259263 }
@@ -400,7 +404,7 @@ encodeThunkPtrData (ThunkPtr rev src) = case src of
400404
401405createThunk :: MonadIO m => FilePath -> ThunkPtr -> m ()
402406createThunk target thunk = liftIO $ do
403− createDirectoryIfMissing True (target </> ".attr-cache")
407+ createDirectoryIfMissing True (target </> attrCacheFileName)
404408 T.writeFile (target </> "default.nix") (thunkPtrLoader thunk)
405409 let
406410 jsonFileName = case _thunkPtr_source thunk of
@@ -574,7 +578,7 @@ nixBuildThunkAttrWithCache thunkDir attr = do
574578 let cacheErrHandler e
575579 | isDoesNotExistError e = return Nothing -- expected from a cache miss
576580 | otherwise = putLog Error (T.pack $ displayException e) >> return Nothing
577− cacheDir = thunkDir </> ".attr-cache"
581+ cacheDir = thunkDir </> attrCacheFileName
578582 cachePath = cacheDir </> attr <.> "out"
579583 latestChange <- liftIO $ do
580584 createDirectoryIfMissing False cacheDir