| 1 | From 457bc7438a4f0801dbf332fa2369248bddf5da0c Mon Sep 17 00:00:00 2001
|
| 2 | Message-Id: <457bc7438a4f0801dbf332fa2369248bddf5da0c.1678309546.git.dev@jpoiret.xyz>
|
| 3 | From: Josselin Poiret <[email protected]>
|
| 4 | Date: Wed, 8 Mar 2023 18:31:52 +0100
|
| 5 | Subject: [PATCH] Add environment variable for library directories
|
| 6 |
|
| 7 | AGDA_LIBDIRS is a new environment colon-separated variable for site libraries.
|
| 8 | Agda will look for .agda-lib files directly inside direct descendants of these.
|
| 9 | ---
|
| 10 | src/full/Agda/Interaction/Library.hs | 16 ++++++++++++++--
|
| 11 | 1 file changed, 14 insertions(+), 2 deletions(-)
|
| 12 |
|
| 13 | diff --git a/src/full/Agda/Interaction/Library.hs b/src/full/Agda/Interaction/Library.hs
|
| 14 | index 09c1f2a82..774cc3e74 100644
|
| 15 | |
| 16 | |
| 17 | @@ -323,13 +323,25 @@ getInstalledLibraries overrideLibFile = mkLibM [] $ do
|
| 18 | raiseErrors' [ LibrariesFileNotFound theOverrideLibFile ]
|
| 19 | return []
|
| 20 | Right file -> do
|
| 21 | - if not (lfExists file) then return [] else do
|
| 22 | + siteLibDirs <- liftIO $ fromMaybe [] . fmap splitAtColon . lookup "AGDA_LIBDIRS" <$> getEnvironment
|
| 23 | + siteLibs <- liftIO $ concat <$> mapM findSiteLibs siteLibDirs
|
| 24 | + if not (lfExists file) then parseLibFiles Nothing $ nubOn snd ((0,) <$> siteLibs) else do
|
| 25 | ls <- liftIO $ stripCommentLines <$> UTF8.readFile (lfPath file)
|
| 26 | files <- liftIO $ sequence [ (i, ) <$> expandEnvironmentVariables s | (i, s) <- ls ]
|
| 27 | - parseLibFiles (Just file) $ nubOn snd files
|
| 28 | + parseLibFiles (Just file) $ nubOn snd (files ++ fmap (0,) siteLibs)
|
| 29 | `catchIO` \ e -> do
|
| 30 | raiseErrors' [ ReadError e "Failed to read installed libraries." ]
|
| 31 | return []
|
| 32 | + where splitAtColon :: String -> [String]
|
| 33 | + splitAtColon "" = []
|
| 34 | + splitAtColon str = case break (==':') str of
|
| 35 | + (a, _:b) -> a : splitAtColon b
|
| 36 | + (a, "") -> [a]
|
| 37 | + findSiteLibs :: String -> IO [String]
|
| 38 | + findSiteLibs dir = do
|
| 39 | + subDirs <- filterM doesDirectoryExist =<< map (dir </>) <$> listDirectory dir
|
| 40 | + subFiles <- mapM (\dir -> map (dir </>) <$> listDirectory dir) subDirs
|
| 41 | + return $ concatMap (filter (List.isSuffixOf ".agda-lib")) subFiles
|
| 42 |
|
| 43 | -- | Parse the given library files.
|
| 44 | --
|
| 45 |
|
| 46 | base-commit: 183534bc41af5a53daf685122997dc98883f2be2
|
| 47 | --
|
| 48 | 2.39.1
|
| 49 |
|