{- ----------------------------------------------------------------------------- Copyright 2020-2021 Kevin P. Barry Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ----------------------------------------------------------------------------- -} -- Author: Kevin P. Barry [ta0kira@gmail.com] {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE Trustworthy #-} module Cli.CompileOptions ( CompileOptions(..), CompileMode(..), ExtraSource(..), ForceMode(..), HelpMode(..), LinkerMode(..), emptyCompileOptions, getLinkFlags, getSourceCategories, getSourceDeps, getSourceFile, isCompileBinary, isCompileFast, isCompileIncremental, isCompileRecompile, isCompileUnspecified, isCreateTemplates, isExecuteTests, maybeDisableHelp, -- Generated by Lens >>> coExtraFiles, coExtraPaths, coForce, coHelp, coMode, coParallel, coPaths, coPrivateDeps, coPublicDeps, coSourcePrefix, -- Generated by Lens <<< ) where import Lens.Micro.TH (makeLenses) import Types.TypeCategory (FunctionName) import Types.TypeInstance (CategoryName) emptyCompileOptions :: CompileOptions emptyCompileOptions = CompileOptions { _coHelp = HelpUnspecified, _coPublicDeps = [], _coPrivateDeps = [], _coPaths = [], _coExtraFiles = [], _coExtraPaths = [], _coSourcePrefix = "", _coMode = CompileUnspecified, _coForce = DoNotForce, _coParallel = 0 } data ExtraSource = CategorySource { csSource :: FilePath, csCategories :: [CategoryName], csRequires :: [CategoryName] } | OtherSource { osSource :: FilePath } deriving (Eq,Show) getSourceFile :: ExtraSource -> String getSourceFile (CategorySource s _ _) = s getSourceFile (OtherSource s) = s getSourceCategories :: ExtraSource -> [CategoryName] getSourceCategories (CategorySource _ cs _) = cs getSourceCategories (OtherSource _) = [] getSourceDeps :: ExtraSource -> [CategoryName] getSourceDeps (CategorySource _ _ ds) = ds getSourceDeps (OtherSource _) = [] data HelpMode = HelpNeeded | HelpNotNeeded | HelpUnspecified deriving (Eq,Show) data ForceMode = DoNotForce | ForceAll deriving (Eq,Ord,Show) data CompileMode = CompileBinary { cbCategory :: CategoryName, cbFunction :: FunctionName, cbLinker :: LinkerMode, cbOutputName :: FilePath, cbLinkFlags :: [String] } | CompileFast { cfCategory :: CategoryName, cfFunction :: FunctionName, cfSource :: FilePath } | ExecuteTests { etInclude :: [FilePath], etCallLog :: Maybe FilePath } | CompileIncremental { ciLinkFlags :: [String] } | CompileRecompile | CompileRecompileRecursive | CreateTemplates | CompileUnspecified deriving (Eq,Show) data LinkerMode = LinkStatic | LinkDynamic deriving (Eq,Show) isCompileBinary :: CompileMode -> Bool isCompileBinary (CompileBinary _ _ _ _ _) = True isCompileBinary _ = False isCompileFast :: CompileMode -> Bool isCompileFast (CompileFast _ _ _) = True isCompileFast _ = False isCompileIncremental :: CompileMode -> Bool isCompileIncremental (CompileIncremental _) = True isCompileIncremental _ = False isCompileRecompile :: CompileMode -> Bool isCompileRecompile CompileRecompile = True isCompileRecompile CompileRecompileRecursive = True isCompileRecompile _ = False isExecuteTests :: CompileMode -> Bool isExecuteTests (ExecuteTests _ _) = True isExecuteTests _ = False isCreateTemplates :: CompileMode -> Bool isCreateTemplates CreateTemplates = True isCreateTemplates _ = False isCompileUnspecified :: CompileMode -> Bool isCompileUnspecified CompileUnspecified = True isCompileUnspecified _ = False maybeDisableHelp :: HelpMode -> HelpMode maybeDisableHelp HelpUnspecified = HelpNotNeeded maybeDisableHelp h = h getLinkFlags :: CompileMode -> [String] getLinkFlags (CompileBinary _ _ _ _ lf) = lf getLinkFlags (CompileIncremental lf) = lf getLinkFlags _ = [] data CompileOptions = CompileOptions { _coHelp :: HelpMode, _coPublicDeps :: [FilePath], _coPrivateDeps :: [FilePath], _coPaths :: [FilePath], _coExtraFiles :: [ExtraSource], _coExtraPaths :: [FilePath], _coSourcePrefix :: FilePath, _coMode :: CompileMode, _coForce :: ForceMode, _coParallel :: Int } deriving (Show) $(makeLenses ''CompileOptions)