cabal-dir (empty) → 0.1.0.0
raw patch · 4 files changed
+159/−0 lines, 4 filesdep +Cabaldep +basedep +directorysetup-changed
Dependencies added: Cabal, base, directory
Files
- LICENSE +30/−0
- Setup.hs +2/−0
- cabal-dir.cabal +44/−0
- cabal-dir.hs +83/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2013, Yoshikuni Jujo <PAF01143@nifty.ne.jp>++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Yoshikuni Jujo <PAF01143@nifty.ne.jp> nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ cabal-dir.cabal view
@@ -0,0 +1,44 @@+-- Initial cabal-dir.cabal generated by cabal init. For further +-- documentation, see http://haskell.org/cabal/users-guide/++name: cabal-dir+version: 0.1.0.0+stability: Experimental+synopsis: show dist dir of 'cabal copy/install'+description: + show dist dir of 'cabal copy/install'+ .+ > % cabal configure+ > % cabal-dir+ > bindir : /usr/local/bin+ > libdir : /usr/local/lib/foo-0.1.2.3/ghc-8.8.8+ > datadir: /usr/local/share/foo-0.1.2.3+ > htmldir: /usr/local/share/doc/foo-0.1.2.3/html+ >+ > % cabal-dir /usr/local+ > bindir : bin+ > libdir : lib/foo-0.1.2.3/ghc-8.8.8+ > datadir: share/foo-0.1.2.3+ > htmldir: share/doc/foo-0.1.2.3/html+license: BSD3+license-file: LICENSE+author: Yoshikuni Jujo <PAF01143@nifty.ne.jp>+maintainer: Yoshikuni Jujo <PAF01143@nifty.ne.jp>+-- copyright: +category: Distribution+build-type: Simple+cabal-version: >=1.8++source-repository head+ type: git+ location: git://github.com/YoshikuniJujo/cabal-dir.git++source-repository this+ type: git+ location: git://github.com/YoshikuniJujo/cabal-dir.git+ tag: 0.1.0.0++executable cabal-dir+ main-is: cabal-dir.hs+ -- other-modules: + build-depends: base > 3 && < 5, directory, Cabal
+ cabal-dir.hs view
@@ -0,0 +1,83 @@+import Distribution.Simple.LocalBuildInfo(+ LocalBuildInfo, CopyDest(..), absoluteInstallDirs)+import qualified Distribution.Simple.LocalBuildInfo as LBI+import Control.Applicative++import Distribution.PackageDescription.Parse+import Distribution.PackageDescription+import Distribution.Verbosity++import Distribution.Package+import Distribution.Version++import System.Directory+import Data.List++import System.Environment++data InstallDirs = InstallDirs {+ bindir :: FilePath,+ libdir :: FilePath,+ datadir :: FilePath,+ htmldir :: FilePath+ } deriving Show++getLocalBuildInfo :: IO LocalBuildInfo+getLocalBuildInfo = read . (!! 1) . lines <$> readFile "./dist/setup-config"++getPackageDescription :: IO PackageDescription+getPackageDescription = packageDescription <$>+ (readPackageDescription silent =<< getCabalFile)++getCabalFile :: IO FilePath+getCabalFile =+ head . filter (".cabal" `isSuffixOf`) <$> getDirectoryContents "."++getInstallDirs :: IO InstallDirs+getInstallDirs = do+ lbi <- getLocalBuildInfo+ pd <- getPackageDescription+ let dirs = absoluteInstallDirs pd lbi NoCopyDest+ return $ InstallDirs {+ bindir = LBI.bindir dirs,+ libdir = LBI.libdir dirs,+ datadir = LBI.datadir dirs,+ htmldir = LBI.htmldir dirs+ }++showInstallDirsGen :: (FilePath -> String) -> InstallDirs -> String+showInstallDirsGen sw InstallDirs {+ bindir = bd,+ libdir = ld,+ datadir = dd,+ htmldir = hd } =+ "bindir : " ++ sw bd ++ "\n" +++ "libdir : " ++ sw ld ++ "\n" +++ "datadir: " ++ sw dd ++ "\n" +++ "htmldir: " ++ sw hd ++ "\n"++showInstallDirs :: InstallDirs -> String+showInstallDirs = showInstallDirsGen id++showRPInstallDirs :: FilePath -> InstallDirs -> String+showRPInstallDirs = showInstallDirsGen . removePrefix++printInstallDirs :: InstallDirs -> IO ()+printInstallDirs = putStr . showInstallDirs++printRPInstallDirs :: FilePath -> InstallDirs -> IO ()+printRPInstallDirs p = putStr . showRPInstallDirs p++removePrefix :: FilePath -> FilePath -> String+removePrefix p s+ | p `isPrefixOf` s = dropWhile (== '/') $ drop (length p) s+ | otherwise = s++main :: IO ()+main = do+ args <- getArgs+ let prfx = case args of+ [] -> ""+ [p] -> p+ _ -> error "bad arguments"+ getInstallDirs >>= printRPInstallDirs prfx