Skip to content

Commit de5a79c

Browse files
author
Jan de Muijnck-Hughes
committed
Allow Idris to install IdrisDoc into a central location.
+ Default location is `<getDataDir>/docs`. + Flag `--info` has been updated to show doc location. + New flag `--installdoc <ipkg>` provided to install documentation + New flag `--docdir` provided to show documentation installation location. + New environment variable `IDRIS_DOC_PATH` to allow alternate means of customisation. + Installation for Idris' std libraries has been augmented to install library documentation as well.
1 parent 8ea8a38 commit de5a79c

File tree

15 files changed

+83
-39
lines changed

15 files changed

+83
-39
lines changed

Setup.hs

-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,6 @@ idrisInstall verbosity copy pkg local = unless (execOnly (configFlags local)) $
268268
notice verbosity $ unwords ["Copying man page to", mandest]
269269
installOrdinaryFiles verbosity mandest [("man", "idris.1")]
270270

271-
272271
makeInstall src target =
273272
make verbosity [ "-C", src, "install" , "TARGET=" ++ target, "IDRIS=" ++ idrisCmd local]
274273

libs/Makefile

-1
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,4 @@ doc_clean:
3434
$(MAKE) -C effects doc_clean
3535
$(MAKE) -C pruviloj doc_clean
3636

37-
3837
.PHONY: build install clean doc doc_clean

libs/base/Makefile

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ PKG := base
44
build:
55
$(IDRIS) --build ${PKG}.ipkg
66

7-
install:
7+
install:
88
$(IDRIS) --install ${PKG}.ipkg
9+
${IDRIS} --installdoc ${PKG}.ipkg
910

1011
clean:
1112
$(IDRIS) --clean ${PKG}.ipkg
@@ -21,4 +22,4 @@ doc_clean:
2122
linecount:
2223
find . -name '*.idr' | xargs wc -l
2324

24-
.PHONY: build install clean rebuild linecount
25+
.PHONY: build install clean rebuild linecount doc doc_clean

libs/contrib/Makefile

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ PKG := contrib
44
build:
55
$(IDRIS) --build ${PKG}.ipkg
66

7-
install:
7+
install:
88
$(IDRIS) --install ${PKG}.ipkg
9+
${IDRIS} --installdoc ${PKG}.ipkg
910

1011
clean:
1112
$(IDRIS) --clean ${PKG}.ipkg
@@ -21,4 +22,4 @@ doc_clean:
2122
linecount:
2223
find . -name '*.idr' | xargs wc -l
2324

24-
.PHONY: build install clean rebuild linecount
25+
.PHONY: build install clean rebuild linecount doc doc_clean

libs/effects/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ clean:
99

1010
install:
1111
$(IDRIS) --install ${PKG}.ipkg
12+
${IDRIS} --installdoc ${PKG}.ipkg
1213

1314
rebuild: clean build
1415

libs/prelude/Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ PKG := prelude
44
build:
55
$(IDRIS) --build ${PKG}.ipkg
66

7-
install:
7+
install:
88
$(IDRIS) --install ${PKG}.ipkg
9+
${IDRIS} --installdoc ${PKG}.ipkg
910

1011
clean:
1112
$(IDRIS) --clean ${PKG}.ipkg

libs/pruviloj/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ clean:
99

1010
install:
1111
$(IDRIS) --install ${PKG}.ipkg
12+
${IDRIS} --installdoc ${PKG}.ipkg
1213

1314
rebuild: clean build
1415

main/Main.hs

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ processShowOptions opts = runIO $ do
1818
when (ShowLoggingCats `elem` opts) $ showExitIdrisLoggingCategories
1919
when (ShowIncs `elem` opts) $ showExitIdrisFlagsInc
2020
when (ShowLibs `elem` opts) $ showExitIdrisFlagsLibs
21-
when (ShowLibdir `elem` opts) $ showExitIdrisLibDir
21+
when (ShowLibDir `elem` opts) $ showExitIdrisLibDir
22+
when (ShowDocDir `elem` opts) $ showExitIdrisDocDir
2223
when (ShowPkgs `elem` opts) $ showExitIdrisInstalledPackages
2324

2425
check :: [Opt] -> (Opt -> Maybe a) -> ([a] -> Idris ()) -> Idris ()

src/IRTS/System.hs

+17-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module IRTS.System( getDataFileName
1212
, getCC
1313
, getLibFlags
1414
, getIdrisLibDir
15+
, getIdrisDocDir
1516
, getIncFlags
1617
, getEnvFlags
1718
, version
@@ -31,23 +32,31 @@ import Paths_idris (version)
3132
import Paths_idris
3233
#endif
3334

34-
overrideDataDirWith :: String -> IO FilePath
35-
overrideDataDirWith envVar = do
35+
overrideIdrisDirWith :: String -- ^ Sub directory in `getDataDir` location.
36+
-> String -- ^ Environment variable to get new location from.
37+
-> IO FilePath
38+
overrideIdrisDirWith fp envVar = do
3639
envValue <- lookupEnv envVar
3740
case envValue of
3841
Nothing -> do
3942
ddir <- getDataDir
40-
return (ddir </> "libs")
43+
return (ddir </> fp)
4144
Just ddir -> return ddir
4245

46+
overrideIdrisLibDirWith :: String -> IO FilePath
47+
overrideIdrisLibDirWith = overrideIdrisDirWith "libs"
48+
49+
overrideIdrisDocDirWith :: String -> IO FilePath
50+
overrideIdrisDocDirWith = overrideIdrisDirWith "docs"
51+
4352
getCC :: IO String
4453
getCC = fromMaybe "gcc" <$> lookupEnv "IDRIS_CC"
4554

4655
getEnvFlags :: IO [String]
4756
getEnvFlags = maybe [] (splitOn " ") <$> lookupEnv "IDRIS_CFLAGS"
4857

4958
getTargetDir :: IO String
50-
getTargetDir = overrideDataDirWith "TARGET"
59+
getTargetDir = overrideIdrisLibDirWith "TARGET"
5160

5261
#if defined(freebsd_HOST_OS) || defined(dragonfly_HOST_OS)\
5362
|| defined(openbsd_HOST_OS) || defined(netbsd_HOST_OS)
@@ -68,7 +77,10 @@ getLibFlags = do dir <- getDataDir
6877
return $ ["-L" ++ (dir </> "rts"),
6978
"-lidris_rts"] ++ extraLib ++ gmpLib ++ ["-lpthread"]
7079

71-
getIdrisLibDir = addTrailingPathSeparator <$> overrideDataDirWith "IDRIS_LIBRARY_PATH"
80+
getIdrisLibDir = addTrailingPathSeparator <$> overrideIdrisLibDirWith "IDRIS_LIBRARY_PATH"
81+
82+
getIdrisDocDir = addTrailingPathSeparator <$> overrideIdrisDocDirWith "IDRIS_DOC_PATH"
83+
7284

7385
getIncFlags = do dir <- getDataDir
7486
return $ ("-I" ++ dir </> "rts") : extraInclude

src/Idris/AbsSyntax.hs

+5-4
Original file line numberDiff line numberDiff line change
@@ -2545,7 +2545,7 @@ getPkgDir (Pkg str) = Just str
25452545
getPkgDir _ = Nothing
25462546

25472547
getPkg :: Opt -> Maybe (Bool, String)
2548-
getPkg (PkgBuild str) = Just (False, str)
2548+
getPkg (PkgBuild str) = Just (False, str)
25492549
getPkg (PkgInstall str) = Just (True, str)
25502550
getPkg _ = Nothing
25512551

@@ -2563,9 +2563,10 @@ getPkgCheck _ = Nothing
25632563

25642564
-- | Returns None if given an Opt which is not PkgMkDoc
25652565
-- Otherwise returns Just x, where x is the contents of PkgMkDoc
2566-
getPkgMkDoc :: Opt -- ^ Opt to extract
2567-
-> Maybe String -- ^ Result
2568-
getPkgMkDoc (PkgMkDoc str) = Just str
2566+
getPkgMkDoc :: Opt -- ^ Opt to extract
2567+
-> Maybe (Bool, String) -- ^ Result
2568+
getPkgMkDoc (PkgDocBuild str) = Just (False,str)
2569+
getPkgMkDoc (PkgDocInstall str) = Just (True,str)
25692570
getPkgMkDoc _ = Nothing
25702571

25712572
getPkgTest :: Opt -- ^ the option to extract

src/Idris/AbsSyntaxTree.hs

+4-2
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,8 @@ data Opt = Filename String
492492
| IdemodeSocket
493493
| ShowAll
494494
| ShowLibs
495-
| ShowLibdir
495+
| ShowLibDir
496+
| ShowDocDir
496497
| ShowIncs
497498
| ShowPkgs
498499
| ShowLoggingCats
@@ -524,7 +525,8 @@ data Opt = Filename String
524525
| PkgClean String
525526
| PkgCheck String
526527
| PkgREPL String
527-
| PkgMkDoc String -- IdrisDoc
528+
| PkgDocBuild String -- IdrisDoc
529+
| PkgDocInstall String
528530
| PkgTest String
529531
| PkgIndex FilePath
530532
| WarnOnly

src/Idris/CmdOptions.hs

+10-8
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ parseFlags = many $
129129
<|> flag' ShowLoggingCats (long "listlogcats" <> help "Display logging categories")
130130
<|> flag' ShowLibs (long "link" <> help "Display link flags")
131131
<|> flag' ShowPkgs (long "listlibs" <> help "Display installed libraries")
132-
<|> flag' ShowLibdir (long "libdir" <> help "Display library directory")
132+
<|> flag' ShowLibDir (long "libdir" <> help "Display library directory")
133+
<|> flag' ShowDocDir (long "docdir" <> help "Display idrisdoc install directory")
133134
<|> flag' ShowIncs (long "include" <> help "Display the includes flags")
134135

135136
<|> flag' Verbose (short 'V' <> long "verbose" <> help "Loud verbosity")
@@ -144,13 +145,14 @@ parseFlags = many $
144145
<|> (Port <$> option portReader (long "port" <> metavar "PORT" <> help "REPL TCP port - pass \"none\" to not bind any port"))
145146

146147
-- Package commands
147-
<|> (PkgBuild <$> strOption (long "build" <> metavar "IPKG" <> help "Build package"))
148-
<|> (PkgInstall <$> strOption (long "install" <> metavar "IPKG" <> help "Install package"))
149-
<|> (PkgREPL <$> strOption (long "repl" <> metavar "IPKG" <> help "Launch REPL, only for executables"))
150-
<|> (PkgClean <$> strOption (long "clean" <> metavar "IPKG" <> help "Clean package"))
151-
<|> (PkgMkDoc <$> strOption (long "mkdoc" <> metavar "IPKG" <> help "Generate IdrisDoc for package"))
152-
<|> (PkgCheck <$> strOption (long "checkpkg" <> metavar "IPKG" <> help "Check package only"))
153-
<|> (PkgTest <$> strOption (long "testpkg" <> metavar "IPKG" <> help "Run tests for package"))
148+
<|> (PkgBuild <$> strOption (long "build" <> metavar "IPKG" <> help "Build package"))
149+
<|> (PkgInstall <$> strOption (long "install" <> metavar "IPKG" <> help "Install package"))
150+
<|> (PkgREPL <$> strOption (long "repl" <> metavar "IPKG" <> help "Launch REPL, only for executables"))
151+
<|> (PkgClean <$> strOption (long "clean" <> metavar "IPKG" <> help "Clean package"))
152+
<|> (PkgDocBuild <$> strOption (long "mkdoc" <> metavar "IPKG" <> help "Generate IdrisDoc for package"))
153+
<|> (PkgDocInstall <$> strOption (long "installdoc" <> metavar "IPKG" <> help "Install IdrisDoc for package"))
154+
<|> (PkgCheck <$> strOption (long "checkpkg" <> metavar "IPKG" <> help "Check package only"))
155+
<|> (PkgTest <$> strOption (long "testpkg" <> metavar "IPKG" <> help "Run tests for package"))
154156

155157
-- Misc options
156158
<|> (BCAsm <$> strOption (long "bytecode"))

src/Idris/Info.hs

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Maintainer : The Idris Community.
77
-}
88
module Idris.Info
99
( getIdrisLibDir
10+
, getIdrisDocDir
1011
, getIdrisFlagsLib
1112
, getIdrisFlagsInc
1213
, getIdrisFlagsEnv
@@ -33,6 +34,9 @@ import Version_idris (gitHash)
3334

3435
import Paths_idris
3536

37+
getIdrisDocDir :: IO String
38+
getIdrisDocDir = S.getIdrisDocDir
39+
3640
getIdrisLibDir :: IO String
3741
getIdrisLibDir = S.getIdrisLibDir
3842

src/Idris/Info/Show.hs

+12
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ showExitIdrisLibDir = do
2424
showIdrisLibDir
2525
exitSuccess
2626

27+
showIdrisDocDir :: IO ()
28+
showIdrisDocDir = do
29+
ldir <- getIdrisDocDir
30+
putStrLn ldir
31+
32+
showExitIdrisDocDir :: IO ()
33+
showExitIdrisDocDir = do
34+
showIdrisDocDir
35+
exitSuccess
36+
2737
showIdrisFlagsInc :: IO ()
2838
showIdrisFlagsInc = do
2939
incFlags <- getIdrisFlagsInc
@@ -68,8 +78,10 @@ showIdrisInfo = do
6878
putStrLn "Paths:"
6979
ldir <- getIdrisLibDir
7080
udir <- getIdrisUserDataDir
81+
ddir <- getIdrisDocDir
7182
putStrLn $ unwords ["-", "Library Dir:", ldir]
7283
putStrLn $ unwords ["-", "User Dir:", udir]
84+
putStrLn $ unwords ["-", "Documentation Dir:", ddir]
7385

7486
putStrLn "Flags:"
7587
lflag <- getIdrisFlagsLib

src/Idris/Package.hs

+19-12
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,10 @@ cleanPkg copts fp = do
190190
--
191191
-- Issue number #1572 on the issue tracker
192192
-- https://github.com/idris-lang/Idris-dev/issues/1572
193-
documentPkg :: [Opt] -- ^ Command line options.
194-
-> FilePath -- ^ Path to ipkg file.
193+
documentPkg :: [Opt] -- ^ Command line options.
194+
-> (Bool,FilePath) -- ^ (Should we install?, Path to ipkg file).
195195
-> IO ()
196-
documentPkg copts fp = do
196+
documentPkg copts (install,fp) = do
197197
pkgdesc <- parseDesc fp
198198
cd <- getCurrentDirectory
199199
let pkgDir = cd </> takeDirectory fp
@@ -223,7 +223,13 @@ documentPkg copts fp = do
223223
putStrLn $ pshow idrisInit err
224224
exitWith (ExitFailure 1)
225225
Right ist -> do
226-
docRes <- generateDocs ist mods outputDir
226+
iDocDir <- getIdrisDocDir
227+
pkgDocDir <- makeAbsolute (iDocDir </> pkgname pkgdesc)
228+
let out_dir = if install then pkgDocDir else outputDir
229+
when install $ do
230+
putStrLn $ unwords ["Attempting to install IdrisDocs for", pkgname pkgdesc, "in:", out_dir]
231+
232+
docRes <- generateDocs ist mods out_dir
227233
case docRes of
228234
Right _ -> return ()
229235
Left msg -> do
@@ -416,14 +422,15 @@ mergeOptions copts popts =
416422
normaliseOpts = filter filtOpt
417423

418424
filtOpt :: Opt -> Bool
419-
filtOpt (PkgBuild _) = False
420-
filtOpt (PkgInstall _) = False
421-
filtOpt (PkgClean _) = False
422-
filtOpt (PkgCheck _) = False
423-
filtOpt (PkgREPL _) = False
424-
filtOpt (PkgMkDoc _) = False
425-
filtOpt (PkgTest _) = False
426-
filtOpt _ = True
425+
filtOpt (PkgBuild _) = False
426+
filtOpt (PkgInstall _) = False
427+
filtOpt (PkgClean _) = False
428+
filtOpt (PkgCheck _) = False
429+
filtOpt (PkgREPL _) = False
430+
filtOpt (PkgDocBuild _) = False
431+
filtOpt (PkgDocInstall _) = False
432+
filtOpt (PkgTest _) = False
433+
filtOpt _ = True
427434

428435
chkOpt :: Opt -> Either String Opt
429436
chkOpt o@(OLogging _) = Right o

0 commit comments

Comments
 (0)