2020-12-16 17:53:55 +03:00
|
|
|
{-# LANGUAGE DeriveGeneric #-}
|
2020-05-30 12:52:37 +03:00
|
|
|
{-# LANGUAGE RecordWildCards #-}
|
2020-12-02 18:33:37 +03:00
|
|
|
|
2020-05-30 12:52:37 +03:00
|
|
|
module Project where
|
|
|
|
|
2020-12-16 17:53:55 +03:00
|
|
|
import Data.Hashable
|
|
|
|
import GHC.Generics (Generic)
|
2020-05-30 12:52:37 +03:00
|
|
|
import Info
|
|
|
|
import Util
|
|
|
|
|
2020-05-12 21:24:40 +03:00
|
|
|
data Target = Native | Target String
|
2020-12-02 18:33:37 +03:00
|
|
|
|
2020-05-12 21:24:40 +03:00
|
|
|
instance Show Target where
|
|
|
|
show Native = "native"
|
|
|
|
show (Target x) = x
|
|
|
|
|
2020-05-30 12:52:37 +03:00
|
|
|
-- | Project (represents a lot of useful information for working at the REPL and building executables)
|
2020-12-03 14:02:58 +03:00
|
|
|
data Project = Project
|
|
|
|
{ projectTitle :: String,
|
|
|
|
projectIncludes :: [Includer],
|
2021-04-01 10:42:42 +03:00
|
|
|
projectPreproc :: [String],
|
2020-12-03 14:02:58 +03:00
|
|
|
projectCFlags :: [String],
|
|
|
|
projectLibFlags :: [String],
|
|
|
|
projectPkgConfigFlags :: [String],
|
|
|
|
projectFiles :: [(FilePath, ReloadMode)],
|
|
|
|
projectAlreadyLoaded :: [FilePath],
|
|
|
|
projectEchoC :: Bool,
|
|
|
|
projectLibDir :: FilePath,
|
|
|
|
projectCarpDir :: FilePath,
|
|
|
|
projectOutDir :: FilePath,
|
|
|
|
projectDocsDir :: FilePath,
|
|
|
|
projectDocsLogo :: FilePath,
|
|
|
|
projectDocsPrelude :: String,
|
|
|
|
projectDocsURL :: String,
|
|
|
|
projectDocsGenerateIndex :: Bool,
|
|
|
|
projectDocsStyling :: String,
|
|
|
|
projectPrompt :: String,
|
|
|
|
projectCarpSearchPaths :: [FilePath],
|
|
|
|
projectPrintTypedAST :: Bool,
|
|
|
|
projectCompiler :: String,
|
|
|
|
projectTarget :: Target,
|
|
|
|
projectCore :: Bool,
|
|
|
|
projectEchoCompilationCommand :: Bool,
|
|
|
|
projectCanExecute :: Bool,
|
|
|
|
projectFilePathPrintLength :: FilePathPrintLength,
|
|
|
|
projectGenerateOnly :: Bool,
|
|
|
|
projectBalanceHints :: Bool,
|
|
|
|
projectForceReload :: Bool, -- Setting this to true will make the `load-once` command work just like `load`.
|
|
|
|
projectCModules :: [FilePath],
|
|
|
|
projectLoadStack :: [FilePath]
|
|
|
|
}
|
2020-05-30 12:52:37 +03:00
|
|
|
|
|
|
|
projectFlags :: Project -> String
|
|
|
|
projectFlags proj = joinWithSpace (projectCFlags proj ++ projectLibFlags proj)
|
|
|
|
|
|
|
|
instance Show Project where
|
2020-12-16 17:53:55 +03:00
|
|
|
show Project {..} =
|
2020-12-02 18:33:37 +03:00
|
|
|
unlines
|
|
|
|
[ "Title: " ++ projectTitle,
|
|
|
|
"Compiler: " ++ projectCompiler,
|
|
|
|
"Target: " ++ show projectTarget,
|
|
|
|
"Includes:\n " ++ joinIndented (map show projectIncludes),
|
2021-03-04 09:29:52 +03:00
|
|
|
"Preprocessor directives:\n " ++ joinIndented (map show projectPreproc),
|
2020-12-02 18:33:37 +03:00
|
|
|
"Cflags:\n " ++ joinIndented projectCFlags,
|
|
|
|
"Library flags:\n " ++ joinIndented projectLibFlags,
|
|
|
|
"Flags for pkg-config:\n " ++ joinIndented projectPkgConfigFlags,
|
|
|
|
"Carp source files:\n " ++ joinIndented (map showLoader projectFiles),
|
|
|
|
"Already loaded:\n " ++ joinIndented projectAlreadyLoaded,
|
|
|
|
"Echo C: " ++ showB projectEchoC,
|
|
|
|
"Echo compilation command: " ++ showB projectEchoCompilationCommand,
|
|
|
|
"Can execute: " ++ showB projectCanExecute,
|
|
|
|
"Output directory: " ++ projectOutDir,
|
|
|
|
"Docs directory: " ++ projectDocsDir,
|
|
|
|
"Docs logo: " ++ projectDocsLogo,
|
|
|
|
"Docs prelude: " ++ projectDocsPrelude,
|
|
|
|
"Docs Project URL: " ++ projectDocsURL,
|
|
|
|
"Docs generate index: " ++ showB projectDocsGenerateIndex,
|
|
|
|
"Docs CSS URL: " ++ projectDocsStyling,
|
|
|
|
"Library directory: " ++ projectLibDir,
|
|
|
|
"CARP_DIR: " ++ projectCarpDir,
|
|
|
|
"Prompt: " ++ projectPrompt,
|
|
|
|
"Using Core: " ++ showB projectCore,
|
|
|
|
"Search paths for 'load' command:\n " ++ joinIndented projectCarpSearchPaths,
|
|
|
|
"Print AST (with 'info' command): " ++ showB projectPrintTypedAST,
|
|
|
|
"File path print length (when using --check): " ++ show projectFilePathPrintLength,
|
|
|
|
"Generate Only: " ++ showB projectGenerateOnly,
|
|
|
|
"Balance Hints: " ++ showB projectBalanceHints,
|
|
|
|
"Force Reload: " ++ showB projectForceReload,
|
|
|
|
"C modules:\n " ++ joinIndented projectCModules,
|
|
|
|
"Load stack:\n " ++ joinIndented projectLoadStack
|
|
|
|
]
|
|
|
|
where
|
|
|
|
showB b = if b then "true" else "false"
|
|
|
|
joinIndented = joinWith "\n "
|
2020-05-30 12:52:37 +03:00
|
|
|
|
|
|
|
-- | Represent the inclusion of a C header file, either like <string.h> or "string.h"
|
2020-12-02 18:33:37 +03:00
|
|
|
data Includer
|
|
|
|
= SystemInclude String
|
|
|
|
| RelativeInclude String
|
2020-12-16 17:53:55 +03:00
|
|
|
deriving (Eq, Generic)
|
|
|
|
|
|
|
|
instance Hashable Includer
|
2020-05-30 12:52:37 +03:00
|
|
|
|
|
|
|
instance Show Includer where
|
|
|
|
show (SystemInclude file) = "<" ++ file ++ ">"
|
|
|
|
show (RelativeInclude file) = "\"" ++ file ++ "\""
|
|
|
|
|
|
|
|
-- | This flag is used on Carp source files to decide wether to reload them or not when calling `(reload)` / `:r`
|
2020-12-02 18:33:37 +03:00
|
|
|
data ReloadMode = DoesReload | Frozen deriving (Show)
|
2020-05-30 12:52:37 +03:00
|
|
|
|
|
|
|
showLoader :: (FilePath, ReloadMode) -> String
|
|
|
|
showLoader (fp, DoesReload) = fp
|
|
|
|
showLoader (fp, Frozen) = fp ++ " (frozen)"
|