on master help sign in
Fixes #499 allowing packages to be installed to custom location.

When installing idris packages, specifying the command option `--ibcsubdir <dir>` will install the package to `<dir>`. This PR is to provide an option complimenting the env `TARGET` as the option `-i <path>` compliments `IDRIS_LIBRARY_PATH`. This option doesn't affect the other package commands, as they should be performed locale to the package source. Aside from test that goes to a temp directory.

commit0c517d61cd78a68950662750d5b209f0358d8ab4 authorJan de Muijnck-Hughes <jfdm@st-andrews.ac.uk> dateTue 29 Mar 2016, 14:35 (11 years ago) parent7daba78
3 files changed+53−42
CHANGELOG.md+5−3 src/Idris/REPL.hs+2−1 src/Pkg/Package.hs+46−38
CHANGELOG.md+5−3
@@ -3,9 +3,11 @@
33* Improved startup performance by reducing the processing of an already imported
44 module that has changed accessibility.
55
6−* A limited set of command line options can be used to override package declared
7− options. Overridable options are currently, logging level and categories,
8− default totality check, warn reach, IBC output folder, and idris path.
6+* A limited set of command line options can be used to override
7+ package declared options. Overridable options are currently, logging
8+ level and categories, default totality check, warn reach, IBC output
9+ folder, and idris path. Note overriding IBC output folder, only
10+ affects the installation of Idris packages.
911
1012* Remove deprecated options `--ideslave` and `--ideslave-socket`. These options
1113 were replaced with `--ide-mode` and `--ide-mode-socket` in 0.9.17
src/Idris/REPL.hs+2−1
@@ -2,7 +2,8 @@
22 PatternGuards, CPP #-}
33
44module Idris.REPL(getClient, getPkg, getPkgCheck, getPkgClean, getPkgMkDoc,
5− getPkgREPL, getPkgTest, getPort, idris, idrisMain, loadInputs,
5+ getPkgREPL, getPkgTest, getPort, getIBCSubDir,
6+ idris, idrisMain, loadInputs,
67 opt, runClient, runMain, ver) where
78
89import Idris.AbsSyntax
src/Pkg/Package.hs+46−38
@@ -17,8 +17,8 @@ import Control.Monad.Trans.Except (runExceptT)
1717
1818import Data.List
1919import Data.List.Split(splitOn)
20−
21−import Data.Either
20+import Data.Maybe(fromMaybe)
21+import Data.Either(partitionEithers)
2222
2323import Idris.Core.TT
2424import Idris.REPL
@@ -79,7 +79,7 @@ buildPkg copts warnonly (install, fp) = do
7979 case errSpan ist of
8080 Just _ -> exitWith (ExitFailure 1)
8181 _ -> return ()
82− when install $ installPkg pkgdesc
82+ when install $ installPkg (opt getIBCSubDir copts) pkgdesc
8383
8484-- --------------------------------------------------------- [ Check Packages ]
8585
@@ -254,14 +254,21 @@ testPkg copts fp = do
254254-- ----------------------------------------------------------- [ Installation ]
255255
256256-- | Install package
257−installPkg :: PkgDesc -> IO ()
258−installPkg pkgdesc
259− = inPkgDir pkgdesc $
260− do case (execout pkgdesc) of
261− Nothing -> do mapM_ (installIBC (pkgname pkgdesc)) (modules pkgdesc)
262− installIdx (pkgname pkgdesc)
263− Just o -> return () -- do nothing, keep executable locally, for noe
264− mapM_ (installObj (pkgname pkgdesc)) (objs pkgdesc)
257+installPkg :: [String] -- ^ Alternate install location
258+ -> PkgDesc -- ^ iPKG file.
259+ -> IO ()
260+installPkg altdests pkgdesc = inPkgDir pkgdesc $ do
261+ d <- getTargetDir
262+ let destdir = case altdests of
263+ [] -> d
264+ (d':_) -> d'
265+ case (execout pkgdesc) of
266+ Nothing -> do
267+ mapM_ (installIBC destdir (pkgname pkgdesc)) (modules pkgdesc)
268+ installIdx destdir (pkgname pkgdesc)
269+ Just o -> return () -- do nothing, keep executable locally, for noe
270+
271+ mapM_ (installObj destdir (pkgname pkgdesc)) (objs pkgdesc)
265272
266273-- ---------------------------------------------------------- [ Helper Methods ]
267274-- Methods for building, testing, installing, and removal of idris
@@ -305,33 +312,34 @@ rmExe p = do
305312toIBCFile (UN n) = str n ++ ".ibc"
306313toIBCFile (NS n ns) = foldl1' (</>) (reverse (toIBCFile n : map str ns))
307314
308−installIBC :: String -> Name -> IO ()
309−installIBC p m = do let f = toIBCFile m
310− d <- getTargetDir
311− let destdir = d </> p </> getDest m
312− putStrLn $ "Installing " ++ f ++ " to " ++ destdir
313− createDirectoryIfMissing True destdir
314− copyFile f (destdir </> takeFileName f)
315− return ()
316− where getDest (UN n) = ""
317− getDest (NS n ns) = foldl1' (</>) (reverse (getDest n : map str ns))
318−
319−installIdx :: String -> IO ()
320−installIdx p = do d <- getTargetDir
321− let f = pkgIndex p
322− let destdir = d </> p
323− putStrLn $ "Installing " ++ f ++ " to " ++ destdir
324− createDirectoryIfMissing True destdir
325− copyFile f (destdir </> takeFileName f)
326− return ()
327−
328−installObj :: String -> String -> IO ()
329−installObj p o = do d <- getTargetDir
330− let destdir = addTrailingPathSeparator (d </> p)
331− putStrLn $ "Installing " ++ o ++ " to " ++ destdir
332− createDirectoryIfMissing True destdir
333− copyFile o (destdir </> takeFileName o)
334− return ()
315+installIBC :: String -> String -> Name -> IO ()
316+installIBC dest p m = do
317+ let f = toIBCFile m
318+ let destdir = dest </> p </> getDest m
319+ putStrLn $ "Installing " ++ f ++ " to " ++ destdir
320+ createDirectoryIfMissing True destdir
321+ copyFile f (destdir </> takeFileName f)
322+ return ()
323+ where
324+ getDest (UN n) = ""
325+ getDest (NS n ns) = foldl1' (</>) (reverse (getDest n : map str ns))
326+
327+installIdx :: String -> String -> IO ()
328+installIdx dest p = do
329+ let f = pkgIndex p
330+ let destdir = dest </> p
331+ putStrLn $ "Installing " ++ f ++ " to " ++ destdir
332+ createDirectoryIfMissing True destdir
333+ copyFile f (destdir </> takeFileName f)
334+ return ()
335+
336+installObj :: String -> String -> String -> IO ()
337+installObj dest p o = do
338+ let destdir = addTrailingPathSeparator (dest </> p)
339+ putStrLn $ "Installing " ++ o ++ " to " ++ destdir
340+ createDirectoryIfMissing True destdir
341+ copyFile o (destdir </> takeFileName o)
342+ return ()
335343
336344#ifdef mingw32_HOST_OS
337345mkDirCmd = "mkdir "