packages feed

cabal-cargs (empty) → 0.1.1

raw patch · 79 files changed

+1643/−0 lines, 79 filesdep +Cabaldep +basedep +cabal-cargssetup-changed

Dependencies added: Cabal, base, cabal-cargs, cmdargs, directory, either, filepath, lens, strict, system-fileio, system-filepath, tasty, tasty-golden, text, transformers, unordered-containers

Files

+ LICENSE view
@@ -0,0 +1,24 @@+Copyright (c) 2011, Daniel Trstenjak+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 the <organization> nor the+      names of its 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 DANIEL TRSTENJAK 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.
+ README.md view
@@ -0,0 +1,152 @@+cabal-cargs+===========++`cabal-cargs` is a command line program for extracting compiler relevant+arguments from a cabal file and print them out formatted so that they're+directly usable as arguments for `ghc` or `hdevtools`.++The main motivation for writing `cabal-cargs` was to get a mostly just working+default, non modified `hdevtools`.++Example: Cabal and Sandbox aware Hdevtools+==========================================++If you want to call `hdevtools check` for a source file of a cabalized project and+would like to consider all compiler relevant arguments in the cabal file - like+`hs-source-dirs`, `ghc-options`, `cpp-options` ... - and also the `cabal sandbox`,+the you could just use `cabal-cargs` the following way:++    $> hdevtools check `cabal-cargs --format=hdevtools --sourcefile=Source.hs` Source.hs++This call of `cabal-cargs` will search for a cabal file starting at the directory+of `Source.hs` upwards the directory tree. The cabal file is then searched for+a fitting section for the given source file. A section is considered fitting if+the source file is contained in a directory or sub-directory listed in `hs-source-dirs`. ++At the end the fields of the found sections are printed out in the desired format.++Normally you don't want to use `cabal-cargs` manually, but use it to initialize the+options of hdevtools. So in the case of the editor `vim` and the plugin `vim-hdevtools`+you could use something like:++    function! s:CabalCargs(args)+       let l:output = system('cabal-cargs ' . a:args)+       if v:shell_error != 0+          let l:lines = split(l:output, '\n')+          echohl ErrorMsg+          echomsg 'args: ' . a:args+          for l:line in l:lines+             echomsg l:line+          endfor+          echohl None+          return ''+       endif+       return l:output+    endfunction+    +    function! s:HdevtoolsOptions()+        return s:CabalCargs('--format=hdevtools --sourcefile=' . shellescape(expand('%')))+    endfunction+    +    autocmd Bufenter *.hs :call s:InitHaskellVars()+    +    function! s:InitHaskellVars()+       if filereadable(expand('%'))+          let g:hdevtools_options = s:HdevtoolsOptions()+       endif+    endfunction++To see if `cabal-cargs` did the right thing you can verify the hdevtools options by+calling in the vim command line:++    :let g:hdevtools_options++Example: Compiler Arguments from Cabal File+============================================++Instead of searching for the cabal file by a source file the cabal file can be given explicitly:++    $> cabal-cargs --cabalfile=Some.cabal++If an additional source file is given, then the cabal file is searched for a fitting section.++Sections+========++If you don't want any automatic finding of sections or only want to consider a+certain section, then you could do this by using the options:+* `--library`+* `--executable=name`+* `--testsuite=name`+* `--benchmark=name`++You can use multiple of these options at once and even specify multiple+e.g. executables at once: `--executable=exe1 --executable=exe2 ...`.++Fields+======++By default all fields of a section are printed out. You can constrain the+output by the option: `--only=name`. This option can be specified multiple times.++The allowed names are the field names from the cabal file, just the hyphen+replaced by an underscore e.g.: `hs-source-dirs` -> `hs_source_dirs`.++Currently supported cabal fields are:+* `hs_source_dirs`+* `ghc_options`+* `default_extensions`+* `default_language`+* `cpp_options`+* `c_sources`+* `cc_options`+* `extra_lib_dirs`+* `extra_libraries`+* `ld_options`+* `include_dirs`+* `includes`++There are further some special fields:+* `package_db`+* `autogen_hs_source_dirs`+* `autogen_include_dirs`+* `autogen_includes`++It's not quite true, that all fields are printed out if not constrained, that's+only the case for the `pure` formatting option. For the other formatting options+currently the fields `c_sources`, `extra_libraries` and `ld_options` are ignored.  ++Also there's one special field for `hdevtools` which is always printed out:+the used socket file.++Flags+=====++The conditional parts of the cabal file are respected by `cabal-cargs` by taking+the default values of the flags defined in the cabal file into account.++You can overwrite the default values of the flags with the options:+* `--enable=FLAGNAME`+* `--disable=FLAGNAME` ++It's also possible to overwrite the `OS` and `Arch` values - which by default are+the ones the cabal library was build on - with the options:+* `--os=OSNAME`+* `--arch=ARCHNAME`++Formatting+==========++By default the fields are formatted for the `ghc` compiler. The available options+for `--format` are:+* `ghc`+* `hdevtools`+* `pure`++`pure` prints the values like they are present in the cabal file and is mostly+only useful in conjunction with `--only` to get the value of one cabal field.++Installation+============++It's recommended to build `cabal-cargs` in a `cabal sandbox` with: `cabal install cabal-cargs`.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ cabal-cargs.cabal view
@@ -0,0 +1,68 @@+name: cabal-cargs+version: 0.1.1+cabal-version: >=1.9.2+build-type: Simple+license: BSD3+license-file: LICENSE+maintainer: daniel.trstenjak@gmail.com+synopsis: A command line program for extracting compiler arguments from a cabal file.+description: For further details please consult the <https://github.com/dan-t/cabal-cargs README>.+category: Utils+author: Daniel Trstenjak+data-dir: ""+extra-source-files: +    README.md+    tests/mkGoldens+    tests/takeOutputsAsGoldens+    tests/inputFiles/withoutSandbox/test.cabal+    tests/inputFiles/withoutSandbox/dist/.gitignore+    tests/inputFiles/withoutSandbox/exe/Source.hs+    tests/inputFiles/withoutSandbox/lib/Source.hs+    tests/inputFiles/withSandbox/test.cabal+    tests/inputFiles/withSandbox/dist/dist-sandbox-6d1acfa0/.gitignore+    tests/inputFiles/withSandbox/.cabal-sandbox/x86_64-linux-ghc-7.6.2-packages.conf.d/.gitignore+    tests/inputFiles/withSandbox/exe/Source.hs+    tests/inputFiles/withSandbox/lib/Source.hs+    tests/goldenFiles/withoutSandbox/*.txt+    tests/goldenFiles/withSandbox/*.txt+    tests/outputFiles/withoutSandbox/.gitignore+    tests/outputFiles/withSandbox/.gitignore+ +source-repository head+    type: git+    location: https://github.com/dan-t/cabal-cargs+ +library+    build-depends: base >=3 && <5, cmdargs >=0.10.5 && <0.11,+                   lens >=4.0.1 && <4.1, directory -any, strict >=0.3.2 && <0.4,+                   transformers >=0.3.0.0 && <0.4, either >=4.1.1 && <4.2,+                   text >=1.1.0.1 && <1.2, system-filepath >=0.4.9 && <0.5,+                   system-fileio >=0.3.12 && <0.4, unordered-containers >=0.2.3.3 && <0.3,+                   Cabal >=1.18.0 && <1.19+    exposed-modules: CabalCargs.Args CabalCargs.Field CabalCargs.Fields+                     CabalCargs.Formatting CabalCargs.Format CabalCargs.Spec+                     CabalCargs.Sections CabalCargs.CompilerArgs CabalCargs.Lenses+                     CabalCargs.CondVars+    exposed: True+    buildable: True+    cpp-options: -DCABAL+    hs-source-dirs: lib+    other-modules: Paths_cabal_cargs+    ghc-options: -W+ +executable cabal-cargs+    build-depends: base >=3 && <5, cabal-cargs -any+    main-is: Main.hs+    buildable: True+    hs-source-dirs: exe+    ghc-options: -W++test-suite tests+    build-depends: base >=3 && <5, tasty ==0.7.*,+                   tasty-golden >=2.2.0.2 && <2.3, filepath >=1.3.0.1 && <1.4,+                   cabal-cargs -any+    type: exitcode-stdio-1.0+    main-is: Main.hs+    buildable: True+    hs-source-dirs: tests+    ghc-options: -W
+ exe/Main.hs view
@@ -0,0 +1,24 @@++module Main where++import System.Exit (exitFailure, exitSuccess)+import System.IO (hPutStrLn, stderr)+import qualified CabalCargs.Args as CmdArgs+import qualified CabalCargs.Format as F+import qualified CabalCargs.CompilerArgs as CompilerArgs+import Data.List (intercalate)+++main :: IO ()+main = do+   cmdArgs <- CmdArgs.get+   let formatting = CmdArgs.format cmdArgs+   cargs   <- CompilerArgs.fromCmdArgs cmdArgs+   case cargs of+        Left error -> do+           hPutStrLn stderr ("cabal-cargs: " ++ error)+           exitFailure++        Right cargs_ -> do+           putStr $ intercalate " " $ F.format formatting cargs_+           exitSuccess
+ lib/CabalCargs/Args.hs view
@@ -0,0 +1,63 @@+{-# LANGUAGE DeriveDataTypeable, CPP #-}++module CabalCargs.Args where++import System.Console.CmdArgs+import CabalCargs.Field (Field)+import CabalCargs.Formatting (Formatting)+ +#ifdef CABAL+import Data.Version (showVersion)+import Paths_cabal_cargs (version)+#endif+++-- | The command line arguments of the cabal-cargs command.+data Args = Args+   { library    :: Bool+   , executable :: [String]+   , testSuite  :: [String]+   , benchmark  :: [String]+   , only       :: [Field]+   , format     :: Formatting+   , sourceFile :: Maybe FilePath+   , cabalFile  :: Maybe FilePath+   , enable     :: [String]+   , disable    :: [String]+   , os         :: Maybe String+   , arch       :: Maybe String+   , relative   :: Bool+   }+   deriving (Data, Typeable, Show, Eq)+++get :: IO Args+get = cmdArgs $ Args+   { library    = def &= help "Only the compiler args of the library section are printed out."+   , executable = def &= typ "NAME" &= help "Only the compiler args of the library section are printed out."+   , testSuite  = def &= typ "NAME" &= help "Only the compiler args of the test suite section are printed out."+   , benchmark  = def &= typ "NAME" &= help "Only the compiler args of the benchmark section are printed out."+   , only       = def &= typ "FIELD" &= help "Only the specified compiler args are printed out, otherwise all args are printed out. The field name equals the ones in the cabal file, just the '-' replaced by a '_' e.g.: hs_source_dirs, ghc_options, cpp_options ..."+   , format     = def &= typ "FORMAT" &= help "How the print out should be formated: ghc, hdevtools, pure."+   , sourceFile = def &= typ "FILE" &= help "If given, then the cabal file is searched for a matching section. If multiple sections match, then all sections are used."+   , cabalFile  = def &= typ "FILE" &= help "If not given, then a cabal file is searched upwards the directory tree."+   , enable     = def &= explicit &= typ "FLAGNAME" &= name "enable" &= name "E" &= help "Enable a flag defined in the cabal file."+   , disable    = def &= explicit &= typ "FLAGNAME" &= name "disable" &= name "D" &= help "Disable a flag defined in the cabal file."+   , os         = def &= explicit &= typ "NAME" &= name "os" &= help "Set the used OS. See 'Distribution.System.OS' in the cabal library for valid values."+   , arch       = def &= explicit &= typ "NAME" &= name "arch" &= help "Set the used Arch. See 'Distribution.System.Arch' in the cabal library for valid values."+   , relative   = def &= help "If all returned paths should be relative to the directory of the cabal file, otherwise the paths are absolute. This option is mostly only used for the normalization of the output for the test cases."+   }+   &= program "cabal-cargs"+   &= summary ""+   &= help "A command line program for extracting compiler arguments from a cabal file."+   &= helpArg [explicit, name "help", name "h"]+   &= versionArg [explicit, name "version", name "v", summary versionInfo]+++versionInfo :: String+versionInfo =+#ifdef CABAL+   "cabal-cargs version " ++ showVersion version+#else+   "cabal-cargs version unknown (not built with cabal)"+#endif
+ lib/CabalCargs/CompilerArgs.hs view
@@ -0,0 +1,199 @@+{-# Language PatternGuards, TemplateHaskell, Rank2Types #-}++module CabalCargs.CompilerArgs+   ( CompilerArgs(..)+   , fromCmdArgs+   , fromSpec+   ) where++import CabalCargs.Spec (Spec)+import qualified CabalCargs.Spec as Spec+import qualified CabalCargs.Args as A+import qualified CabalCargs.Sections as S+import qualified CabalCargs.Field as F+import qualified CabalCargs.Fields as Fs+import qualified CabalCargs.Lenses as L+import Data.List (nub, foldl')+import Data.Maybe (maybeToList)+import Control.Applicative ((<$>))+import Control.Lens+import Control.Monad.Trans.Either (runEitherT)+import qualified Filesystem.Path.CurrentOS as FP+import Filesystem.Path ((</>))+++-- | The collected compiler args from the cabal file. Till the field 'packageDB'+--   all fields represent the equaliy named fields ('-' replaced by CamelCase)+--   from the cabal file.+data CompilerArgs = CompilerArgs +   { hsSourceDirs        :: [FilePath]+   , ghcOptions          :: [String]+   , defaultExtensions   :: [String]+   , defaultLanguage     :: [String]+   , cppOptions          :: [String]+   , cSources            :: [FilePath]+   , ccOptions           :: [String]+   , extraLibDirs        :: [FilePath]+   , extraLibraries      :: [String]+   , ldOptions           :: [String]+   , includeDirs         :: [FilePath]+   , includes            :: [String]+   , packageDB           :: Maybe FilePath -- ^ the path to the package database of the cabal sandbox+   , autogenHsSourceDirs :: [FilePath]     -- ^ dirs of automatically generated haskell source files by cabal (e.g. Paths_*)+   , autogenIncludeDirs  :: [FilePath]     -- ^ dirs of automatically generated include files by cabal+   , autogenIncludes     :: [String]       -- ^ automatically generated include files by cabal (e.g. cabal_macros.h)+   , cabalFile           :: FilePath       -- ^ path to the used cabal file+   , relativePaths       :: Bool           -- ^ if all returned paths are relative to the directory of the cabal file, otherwise all paths are absolute+   }+   deriving (Show, Eq)+++makeLensesFor [ ("hsSourceDirs"       , "hsSourceDirsL")+              , ("ghcOptions"         , "ghcOptionsL")+              , ("defaultExtensions"  , "defaultExtensionsL")+              , ("defaultLanguage"    , "defaultLanguageL")+              , ("cppOptions"         , "cppOptionsL")+              , ("cSources"           , "cSourcesL")+              , ("ccOptions"          , "ccOptionsL")+              , ("extraLibDirs"       , "extraLibDirsL")+              , ("extraLibraries"     , "extraLibrariesL")+              , ("ldOptions"          , "ldOptionsL")+              , ("includeDirs"        , "includeDirsL")+              , ("includes"           , "includesL")+              , ("autogenHsSourceDirs", "autogenHsSourceDirsL")+              , ("autogenIncludeDirs" , "autogenIncludeDirsL")+              , ("autogenIncludes"    , "autogenIncludesL")+              ] ''CompilerArgs++type Error = String+++-- | Create a 'CompilerArgs' by the command line arguments given to 'cabal-cargs'.+fromCmdArgs :: A.Args -> IO (Either Error CompilerArgs)+fromCmdArgs args = runEitherT $ do+   fromSpec <$> Spec.fromCmdArgs args+++-- | Create a 'CompilerArgs' and collect the compiler args specified by 'Spec'.+fromSpec :: Spec -> CompilerArgs+fromSpec spec =+   case Spec.sections spec of+        S.Sections sections ->+           setCabalFile $ absolutePaths $ foldl' collectFromSection compilerArgs sections++        S.AllSections ->+           setCabalFile $ absolutePaths $ collectFields buildInfos compilerArgs++   where+      compilerArgs = defaultCompilerArgs { relativePaths = Spec.relativePaths spec }++      setCabalFile cargs = cargs { cabalFile = Spec.cabalFile spec }++      absolutePaths cargs+         | Spec.relativePaths spec+         = cargs++         | otherwise+         = cargs & hsSourceDirsL        %~ map prependCabalDir+                 & cSourcesL            %~ map prependCabalDir+                 & extraLibDirsL        %~ map prependCabalDir+                 & includeDirsL         %~ map prependCabalDir+                 & autogenHsSourceDirsL %~ map prependCabalDir+                 & autogenIncludeDirsL  %~ map prependCabalDir+                 & packageDBL           %~ map prependCabalDir+         where+            prependCabalDir path = FP.encodeString $ cabalDir </> FP.decodeString path+            cabalDir             = FP.directory . FP.decodeString $ Spec.cabalFile spec++      collectFromSection cargs section =+         collectFields (buildInfosOf section) cargs++      collectFields buildInfos cargs =+        foldl' (addCarg buildInfos) cargs fields+        where+           addCarg _ cargs F.Package_Db  =+              cargs & packageDBL .~ (maybeToList $ Spec.packageDB spec)++           addCarg _ cargs F.Autogen_Hs_Source_Dirs+              | Just distDir <- Spec.distDir spec+              = cargs & autogenHsSourceDirsL .~ [distDir ++ "/build/autogen"]++              | otherwise+              = cargs++           addCarg _ cargs F.Autogen_Include_Dirs+              | Just distDir <- Spec.distDir spec+              = cargs & autogenIncludeDirsL .~ [distDir ++ "/build/autogen"]++              | otherwise+              = cargs++           addCarg _ cargs F.Autogen_Includes+              | Just _ <- Spec.distDir spec+              = cargs & autogenIncludesL .~ ["cabal_macros.h"]++              | otherwise+              = cargs++           addCarg buildInfos cargs field =+              cargs & (fieldL field) %~ nub . (++ buildInfoFields)+              where+                 buildInfoFields = concat $ map (^. L.field field) buildInfos ++           fields   = case Spec.fields spec of+                           Fs.Fields fs -> fs+                           _            -> F.allFields++      buildInfos           = L.buildInfos (Spec.condVars spec) (Spec.cabalPackage spec)+      buildInfosOf section = L.buildInfosOf section (Spec.condVars spec) (Spec.cabalPackage spec) +++packageDBL :: Lens' CompilerArgs [String]+packageDBL = lens getter setter+   where+      getter = maybeToList . packageDB++      setter cargs [db@(_:_)] = cargs { packageDB = Just db }+      setter cargs          _ = cargs+++fieldL :: F.Field -> Lens' CompilerArgs [String]+fieldL F.Hs_Source_Dirs         = hsSourceDirsL+fieldL F.Ghc_Options            = ghcOptionsL+fieldL F.Default_Extensions     = defaultExtensionsL+fieldL F.Default_Language       = defaultLanguageL+fieldL F.Cpp_Options            = cppOptionsL+fieldL F.C_Sources              = cSourcesL+fieldL F.Cc_Options             = ccOptionsL+fieldL F.Extra_Lib_Dirs         = extraLibDirsL+fieldL F.Extra_Libraries        = extraLibrariesL+fieldL F.Ld_Options             = ldOptionsL+fieldL F.Include_Dirs           = includeDirsL+fieldL F.Includes               = includesL+fieldL F.Package_Db             = packageDBL+fieldL F.Autogen_Hs_Source_Dirs = autogenHsSourceDirsL+fieldL F.Autogen_Include_Dirs   = autogenIncludeDirsL+fieldL F.Autogen_Includes       = autogenIncludesL+++defaultCompilerArgs :: CompilerArgs+defaultCompilerArgs = CompilerArgs+   { hsSourceDirs        = []+   , ghcOptions          = []+   , defaultExtensions   = []+   , defaultLanguage     = []+   , cppOptions          = []+   , cSources            = []+   , ccOptions           = []+   , extraLibDirs        = []+   , extraLibraries      = []+   , ldOptions           = []+   , includeDirs         = []+   , includes            = []+   , cabalFile           = ""+   , packageDB           = Nothing+   , autogenHsSourceDirs = []+   , autogenIncludeDirs  = []+   , autogenIncludes     = []+   , relativePaths       = False+   }
+ lib/CabalCargs/CondVars.hs view
@@ -0,0 +1,77 @@+{-# Language TemplateHaskell, PatternGuards #-}++module CabalCargs.CondVars+   ( CondVars(..)+   , fromDefaults+   , enableFlag+   , disableFlag+   , eval+   ) where++import qualified Distribution.PackageDescription as PD+import Distribution.PackageDescription (Condition(..))+import qualified Distribution.System as S+import Distribution.System (OS(..), Arch(..))+import qualified Data.HashMap.Strict as HM+import Control.Lens++type FlagName = String+type FlagMap  = HM.HashMap FlagName Bool+++-- | The conditional variables that are used to resolve the conditionals inside of+--   the cabal file. Holds the enable state of the cabal flags and the used OS and ARCH.+data CondVars = CondVars+   { flags :: FlagMap  -- ^ initialized with the default flag values which are accordingly+                       --   modified by the explicitely given flag values by the user+   , os    :: OS       -- ^ the used OS, by default the one cabal was build on or given explicitely by the user+   , arch  :: Arch     -- ^ the used ARCH, by default the one cabal was build on or given explicitely by the user+   } deriving (Show)+++makeLensesFor [ ("flags", "flagsL")+              ] ''CondVars+++-- | Create a 'CondVars' from the default flags of the cabal package description.+--   The 'os' and 'arch' fields are initialized by the ones the cabal library was build on.+fromDefaults :: PD.GenericPackageDescription -> CondVars+fromDefaults pkgDescrp = CondVars { flags = flags, os = S.buildOS, arch = S.buildArch }+   where+      flags = HM.fromList $ map nameWithDflt (PD.genPackageFlags pkgDescrp)++      nameWithDflt PD.MkFlag { PD.flagName = PD.FlagName name, PD.flagDefault = dflt } =+         (name, dflt)+++-- | Enable the given flag in 'CondVars'.+enableFlag :: FlagName -> CondVars -> CondVars+enableFlag flag condVars =+   condVars & flagsL %~ (HM.insert flag True)+++-- | Disable the given flag in 'CondVars'.+disableFlag :: FlagName -> CondVars -> CondVars+disableFlag flag condVars =+   condVars & flagsL %~ (HM.insert flag False)+++-- | Evaluate the 'Condition' using the 'CondVars'.+eval :: CondVars -> (Condition PD.ConfVar) -> Bool+eval condVars cond = eval' cond+   where+      eval' (Var var)    = hasVar var+      eval' (Lit val)    = val+      eval' (CNot c)     = not $ eval' c+      eval' (COr c1 c2)  = eval' c1 || eval' c2+      eval' (CAnd c1 c2) = eval' c1 && eval' c2++      hasVar (PD.OS osVar)                = osVar == os condVars+      hasVar (PD.Arch archVar)            = archVar == arch condVars+      hasVar (PD.Impl _ _ )               = True+      hasVar (PD.Flag (PD.FlagName name))+         | Just v <- HM.lookup name (flags condVars)+         = v++         | otherwise+         = False
+ lib/CabalCargs/Field.hs view
@@ -0,0 +1,37 @@+{-# LANGUAGE DeriveDataTypeable #-}++module CabalCargs.Field+   ( Field(..)+   , allFields+   ) where++import Data.Data (Data, Typeable)++-- | A compiler relevant field. Till 'Package_Db' all fields are from the cabal file+--   with the same name, just with lower case letters and the '_' replaced by a '-'.+data Field = Hs_Source_Dirs+           | Ghc_Options+           | Default_Extensions+           | Default_Language++           | Cpp_Options+           | C_Sources+           | Cc_Options++           | Extra_Lib_Dirs+           | Extra_Libraries+           | Ld_Options++           | Include_Dirs+           | Includes++           | Package_Db             -- ^ the package database of a cabal sandbox+           | Autogen_Hs_Source_Dirs -- ^ dirs of automatically generated haskell source files by cabal (e.g. Paths_*)+           | Autogen_Include_Dirs   -- ^ dirs of automatically generated include files by cabal+           | Autogen_Includes       -- ^ automatically generated include files by cabal (e.g. cabal_macros.h)+           deriving (Data, Typeable, Show, Eq, Enum, Bounded)+++-- | Get all known fields.+allFields :: [Field]+allFields = [ minBound .. maxBound ]
+ lib/CabalCargs/Fields.hs view
@@ -0,0 +1,26 @@+{-# LANGUAGE PatternGuards #-}++module CabalCargs.Fields+   ( Fields(..)+   , fields+   ) where++import CabalCargs.Args (Args)+import qualified CabalCargs.Args as Args+import qualified CabalCargs.Field as F+++-- | Which fields should be considered for the print out.+data Fields = AllFields        -- ^ all fields are printed out+            | Fields [F.Field] -- ^ only these fields are printed out+            deriving (Show, Eq)+++-- | Convert the command line arguments into 'Fields'.+fields :: Args -> Fields+fields args+   | fs@(_:_) <- Args.only args+   = Fields fs++   | otherwise+   = AllFields
+ lib/CabalCargs/Format.hs view
@@ -0,0 +1,73 @@+{-# Language PatternGuards #-}++module CabalCargs.Format+   ( format+   ) where++import CabalCargs.CompilerArgs (CompilerArgs(..))+import CabalCargs.Formatting (Formatting(..))+import Data.Maybe (maybeToList)+import Data.List (foldl')+import qualified Filesystem.Path.CurrentOS as FP+import Filesystem.Path ((</>))+++format :: Formatting -> CompilerArgs -> [String]+format Ghc cargs = concat [ formatHsSourceDirs $ hsSourceDirs cargs+                          , ghcOptions cargs+                          , map ("-X" ++) (defaultExtensions cargs)+                          , map ("-X" ++) (defaultLanguage cargs)+                          , map ("-optP" ++) (cppOptions cargs)+                          , map ("-optc" ++) (ccOptions cargs)+                          , map ("-L" ++) (extraLibDirs cargs)+                          , map ("-l" ++) (extraLibraries cargs)+                          , formatIncludeDirs $ includeDirs cargs+                          , formatIncludes $ includes cargs+                          , maybe [""] (\db -> ["-package-conf=" ++ db]) (packageDB cargs)+                          , formatHsSourceDirs $ autogenHsSourceDirs cargs+                          , formatIncludeDirs $ autogenIncludeDirs cargs+                          , formatIncludes $ autogenIncludes cargs+                          ]+   where+      formatHsSourceDirs = map ("-i" ++)+      formatIncludeDirs  = map ("-I" ++)++      formatIncludes incs = reverse $ foldl' addInclude [] incs+         where+            addInclude incs inc = ("-optP" ++ inc) : ("-optP-include") : incs+++format Hdevtools cargs = (map ("-g" ++) (format Ghc cargs)) ++ socket+   where+      socket = ["--socket=" ++ socketFile]+      socketFile+         | relativePaths cargs+         = ".hdevtools.sock"++         | otherwise+         = prependCabalDir cargs ".hdevtools.sock"+++format Pure cargs = concat [ hsSourceDirs cargs+                           , ghcOptions cargs+                           , defaultExtensions cargs+                           , defaultLanguage cargs+                           , cppOptions cargs+                           , cSources cargs+                           , ccOptions cargs+                           , extraLibDirs cargs+                           , extraLibraries cargs+                           , ldOptions cargs+                           , includeDirs cargs+                           , includes cargs+                           , maybeToList $ packageDB cargs+                           , autogenHsSourceDirs cargs+                           , autogenIncludeDirs cargs+                           , autogenIncludes cargs+                           ]+++prependCabalDir :: CompilerArgs -> String -> String+prependCabalDir cargs path = FP.encodeString $ cabalDir </> (FP.decodeString path)+   where+      cabalDir = FP.directory $ FP.decodeString (cabalFile cargs)
+ lib/CabalCargs/Formatting.hs view
@@ -0,0 +1,19 @@+{-# LANGUAGE DeriveDataTypeable #-}++module CabalCargs.Formatting+   ( Formatting(..)+   ) where++import Data.Data (Data, Typeable)+import System.Console.CmdArgs.Default (Default, def)+++-- | How the fields from the cabal file should be printed out.+data Formatting = Ghc       -- ^ as ghc compatible arguments+                | Hdevtools -- ^ as hdevtools compatible arguments+                | Pure      -- ^ the field values are printed as present in the cabal file+                deriving (Data, Typeable, Show, Eq)+++instance Default Formatting where+   def = Ghc
+ lib/CabalCargs/Lenses.hs view
@@ -0,0 +1,199 @@+{-# LANGUAGE TemplateHaskell, Rank2Types, PatternGuards #-}++module CabalCargs.Lenses+   ( buildInfosOfLib+   , buildInfosOfExe+   , buildInfosOfTest+   , buildInfosOfBenchmark+   , buildInfosOf+   , buildInfos+   , field+   ) where++import Distribution.PackageDescription+import Distribution.Compiler+import Distribution.Package (Dependency)+import Language.Haskell.Extension+import Control.Lens+import Data.List (find)+import qualified CabalCargs.Sections as S+import qualified CabalCargs.Field as F+import qualified CabalCargs.CondVars as CV+++makeLensesFor [ ("hsSourceDirs"     , "hsSourceDirsL")+              , ("options"          , "optionsL")+              , ("defaultLanguage"  , "defaultLanguageL")+              , ("cppOptions"       , "cppOptionsL")+              , ("cSources"         , "cSourcesL")+              , ("ccOptions"        , "ccOptionsL")+              , ("extraLibDirs"     , "extraLibDirsL")+              , ("extraLibs"        , "extraLibsL")+              , ("ldOptions"        , "ldOptionsL")+              , ("includeDirs"      , "includeDirsL")+              , ("includes"         , "includesL")+              ] ''BuildInfo+++buildInfosOf :: S.Section -> CV.CondVars -> GenericPackageDescription -> [BuildInfo]+buildInfosOf S.Library           = buildInfosOfLib+buildInfosOf (S.Executable name) = buildInfosOfExe name+buildInfosOf (S.TestSuite name)  = buildInfosOfTest name+buildInfosOf (S.Benchmark name)  = buildInfosOfBenchmark name+++buildInfos :: CV.CondVars -> GenericPackageDescription -> [BuildInfo]+buildInfos vars pkgDescrp =+   concat [ buildInfosOfLib vars pkgDescrp+          , buildInfosOfAllExes vars pkgDescrp+          , buildInfosOfAllTests vars pkgDescrp+          , buildInfosOfAllBenchmarks vars pkgDescrp+          ]+++buildInfosOfLib :: CV.CondVars -> GenericPackageDescription -> [BuildInfo]+buildInfosOfLib vars pkgDescrp+   | Just condLib <- condLibrary pkgDescrp+   = map libBuildInfo $ condTreeDatas vars condLib++   | otherwise+   = []+++buildInfosOfExe :: String -> CV.CondVars -> GenericPackageDescription -> [BuildInfo]+buildInfosOfExe name vars pkgDescrp+   | Just (_, condExe) <- find ((== name) . fst) $ condExecutables pkgDescrp+   = map buildInfo $ condTreeDatas vars condExe++   | otherwise+   = []+++buildInfosOfAllExes :: CV.CondVars -> GenericPackageDescription -> [BuildInfo]+buildInfosOfAllExes vars pkgDescrp =+   concat $ map ((map buildInfo) . (condTreeDatas vars) . snd) (condExecutables pkgDescrp)+++buildInfosOfTest :: String -> CV.CondVars -> GenericPackageDescription -> [BuildInfo]+buildInfosOfTest name vars pkgDescrp+   | Just (_, condTest) <- find ((== name) . fst) $ condTestSuites pkgDescrp+   = map testBuildInfo $ condTreeDatas vars condTest++   | otherwise+   = []+++buildInfosOfAllTests :: CV.CondVars -> GenericPackageDescription -> [BuildInfo]+buildInfosOfAllTests vars pkgDescrp =+   concat $ map ((map testBuildInfo) . (condTreeDatas vars) . snd) (condTestSuites pkgDescrp)+++buildInfosOfBenchmark :: String -> CV.CondVars -> GenericPackageDescription -> [BuildInfo]+buildInfosOfBenchmark name vars pkgDescrp+   | Just (_, condBench) <- find ((== name) . fst) $ condBenchmarks pkgDescrp+   = map benchmarkBuildInfo $ condTreeDatas vars condBench++   | otherwise+   = []+++buildInfosOfAllBenchmarks :: CV.CondVars -> GenericPackageDescription -> [BuildInfo]+buildInfosOfAllBenchmarks vars pkgDescrp =+   concat $ map ((map benchmarkBuildInfo) . (condTreeDatas vars) . snd) (condBenchmarks pkgDescrp)+++-- | Returns all 'condTreeData' of the 'CondTree' which conditions match the given 'CondVars'. +condTreeDatas :: CV.CondVars -> CondTree ConfVar [Dependency] a -> [a]+condTreeDatas vars tree = go (condTreeComponents tree) [condTreeData tree]+   where+      go [] dats = dats++      go ((cond, ifTree, elseTree) : comps) dats+         | CV.eval vars cond+         = go comps $ go (condTreeComponents ifTree) (condTreeData ifTree : dats)++         | Just tree <- elseTree+         = go comps $ go (condTreeComponents tree) (condTreeData tree : dats)++         | otherwise+         = go comps dats+++-- | A lens from a 'BuildInfo' to a list of stringified field entries of the 'BuildInfo'.+field :: F.Field -> Traversal' BuildInfo [String]+field F.Hs_Source_Dirs         = hsSourceDirsL+field F.Ghc_Options            = optionsL . traversed . filtered ((== GHC) . fst) . _2+field F.Default_Extensions     = oldAndDefaultExtensionsL . extsToStrings+field F.Default_Language       = defaultLanguageL . langToString+field F.Cpp_Options            = cppOptionsL+field F.C_Sources              = cSourcesL+field F.Cc_Options             = ccOptionsL+field F.Extra_Lib_Dirs         = extraLibDirsL+field F.Extra_Libraries        = extraLibsL+field F.Ld_Options             = ldOptionsL+field F.Include_Dirs           = includeDirsL+field F.Includes               = includesL+field F.Package_Db             = nopLens+field F.Autogen_Hs_Source_Dirs = nopLens+field F.Autogen_Include_Dirs   = nopLens+field F.Autogen_Includes       = nopLens+++-- | A lens that merges the fields 'default-extensions' and 'extensions',+--   which now mean the same thing in cabal, 'extensions' is only the old+--   name of 'default-extensions'.+oldAndDefaultExtensionsL :: Lens' BuildInfo [Extension]+oldAndDefaultExtensionsL = lens getter setter+   where+      getter buildInfo      = (oldExtensions buildInfo) ++ (defaultExtensions buildInfo)+      setter buildInfo exts = buildInfo { defaultExtensions = exts }+++-- | A lens (iso) that converts between a list of extensions+--   and a list of strings containing the names of the extensions.+extsToStrings :: Iso' [Extension] [String]+extsToStrings = iso (map toString) (map toExt)+   where+      toString ext = +         case ext of+              EnableExtension knownExt    -> show knownExt+              DisableExtension knownExt   -> "No" ++ show knownExt+              UnknownExtension unknownExt -> unknownExt++      toExt ('N':'o':rest)+         | [(ext, _)] <- reads rest :: [(KnownExtension, String)]+         = DisableExtension ext++      toExt str+         | [(ext, _)] <- reads str :: [(KnownExtension, String)]+         = EnableExtension ext++         | otherwise+         = UnknownExtension str+++-- | A lens (iso) that converts between the language and+--   a list containing a string with the name of the language.+langToString :: Iso' (Maybe Language) [String]+langToString = iso toString toLang+   where+      toString Nothing     = []+      toString (Just lang) =+         case lang of+              UnknownLanguage l -> [l]+              _                 -> [show lang]++      toLang (str:[])+         | [(lang, _)] <- reads str :: [(Language, String)]+         = Just lang++         | otherwise+         = Just $ UnknownLanguage str++      toLang _ = Nothing+++-- | A lens that does nothing, always returns an empty+--   list and doesn't modify the given BuildInfo.+nopLens :: Lens' BuildInfo [String]+nopLens = lens (const []) (\buildInfo _ -> buildInfo)
+ lib/CabalCargs/Sections.hs view
@@ -0,0 +1,36 @@+{-# LANGUAGE PatternGuards #-}++module CabalCargs.Sections+   ( Sections(..)+   , Section(..)+   , sections+   ) where++import CabalCargs.Args (Args)+import qualified CabalCargs.Args as A++-- | A section of the cabal file.+data Section = Library+             | Executable String+             | TestSuite String+             | Benchmark String+             deriving (Show, Eq)++-- | From which sections the compiler args should be collected.+data Sections = AllSections        -- ^ all sections are considered+              | Sections [Section] -- ^ only these sections are considered+              deriving (Show, Eq)+++-- | Convert the command line arguments into 'Sections'.+sections :: Args -> Sections+sections args +   | ss@(_:_) <- concat [ [Library | A.library args]+                        , map Executable (A.executable args)+                        , map TestSuite (A.testSuite args)+                        , map Benchmark (A.benchmark args)+                        ]+   = Sections ss++   | otherwise+   = AllSections
+ lib/CabalCargs/Spec.hs view
@@ -0,0 +1,324 @@+{-# Language PatternGuards #-}++module CabalCargs.Spec+   ( Spec(..)+   , fromCmdArgs+   ) where++import Distribution.PackageDescription (GenericPackageDescription)+import qualified Distribution.PackageDescription as PD+import Distribution.PackageDescription.Parse (parsePackageDescription, ParseResult(..))+import qualified Distribution.System as Sys+import CabalCargs.Args (Args)+import qualified CabalCargs.Lenses as L+import qualified CabalCargs.Args as A+import qualified CabalCargs.Sections as S+import qualified CabalCargs.Fields as F+import qualified CabalCargs.CondVars as CV+import qualified System.IO.Strict as Strict+import Control.Monad.Trans.Either (EitherT, left, right)+import Control.Monad.IO.Class+import Control.Monad (filterM)+import Control.Applicative ((<$>))+import System.Directory (getCurrentDirectory)+import qualified Filesystem.Path.CurrentOS as FP+import Filesystem.Path.CurrentOS ((</>))+import qualified Filesystem as FS+import qualified Data.Text as T+import Data.List (find, isSuffixOf, isPrefixOf)+import Data.Maybe (isJust)+++-- | Specifies which compiler args from which sections should be collected.+data Spec = Spec +   { sections      :: S.Sections                -- ^ the sections used for collecting the compiler args+   , fields        :: F.Fields                  -- ^ for these fields compiler args are collected+   , condVars      :: CV.CondVars               -- ^ used for the evaluation of the conditional fields in the cabal file+   , cabalPackage  :: GenericPackageDescription -- ^ the package description of the read in cabal file+   , cabalFile     :: FilePath                  -- ^ the cabal file read from+   , distDir       :: Maybe FilePath            -- ^ the dist directory of the cabal build, a relative path to the directory of the cabal file+   , packageDB     :: Maybe FilePath            -- ^ the directory of package database of the cabal sandbox, a relative path to the directory of the cabal file+   , relativePaths :: Bool                      -- ^ if all returned paths are relative to the directory of the cabal file, otherwise all paths are absolute+   }+++type Error = String+io = liftIO +++-- | Create a 'Spec' by the command line arguments given to 'cabal-cargs'.+--+--   Depending on the command line arguments 'fromCmdArgs' might behave like+--   'fromCabalFile', if only a cabal file was given, like 'fromSourceFile',+--   if only a source file was given or like a mix of both, if a cabal file+--   and a source file have been given.+fromCmdArgs :: Args -> EitherT Error IO Spec+fromCmdArgs args+   | Just cabalFile <- A.cabalFile args = do+      spec        <- fromCabalFile cabalFile (S.sections args) (F.fields args)+      srcSections <- io $ case A.sourceFile args of+                               Just srcFile -> findSections srcFile cabalFile (cabalPackage spec)+                               _            -> return []++      right $ applyCondVars $ spec { sections      = combineSections (sections spec) srcSections+                                   , relativePaths = A.relative args+                                   }++   | Just sourceFile <- A.sourceFile args = do+      spec <- fromSourceFile sourceFile (F.fields args)+      let specSections = case sections spec of+                              S.Sections ss -> ss+                              _             -> []++      right $ applyCondVars $ spec { sections      = combineSections (S.sections args) specSections+                                   , relativePaths = A.relative args+                                   }++   | otherwise = do+      curDir    <- io $ getCurrentDirectory+      cabalFile <- findCabalFile curDir+      spec      <- fromCabalFile cabalFile (S.sections args) (F.fields args)+      right $ applyCondVars $ spec { relativePaths = A.relative args }++   where+      applyCondVars = applyFlags args . applyOS args . applyArch args++++-- | Create a 'Spec' from the given cabal file, sections and fields.+--+--   If a cabal sandbox is present in the directory of the cabal file, then+--   the path to its package database is also returned.+fromCabalFile :: FilePath -> S.Sections -> F.Fields -> EitherT Error IO Spec+fromCabalFile file sections fields = do+   pkgDB     <- io $ findPackageDB file+   distDir   <- io $ findDistDir file+   pkgDescrp <- packageDescription file+   absFile   <- FP.encodeString <$> (io $ absoluteFile file)+   right $ Spec+      { sections      = sections+      , fields        = fields+      , condVars      = CV.fromDefaults pkgDescrp+      , cabalPackage  = pkgDescrp+      , cabalFile     = absFile+      , distDir       = distDir+      , packageDB     = pkgDB+      , relativePaths = False+      }+++-- | Create a 'Spec' from the given source file and fields.+--+--   Starting at the directory of the source file a cabal file is searched+--   upwards the directory tree.+--+--   The found cabal file is searched for a fitting section for the source file.+--   If no fitting section could be found, then all sections are used.+--+--   If a cabal sandbox is present in the directory of the cabal file, then+--   the path to its package database is also returned.+fromSourceFile :: FilePath -> F.Fields -> EitherT Error IO Spec+fromSourceFile file fields = do+   cabalFile   <- findCabalFile file+   pkgDB       <- io $ findPackageDB cabalFile+   distDir     <- io $ findDistDir cabalFile+   pkgDescrp   <- packageDescription cabalFile+   srcSections <- io $ findSections file cabalFile pkgDescrp+   right $ Spec+      { sections = combineSections S.AllSections srcSections+      , fields        = fields+      , condVars      = CV.fromDefaults pkgDescrp+      , cabalPackage  = pkgDescrp+      , cabalFile     = cabalFile+      , distDir       = distDir+      , packageDB     = pkgDB+      , relativePaths = False+      }+++applyFlags :: Args -> Spec -> Spec+applyFlags args spec =+   spec { condVars = disableFlags . enableFlags $ condVars spec }+   where+      disableFlags condVars = foldr CV.disableFlag condVars (A.disable args)+      enableFlags  condVars = foldr CV.enableFlag condVars (A.enable args)+++applyOS :: Args -> Spec -> Spec+applyOS (A.Args { A.os = os }) spec+   | Just str    <- os+   , [(name, _)] <- reads str :: [(Sys.OS, String)]+   = setOS name++   | Just str    <- os+   = setOS $ Sys.OtherOS str++   | otherwise+   = spec++   where+      setOS name = spec { condVars = (condVars spec) { CV.os = name } }+++applyArch :: Args -> Spec -> Spec+applyArch (A.Args { A.arch = arch }) spec+   | Just str    <- arch+   , [(name, _)] <- reads str :: [(Sys.Arch, String)]+   = setArch name++   | Just str    <- arch+   = setArch $ Sys.OtherArch str++   | otherwise+   = spec++   where+      setArch name = spec { condVars = (condVars spec) { CV.arch = name } }+++packageDescription :: FilePath -> EitherT Error IO GenericPackageDescription+packageDescription file = do+   contents <- io $ Strict.readFile file+   case parsePackageDescription contents of+        ParseFailed error   -> left $ show error+        ParseOk _ pkgDescrp -> right pkgDescrp+++-- | Find matching sections in the package description for the given source file.+--   This is done by checking if the source file is contained in the directory+--   or a sub directory of the directories listed in the 'hs-source-dirs' field+--   of the section.+findSections :: FilePath -> FilePath -> GenericPackageDescription -> IO [S.Section]+findSections srcFile cabalFile pkgDescrp = do+   absSrcFile <- absoluteFile srcFile+   cabalDir   <- absoluteDirectory cabalFile+   let sections = filter (fittingSection absSrcFile cabalDir) (allHsSourceDirs pkgDescrp)   +   return $ map fst sections++   where+      fittingSection srcFile cabalDir (_, []) =+         isJust $ FP.stripPrefix (cabalDir </> FP.empty) srcFile++      fittingSection srcFile cabalDir (_, srcDirs) = any samePrefix srcDirs+         where samePrefix srcDir = isJust $ FP.stripPrefix (cabalDir </> srcDir </> FP.empty) srcFile+++type HsSourceDirs = [FP.FilePath]+-- | Returns the hs-source-dirs of all sections present in the given package description.+allHsSourceDirs :: GenericPackageDescription -> [(S.Section, HsSourceDirs)]+allHsSourceDirs pkgDescrp = map fromBuildInfo buildInfos+   where+      fromBuildInfo (section, buildInfos) =+         (section, toFPs $ concat $ (map PD.hsSourceDirs) (buildInfos condVars pkgDescrp))++      buildInfos = concat [ [ (S.Library, L.buildInfosOfLib) | isJust $ PD.condLibrary pkgDescrp ]+                          , map fromExe (PD.condExecutables pkgDescrp)+                          , map fromTest (PD.condTestSuites pkgDescrp)+                          , map fromBenchm (PD.condBenchmarks pkgDescrp)+                          ]++      fromExe (name, _)    = (S.Executable name, L.buildInfosOfExe name)+      fromTest (name, _)   = (S.TestSuite name, L.buildInfosOfTest name)+      fromBenchm (name, _) = (S.Benchmark name, L.buildInfosOfBenchmark name)++      toFPs = map FP.decodeString++      condVars = CV.fromDefaults pkgDescrp+++-- | Find a cabal file starting at the given directory, going upwards the directory+--   tree until a cabal file could be found. The returned file path is absolute.+findCabalFile :: FilePath -> EitherT Error IO FilePath+findCabalFile file = do+   cabalFile <- io $ do+      dir <- absoluteDirectory file+      findCabalFile' dir++   if cabalFile == FP.empty+      then left "Couldn't find Cabal file!"+      else right . FP.encodeString $ cabalFile++   where+      findCabalFile' dir = do+         files <- filterM FS.isFile =<< (FS.listDirectory dir)+         case find isCabalFile files of+              Just file -> return $ dir </> file+              _         -> do+                 let parent = FP.parent dir+                 if parent == dir+                    then return FP.empty+                    else findCabalFile' parent++      isCabalFile file+         | Just ext <- FP.extension file+         = ext == cabalExt++         | otherwise+         = False++      cabalExt = T.pack "cabal"+++-- | Find the package database of the cabal sandbox from the given cabal file.+--   The returned file path is relative to the directory of the cabal file.+findPackageDB :: FilePath -> IO (Maybe FilePath)+findPackageDB cabalFile = do+   cabalDir <- absoluteDirectory cabalFile+   let sandboxDir = cabalDir </> FP.decodeString ".cabal-sandbox"+   hasDir <- FS.isDirectory sandboxDir+   if hasDir+      then do+         files <- filterM FS.isDirectory =<< (FS.listDirectory sandboxDir)+         return $ FP.encodeString . (stripPrefix cabalDir) <$> find isPackageDB files+      else return Nothing++   where+      isPackageDB file = "packages.conf.d" `isSuffixOf` (FP.encodeString file)+++-- | Find the dist directory of the cabal build from the given cabal file. For a non sandboxed+--   build it's just the directory 'dist' in the cabal build directory. For a sandboxed build+--   it's the directory 'dist/dist-sandbox-*'. The returned file path is relative to the+--   directory of the cabal file.+findDistDir :: FilePath -> IO (Maybe FilePath)+findDistDir cabalFile = do+   cabalDir   <- absoluteDirectory cabalFile+   let distDir = cabalDir </> FP.decodeString "dist"+   hasDistDir <- FS.isDirectory distDir+   if hasDistDir+      then do+         files <- filterM FS.isDirectory =<< (FS.listDirectory distDir)+         return $ FP.encodeString . (stripPrefix cabalDir) <$> maybe (Just distDir) Just (find isSandboxDistDir files)+      else return Nothing++   where+      isSandboxDistDir file =+         "dist-sandbox-" `isPrefixOf` (FP.encodeString . FP.filename $ file)+++absoluteDirectory :: FilePath -> IO FP.FilePath+absoluteDirectory file = do+   absFile <- absoluteFile file+   isDir   <- FS.isDirectory absFile+   if isDir+      then return absFile+      else return . FP.directory $ absFile+++absoluteFile :: FilePath -> IO FP.FilePath+absoluteFile = FS.canonicalizePath . FP.decodeString+++stripPrefix :: FP.FilePath -> FP.FilePath -> FP.FilePath+stripPrefix prefix file+   | Just stripped <- FP.stripPrefix prefix file+   = stripped++   | otherwise+   = file+++combineSections :: S.Sections -> [S.Section] -> S.Sections+combineSections S.AllSections     [] = S.AllSections+combineSections S.AllSections     ss = S.Sections ss+combineSections (S.Sections ss)    _ = S.Sections ss
+ tests/Main.hs view
@@ -0,0 +1,103 @@++module Main where++import qualified Test.Tasty as T+import qualified Test.Tasty.Golden as G+import System.IO (hPutStrLn, stderr)+import System.FilePath ((</>), (<.>))+import CabalCargs.Args+import CabalCargs.Formatting+import qualified CabalCargs.Field as F+import qualified CabalCargs.Format as Fmt+import qualified CabalCargs.CompilerArgs as CompilerArgs+import Data.List (intercalate)+++main = T.defaultMain tests++tests :: T.TestTree+tests = T.testGroup "Tests" [withoutSandboxTests, withSandboxTests]++withoutSandboxTests :: T.TestTree+withoutSandboxTests = testsWithBaseDir "withoutSandbox"++withSandboxTests :: T.TestTree+withSandboxTests = testsWithBaseDir "withSandbox"++testsWithBaseDir :: FilePath -> T.TestTree+testsWithBaseDir dir = T.testGroup dir+   [ test dir "FindCabalFile" $ defaultArgs { sourceFile = libDir }+   , test dir "FromCabalFile" $ defaultArgs { cabalFile = cabalFile } +   , test dir "FromLibSrcFile" $ defaultArgs { sourceFile = libSrcFile }+   , test dir "FromExeSrcFile" $ defaultArgs { sourceFile = exeSrcFile }++   , test dir "FindCabalFileHdevtools" $ defaultArgs { sourceFile = libDir, format = Hdevtools }+   , test dir "FromCabalFileHdevtools" $ defaultArgs { sourceFile = cabalFile, format = Hdevtools }+   , test dir "FromLibSrcFileHdevtools" $ defaultArgs { sourceFile = libSrcFile, format = Hdevtools }+   , test dir "FromExeSrcFileHdevtools" $ defaultArgs { sourceFile = exeSrcFile, format = Hdevtools }++   , test dir "FindCabalFilePure" $ defaultArgs { sourceFile = libDir, format = Pure }+   , test dir "FromCabalFilePure" $ defaultArgs { sourceFile = cabalFile, format = Pure }+   , test dir "FromLibSrcPure" $ defaultArgs { sourceFile = libSrcFile, format = Pure }+   , test dir "FromExeSrcFilePure" $ defaultArgs { sourceFile = exeSrcFile, format = Pure }++   , test dir "AllOfLib" $ defaultArgs { library = True, cabalFile = cabalFile }+   , test dir "AllOfExe" $ defaultArgs { executable = ["cabal-cargs"], cabalFile = cabalFile }+   , test dir "AllOfTest" $ defaultArgs { testSuite = ["tests"], cabalFile = cabalFile }++   , test dir "OnlyGhcOptionsOfLib" $ defaultArgs { library = True, cabalFile = cabalFile, only = [F.Ghc_Options] }+   , test dir "OnlyGhcOptionsOfExe" $ defaultArgs { executable = ["cabal-cargs"], cabalFile = cabalFile, only = [F.Ghc_Options] }+   , test dir "OnlyGhcOptionsOfTest" $ defaultArgs { testSuite = ["tests"], cabalFile = cabalFile, only = [F.Ghc_Options] }++   , test dir "OnlyPureSrcDirsOfLib" $ defaultArgs { library = True, cabalFile = cabalFile, only = [F.Hs_Source_Dirs], format = Pure }+   , test dir "OnlyPureSrcDirsOfExe" $ defaultArgs { executable = ["cabal-cargs"], cabalFile = cabalFile, only = [F.Hs_Source_Dirs], format = Pure }+   , test dir "OnlyPureSrcDirsOfTest" $ defaultArgs { testSuite = ["tests"], cabalFile = cabalFile, only = [F.Hs_Source_Dirs], format = Pure }++   , test dir "EnableFlag" $ defaultArgs { cabalFile = cabalFile, enable = ["default_false_flag"] }+   , test dir "DisableFlag" $ defaultArgs { cabalFile = cabalFile, disable = ["default_true_flag"] }+   , test dir "EnableAndDisableFlag" $ defaultArgs { cabalFile = cabalFile, enable = ["default_false_flag"], disable = ["default_true_flag"] }+   ]++   where+      cabalFile  = Just $ inputDir </> "test.cabal"+      libSrcFile = Just $ inputDir </> "lib" </> "Source.hs"+      exeSrcFile = Just $ inputDir </> "exe" </> "Source.hs"+      libDir     = Just $ inputDir </> "lib"+      inputDir   = "tests" </> "inputFiles" </> dir+++test :: FilePath -> String -> Args -> T.TestTree+test dir testName args =+   G.goldenVsFileDiff (testName ++ " " ++ dir) diff goldenFile outputFile command+   where+      command = do+         let formatting = format args+         cargs <- CompilerArgs.fromCmdArgs args+         case cargs of+              Left error -> do+                 hPutStrLn stderr ("cabal-cargs: " ++ error)++              Right cargs_ -> do+                 writeFile outputFile (intercalate " " $ Fmt.format formatting cargs_)++      diff ref new = ["diff", "-u", ref, new]+      goldenFile   = "tests" </> "goldenFiles" </> dir </> testName <.> "txt"+      outputFile   = "tests" </> "outputFiles" </> dir </> testName <.> "txt"+++defaultArgs :: Args+defaultArgs = Args+   { library    = False+   , executable = []+   , testSuite  = []+   , benchmark  = []+   , only       = []+   , format     = Ghc+   , sourceFile = Nothing+   , cabalFile  = Nothing+   , enable     = []+   , disable    = []+   , os         = Nothing+   , arch       = Nothing+   , relative   = True+   }
+ tests/goldenFiles/withSandbox/AllOfExe.txt view
@@ -0,0 +1,1 @@+-iexe -W -optP-DEXE -package-conf=.cabal-sandbox/x86_64-linux-ghc-7.6.2-packages.conf.d -idist/dist-sandbox-6d1acfa0/build/autogen -Idist/dist-sandbox-6d1acfa0/build/autogen -optP-include -optPcabal_macros.h
+ tests/goldenFiles/withSandbox/AllOfLib.txt view
@@ -0,0 +1,1 @@+-ilib -W -optP-DLIB -package-conf=.cabal-sandbox/x86_64-linux-ghc-7.6.2-packages.conf.d -idist/dist-sandbox-6d1acfa0/build/autogen -Idist/dist-sandbox-6d1acfa0/build/autogen -optP-include -optPcabal_macros.h
+ tests/goldenFiles/withSandbox/AllOfTest.txt view
@@ -0,0 +1,1 @@+-itests -W -package-conf=.cabal-sandbox/x86_64-linux-ghc-7.6.2-packages.conf.d -idist/dist-sandbox-6d1acfa0/build/autogen -Idist/dist-sandbox-6d1acfa0/build/autogen -optP-include -optPcabal_macros.h
+ tests/goldenFiles/withSandbox/DisableFlag.txt view
@@ -0,0 +1,1 @@+-ilib -iexe -itests -W -optP-DEXE -package-conf=.cabal-sandbox/x86_64-linux-ghc-7.6.2-packages.conf.d -idist/dist-sandbox-6d1acfa0/build/autogen -Idist/dist-sandbox-6d1acfa0/build/autogen -optP-include -optPcabal_macros.h
+ tests/goldenFiles/withSandbox/EnableAndDisableFlag.txt view
@@ -0,0 +1,1 @@+-ilib -iexe -itests -W -optP-DEXE -optP-DTEST -package-conf=.cabal-sandbox/x86_64-linux-ghc-7.6.2-packages.conf.d -idist/dist-sandbox-6d1acfa0/build/autogen -Idist/dist-sandbox-6d1acfa0/build/autogen -optP-include -optPcabal_macros.h
+ tests/goldenFiles/withSandbox/EnableFlag.txt view
@@ -0,0 +1,1 @@+-ilib -iexe -itests -W -optP-DLIB -optP-DEXE -optP-DTEST -package-conf=.cabal-sandbox/x86_64-linux-ghc-7.6.2-packages.conf.d -idist/dist-sandbox-6d1acfa0/build/autogen -Idist/dist-sandbox-6d1acfa0/build/autogen -optP-include -optPcabal_macros.h
+ tests/goldenFiles/withSandbox/FindCabalFile.txt view
@@ -0,0 +1,1 @@+-ilib -iexe -itests -W -optP-DLIB -optP-DEXE -package-conf=.cabal-sandbox/x86_64-linux-ghc-7.6.2-packages.conf.d -idist/dist-sandbox-6d1acfa0/build/autogen -Idist/dist-sandbox-6d1acfa0/build/autogen -optP-include -optPcabal_macros.h
+ tests/goldenFiles/withSandbox/FindCabalFileHdevtools.txt view
@@ -0,0 +1,1 @@+-g-ilib -g-iexe -g-itests -g-W -g-optP-DLIB -g-optP-DEXE -g-package-conf=.cabal-sandbox/x86_64-linux-ghc-7.6.2-packages.conf.d -g-idist/dist-sandbox-6d1acfa0/build/autogen -g-Idist/dist-sandbox-6d1acfa0/build/autogen -g-optP-include -g-optPcabal_macros.h --socket=.hdevtools.sock
+ tests/goldenFiles/withSandbox/FindCabalFilePure.txt view
@@ -0,0 +1,1 @@+lib exe tests -W -DLIB -DEXE .cabal-sandbox/x86_64-linux-ghc-7.6.2-packages.conf.d dist/dist-sandbox-6d1acfa0/build/autogen dist/dist-sandbox-6d1acfa0/build/autogen cabal_macros.h
+ tests/goldenFiles/withSandbox/FromCabalFile.txt view
@@ -0,0 +1,1 @@+-ilib -iexe -itests -W -optP-DLIB -optP-DEXE -package-conf=.cabal-sandbox/x86_64-linux-ghc-7.6.2-packages.conf.d -idist/dist-sandbox-6d1acfa0/build/autogen -Idist/dist-sandbox-6d1acfa0/build/autogen -optP-include -optPcabal_macros.h
+ tests/goldenFiles/withSandbox/FromCabalFileHdevtools.txt view
@@ -0,0 +1,1 @@+-g-ilib -g-iexe -g-itests -g-W -g-optP-DLIB -g-optP-DEXE -g-package-conf=.cabal-sandbox/x86_64-linux-ghc-7.6.2-packages.conf.d -g-idist/dist-sandbox-6d1acfa0/build/autogen -g-Idist/dist-sandbox-6d1acfa0/build/autogen -g-optP-include -g-optPcabal_macros.h --socket=.hdevtools.sock
+ tests/goldenFiles/withSandbox/FromCabalFilePure.txt view
@@ -0,0 +1,1 @@+lib exe tests -W -DLIB -DEXE .cabal-sandbox/x86_64-linux-ghc-7.6.2-packages.conf.d dist/dist-sandbox-6d1acfa0/build/autogen dist/dist-sandbox-6d1acfa0/build/autogen cabal_macros.h
+ tests/goldenFiles/withSandbox/FromExeSrcFile.txt view
@@ -0,0 +1,1 @@+-iexe -W -optP-DEXE -package-conf=.cabal-sandbox/x86_64-linux-ghc-7.6.2-packages.conf.d -idist/dist-sandbox-6d1acfa0/build/autogen -Idist/dist-sandbox-6d1acfa0/build/autogen -optP-include -optPcabal_macros.h
+ tests/goldenFiles/withSandbox/FromExeSrcFileHdevtools.txt view
@@ -0,0 +1,1 @@+-g-iexe -g-W -g-optP-DEXE -g-package-conf=.cabal-sandbox/x86_64-linux-ghc-7.6.2-packages.conf.d -g-idist/dist-sandbox-6d1acfa0/build/autogen -g-Idist/dist-sandbox-6d1acfa0/build/autogen -g-optP-include -g-optPcabal_macros.h --socket=.hdevtools.sock
+ tests/goldenFiles/withSandbox/FromExeSrcFilePure.txt view
@@ -0,0 +1,1 @@+exe -W -DEXE .cabal-sandbox/x86_64-linux-ghc-7.6.2-packages.conf.d dist/dist-sandbox-6d1acfa0/build/autogen dist/dist-sandbox-6d1acfa0/build/autogen cabal_macros.h
+ tests/goldenFiles/withSandbox/FromExeSrcPure.txt view
@@ -0,0 +1,1 @@+exe -W -DEXE .cabal-sandbox/x86_64-linux-ghc-7.6.2-packages.conf.d dist/dist-sandbox-6d1acfa0/build/autogen dist/dist-sandbox-6d1acfa0/build/autogen cabal_macros.h
+ tests/goldenFiles/withSandbox/FromLibSrcFile.txt view
@@ -0,0 +1,1 @@+-ilib -W -optP-DLIB -package-conf=.cabal-sandbox/x86_64-linux-ghc-7.6.2-packages.conf.d -idist/dist-sandbox-6d1acfa0/build/autogen -Idist/dist-sandbox-6d1acfa0/build/autogen -optP-include -optPcabal_macros.h
+ tests/goldenFiles/withSandbox/FromLibSrcFileHdevtools.txt view
@@ -0,0 +1,1 @@+-g-ilib -g-W -g-optP-DLIB -g-package-conf=.cabal-sandbox/x86_64-linux-ghc-7.6.2-packages.conf.d -g-idist/dist-sandbox-6d1acfa0/build/autogen -g-Idist/dist-sandbox-6d1acfa0/build/autogen -g-optP-include -g-optPcabal_macros.h --socket=.hdevtools.sock
+ tests/goldenFiles/withSandbox/FromLibSrcPure.txt view
@@ -0,0 +1,1 @@+lib -W -DLIB .cabal-sandbox/x86_64-linux-ghc-7.6.2-packages.conf.d dist/dist-sandbox-6d1acfa0/build/autogen dist/dist-sandbox-6d1acfa0/build/autogen cabal_macros.h
+ tests/goldenFiles/withSandbox/OnlyGhcOptionsOfExe.txt view
@@ -0,0 +1,1 @@+-W 
+ tests/goldenFiles/withSandbox/OnlyGhcOptionsOfLib.txt view
@@ -0,0 +1,1 @@+-W 
+ tests/goldenFiles/withSandbox/OnlyGhcOptionsOfTest.txt view
@@ -0,0 +1,1 @@+-W 
+ tests/goldenFiles/withSandbox/OnlyPureSrcDirsOfExe.txt view
@@ -0,0 +1,1 @@+exe
+ tests/goldenFiles/withSandbox/OnlyPureSrcDirsOfLib.txt view
@@ -0,0 +1,1 @@+lib
+ tests/goldenFiles/withSandbox/OnlyPureSrcDirsOfTest.txt view
@@ -0,0 +1,1 @@+tests
+ tests/goldenFiles/withoutSandbox/AllOfExe.txt view
@@ -0,0 +1,1 @@+-iexe -W -optP-DEXE  -idist/build/autogen -Idist/build/autogen -optP-include -optPcabal_macros.h
+ tests/goldenFiles/withoutSandbox/AllOfLib.txt view
@@ -0,0 +1,1 @@+-ilib -W -optP-DLIB  -idist/build/autogen -Idist/build/autogen -optP-include -optPcabal_macros.h
+ tests/goldenFiles/withoutSandbox/AllOfTest.txt view
@@ -0,0 +1,1 @@+-itests -W  -idist/build/autogen -Idist/build/autogen -optP-include -optPcabal_macros.h
+ tests/goldenFiles/withoutSandbox/DisableFlag.txt view
@@ -0,0 +1,1 @@+-ilib -iexe -itests -W -optP-DEXE  -idist/build/autogen -Idist/build/autogen -optP-include -optPcabal_macros.h
+ tests/goldenFiles/withoutSandbox/EnableAndDisableFlag.txt view
@@ -0,0 +1,1 @@+-ilib -iexe -itests -W -optP-DEXE -optP-DTEST  -idist/build/autogen -Idist/build/autogen -optP-include -optPcabal_macros.h
+ tests/goldenFiles/withoutSandbox/EnableFlag.txt view
@@ -0,0 +1,1 @@+-ilib -iexe -itests -W -optP-DLIB -optP-DEXE -optP-DTEST  -idist/build/autogen -Idist/build/autogen -optP-include -optPcabal_macros.h
+ tests/goldenFiles/withoutSandbox/FindCabalFile.txt view
@@ -0,0 +1,1 @@+-ilib -iexe -itests -W -optP-DLIB -optP-DEXE  -idist/build/autogen -Idist/build/autogen -optP-include -optPcabal_macros.h
+ tests/goldenFiles/withoutSandbox/FindCabalFileHdevtools.txt view
@@ -0,0 +1,1 @@+-g-ilib -g-iexe -g-itests -g-W -g-optP-DLIB -g-optP-DEXE -g -g-idist/build/autogen -g-Idist/build/autogen -g-optP-include -g-optPcabal_macros.h --socket=.hdevtools.sock
+ tests/goldenFiles/withoutSandbox/FindCabalFilePure.txt view
@@ -0,0 +1,1 @@+lib exe tests -W -DLIB -DEXE dist/build/autogen dist/build/autogen cabal_macros.h
+ tests/goldenFiles/withoutSandbox/FromCabalFile.txt view
@@ -0,0 +1,1 @@+-ilib -iexe -itests -W -optP-DLIB -optP-DEXE  -idist/build/autogen -Idist/build/autogen -optP-include -optPcabal_macros.h
+ tests/goldenFiles/withoutSandbox/FromCabalFileHdevtools.txt view
@@ -0,0 +1,1 @@+-g-ilib -g-iexe -g-itests -g-W -g-optP-DLIB -g-optP-DEXE -g -g-idist/build/autogen -g-Idist/build/autogen -g-optP-include -g-optPcabal_macros.h --socket=.hdevtools.sock
+ tests/goldenFiles/withoutSandbox/FromCabalFilePure.txt view
@@ -0,0 +1,1 @@+lib exe tests -W -DLIB -DEXE dist/build/autogen dist/build/autogen cabal_macros.h
+ tests/goldenFiles/withoutSandbox/FromExeSrcFile.txt view
@@ -0,0 +1,1 @@+-iexe -W -optP-DEXE  -idist/build/autogen -Idist/build/autogen -optP-include -optPcabal_macros.h
+ tests/goldenFiles/withoutSandbox/FromExeSrcFileHdevtools.txt view
@@ -0,0 +1,1 @@+-g-iexe -g-W -g-optP-DEXE -g -g-idist/build/autogen -g-Idist/build/autogen -g-optP-include -g-optPcabal_macros.h --socket=.hdevtools.sock
+ tests/goldenFiles/withoutSandbox/FromExeSrcFilePure.txt view
@@ -0,0 +1,1 @@+exe -W -DEXE dist/build/autogen dist/build/autogen cabal_macros.h
+ tests/goldenFiles/withoutSandbox/FromExeSrcPure.txt view
@@ -0,0 +1,1 @@+exe -W -DEXE dist/build/autogen dist/build/autogen cabal_macros.h
+ tests/goldenFiles/withoutSandbox/FromLibSrcFile.txt view
@@ -0,0 +1,1 @@+-ilib -W -optP-DLIB  -idist/build/autogen -Idist/build/autogen -optP-include -optPcabal_macros.h
+ tests/goldenFiles/withoutSandbox/FromLibSrcFileHdevtools.txt view
@@ -0,0 +1,1 @@+-g-ilib -g-W -g-optP-DLIB -g -g-idist/build/autogen -g-Idist/build/autogen -g-optP-include -g-optPcabal_macros.h --socket=.hdevtools.sock
+ tests/goldenFiles/withoutSandbox/FromLibSrcPure.txt view
@@ -0,0 +1,1 @@+lib -W -DLIB dist/build/autogen dist/build/autogen cabal_macros.h
+ tests/goldenFiles/withoutSandbox/OnlyGhcOptionsOfExe.txt view
@@ -0,0 +1,1 @@+-W 
+ tests/goldenFiles/withoutSandbox/OnlyGhcOptionsOfLib.txt view
@@ -0,0 +1,1 @@+-W 
+ tests/goldenFiles/withoutSandbox/OnlyGhcOptionsOfTest.txt view
@@ -0,0 +1,1 @@+-W 
+ tests/goldenFiles/withoutSandbox/OnlyPureSrcDirsOfExe.txt view
@@ -0,0 +1,1 @@+exe
+ tests/goldenFiles/withoutSandbox/OnlyPureSrcDirsOfLib.txt view
@@ -0,0 +1,1 @@+lib
+ tests/goldenFiles/withoutSandbox/OnlyPureSrcDirsOfTest.txt view
@@ -0,0 +1,1 @@+tests
+ tests/inputFiles/withSandbox/.cabal-sandbox/x86_64-linux-ghc-7.6.2-packages.conf.d/.gitignore view
@@ -0,0 +1,2 @@+*+!.gitignore
+ tests/inputFiles/withSandbox/dist/dist-sandbox-6d1acfa0/.gitignore view
@@ -0,0 +1,2 @@+*+!.gitignore
+ tests/inputFiles/withSandbox/exe/Source.hs view
+ tests/inputFiles/withSandbox/lib/Source.hs view
+ tests/inputFiles/withSandbox/test.cabal view
@@ -0,0 +1,60 @@+name: cabal-cargs+version: 0.1+cabal-version: >=1.9.2+build-type: Simple+license: BSD3+license-file: LICENSE+maintainer: daniel.trstenjak@gmail.com+synopsis: A command line program for extracting compiler arguments from a cabal file.+description: A command line program for extracting compiler arguments from a cabal file.+category: Utils+author: Daniel Trstenjak+data-dir: ""+extra-source-files: README.md+ +source-repository head+    type: git+    location: https://github.com/dan-t/cabal-cargs+ +flag default_false_flag+  default: False++flag default_true_flag+  default: True++library+    build-depends: base >=3 && <5, cmdargs >=0.10.5 && <0.11,+                   lens >=4.0.1 && <4.1, directory -any, strict >=0.3.2 && <0.4,+                   transformers >=0.3.0.0 && <0.4, either >=4.1.1 && <4.2,+                   text >=1.1.0.1 && <1.2, system-filepath >=0.4.9 && <0.5,+                   system-fileio >=0.3.12 && <0.4, Cabal >=1.18.0 && <1.19+    exposed-modules: CabalCargs.Args CabalCargs.Field CabalCargs.Fields+                     CabalCargs.Formatting CabalCargs.Format CabalCargs.Spec+                     CabalCargs.Sections CabalCargs.CompilerArgs CabalCargs.Lenses+    exposed: True+    buildable: True+    if flag(default_true_flag)+        cpp-options: -DLIB+    hs-source-dirs: lib+    other-modules: Paths_cabal_cargs+    ghc-options: -W+ +executable cabal-cargs+    build-depends: base >=3 && <5, cabal-cargs -any+    main-is: Main.hs+    buildable: True+    hs-source-dirs: exe+    ghc-options: -W+    cpp-options: -DEXE++test-suite tests+    build-depends: base >=3 && <5, tasty ==0.7.*,+                   tasty-golden >=2.2.0.2 && <2.3, filepath >=1.3.0.1 && <1.4,+                   cabal-cargs -any+    type: exitcode-stdio-1.0+    main-is: Main.hs+    buildable: True+    hs-source-dirs: tests+    ghc-options: -W+    if flag(default_false_flag)+        cpp-options: -DTEST
+ tests/inputFiles/withoutSandbox/dist/.gitignore view
@@ -0,0 +1,2 @@+*+!.gitignore
+ tests/inputFiles/withoutSandbox/exe/Source.hs view
+ tests/inputFiles/withoutSandbox/lib/Source.hs view
+ tests/inputFiles/withoutSandbox/test.cabal view
@@ -0,0 +1,60 @@+name: cabal-cargs+version: 0.1+cabal-version: >=1.9.2+build-type: Simple+license: BSD3+license-file: LICENSE+maintainer: daniel.trstenjak@gmail.com+synopsis: A command line program for extracting compiler arguments from a cabal file.+description: A command line program for extracting compiler arguments from a cabal file.+category: Utils+author: Daniel Trstenjak+data-dir: ""+extra-source-files: README.md+ +source-repository head+    type: git+    location: https://github.com/dan-t/cabal-cargs+ +flag default_false_flag+  default: False++flag default_true_flag+  default: True++library+    build-depends: base >=3 && <5, cmdargs >=0.10.5 && <0.11,+                   lens >=4.0.1 && <4.1, directory -any, strict >=0.3.2 && <0.4,+                   transformers >=0.3.0.0 && <0.4, either >=4.1.1 && <4.2,+                   text >=1.1.0.1 && <1.2, system-filepath >=0.4.9 && <0.5,+                   system-fileio >=0.3.12 && <0.4, Cabal >=1.18.0 && <1.19+    exposed-modules: CabalCargs.Args CabalCargs.Field CabalCargs.Fields+                     CabalCargs.Formatting CabalCargs.Format CabalCargs.Spec+                     CabalCargs.Sections CabalCargs.CompilerArgs CabalCargs.Lenses+    exposed: True+    buildable: True+    if flag(default_true_flag)+        cpp-options: -DLIB+    hs-source-dirs: lib+    other-modules: Paths_cabal_cargs+    ghc-options: -W+ +executable cabal-cargs+    build-depends: base >=3 && <5, cabal-cargs -any+    main-is: Main.hs+    buildable: True+    hs-source-dirs: exe+    ghc-options: -W+    cpp-options: -DEXE++test-suite tests+    build-depends: base >=3 && <5, tasty ==0.7.*,+                   tasty-golden >=2.2.0.2 && <2.3, filepath >=1.3.0.1 && <1.4,+                   cabal-cargs -any+    type: exitcode-stdio-1.0+    main-is: Main.hs+    buildable: True+    hs-source-dirs: tests+    ghc-options: -W+    if flag(default_false_flag)+        cpp-options: -DTEST
+ tests/mkGoldens view
@@ -0,0 +1,32 @@+#!/usr/bin/env bash+dir=$1+cabal-cargs --relative --sourcefile=inputFiles/$dir/lib > goldenFiles/$dir/FindCabalFile.txt+cabal-cargs --relative --cabalfile=inputFiles/$dir/test.cabal > goldenFiles/$dir/FromCabalFile.txt+cabal-cargs --relative --sourcefile=inputFiles/$dir/lib/Source.hs > goldenFiles/$dir/FromLibSrcFile.txt+cabal-cargs --relative --sourcefile=inputFiles/$dir/exe/Source.hs > goldenFiles/$dir/FromExeSrcFile.txt+.txt+cabal-cargs --relative --format=hdevtools --sourcefile=inputFiles/$dir/lib > goldenFiles/$dir/FindCabalFileHdevtools.txt+cabal-cargs --relative --format=hdevtools --cabalfile=inputFiles/$dir/test.cabal > goldenFiles/$dir/FromCabalFileHdevtools.txt+cabal-cargs --relative --format=hdevtools --sourcefile=inputFiles/$dir/lib/Source.hs > goldenFiles/$dir/FromLibSrcFileHdevtools.txt+cabal-cargs --relative --format=hdevtools --sourcefile=inputFiles/$dir/exe/Source.hs > goldenFiles/$dir/FromExeSrcFileHdevtools.txt++cabal-cargs --relative --format=pure --sourcefile=inputFiles/$dir/lib > goldenFiles/$dir/FindCabalFilePure.txt+cabal-cargs --relative --format=pure --cabalfile=inputFiles/$dir/test.cabal > goldenFiles/$dir/FromCabalFilePure.txt+cabal-cargs --relative --format=pure --sourcefile=inputFiles/$dir/lib/Source.hs > goldenFiles/$dir/FromLibSrcPure.txt+cabal-cargs --relative --format=pure --sourcefile=inputFiles/$dir/exe/Source.hs > goldenFiles/$dir/FromExeSrcFilePure.txt++cabal-cargs --relative --library --cabalfile=inputFiles/$dir/test.cabal > goldenFiles/$dir/AllOfLib.txt+cabal-cargs --relative --executable=cabal-cargs --cabalfile=inputFiles/$dir/test.cabal > goldenFiles/$dir/AllOfExe.txt+cabal-cargs --relative --testsuite=tests --cabalfile=inputFiles/$dir/test.cabal > goldenFiles/$dir/AllOfTest.txt++cabal-cargs --relative --library --only=ghc_options --cabalfile=inputFiles/$dir/test.cabal > goldenFiles/$dir/OnlyGhcOptionsOfLib.txt+cabal-cargs --relative --executable=cabal-cargs --only=ghc_options --cabalfile=inputFiles/$dir/test.cabal > goldenFiles/$dir/OnlyGhcOptionsOfExe.txt+cabal-cargs --relative --testsuite=tests --only=ghc_options --cabalfile=inputFiles/$dir/test.cabal > goldenFiles/$dir/OnlyGhcOptionsOfTest.txt++cabal-cargs --relative --library --only=hs_source_dirs --format=pure --cabalfile=inputFiles/$dir/test.cabal > goldenFiles/$dir/OnlyPureSrcDirsOfLib.txt+cabal-cargs --relative --executable=cabal-cargs --only=hs_source_dirs --format=pure --cabalfile=inputFiles/$dir/test.cabal > goldenFiles/$dir/OnlyPureSrcDirsOfExe.txt+cabal-cargs --relative --testsuite=tests --only=hs_source_dirs --format=pure --cabalfile=inputFiles/$dir/test.cabal > goldenFiles/$dir/OnlyPureSrcDirsOfTest.txt++cabal-cargs --relative --enable=default_false_flag --cabalfile=inputFiles/$dir/test.cabal > goldenFiles/$dir/EnableFlag.txt+cabal-cargs --relative --disable=default_true_flag --cabalfile=inputFiles/$dir/test.cabal > goldenFiles/$dir/DisableFlag.txt+cabal-cargs --relative --enable=default_false_flag --disable=default_true_flag --cabalfile=inputFiles/$dir/test.cabal > goldenFiles/$dir/EnableAndDisableFlag.txt
+ tests/outputFiles/withSandbox/.gitignore view
@@ -0,0 +1,2 @@+*+!.gitignore
+ tests/outputFiles/withoutSandbox/.gitignore view
@@ -0,0 +1,2 @@+*+!.gitignore
+ tests/takeOutputsAsGoldens view
@@ -0,0 +1,5 @@+#!/usr/bin/env bash+dir=$1+for output in `ls outputFiles/$dir` ; do+   cp outputFiles/$dir/$output goldenFiles/$dir/$output+done