Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: change project flag configuration behavior #1451

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions core/Project.carp
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,13 @@
Example usage: `(save-docs Int Float String)`")
(defmacro save-docs [:rest modules]
(eval (list 'save-docs-ex (list quote (collect-into modules array)) [])))

(defmodule Project
(hidden append-flag)
(defndynamic append-flag [flag-set flag]
(Project.config flag-set (cons flag (Project.get-config flag-set))))

(defmacro append-cflag [flag] (Project.append-flag "cflag" flag))
(defmacro append-libflag [flag] (Project.append-flag "libflag" flag))
(defmacro append-pkgflag [flag] (Project.append-flag "pkgconfigflag" flag))
)
4 changes: 4 additions & 0 deletions src/Obj.hs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ isBool :: XObj -> Bool
isBool (XObj (Bol _) _ _) = True
isBool _ = False

isStr :: XObj -> Bool
isStr (XObj (Str _) _ _) = True
isStr _ = False

isExternalFunction :: XObj -> Bool
isExternalFunction (XObj (Lst (XObj (External _) _ _ : _)) _ _) = True
isExternalFunction _ = False
Expand Down
62 changes: 21 additions & 41 deletions src/ProjectConfig.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
-- | Defines a frontend for manipulating Project level data.
module ProjectConfig (projectKeyMap) where

import Data.Either (rights)
import Info
import qualified Map
import Obj
( XObj(XObj),
Obj(Str, Lst, Bol),
unwrapStringXObj,
wrapString,
wrapList,
wrapArray,
isStr )
import Project
import Util

Expand Down Expand Up @@ -46,24 +54,15 @@ projectGetPreproc proj =
-- | Get the project's C compiler flags.
projectGetCFlags :: ProjectGetter
projectGetCFlags proj =
let fs = projectPreproc proj
let fs = projectCFlags proj
in wrapList (map wrapString fs)

-- | Set the project's C compiler flags
--
-- NOTE: This retains existing behavior in which one can only add one flag at
-- a time and the flags are append only. A slightly more functional interface
-- would take a list of flags as arguments; e.g. to add *one* flag:
--
-- (Project.config "cflags" (cons "-my-flag" (Project.get-config "cflags")))
--
-- or to wipe the flags whole-cloth (e.g. for a different target)
--
-- (Project.config "cflags" ("-my" "-new" "-flags"))
--
-- likewise for flag removal etc.
projectSetCFlags :: ProjectSetter
projectSetCFlags proj (XObj (Str f) _ _) = Right (proj {projectCFlags = addIfNotPresent f (projectCFlags proj)})
projectSetCFlags proj (XObj (Lst flags) _ _) =
if not $ all isStr flags
then Left "can't use a non-string as a C compiler flag"
else Right proj {projectCFlags = rights $ map unwrapStringXObj flags}
projectSetCFlags _ _ = Left "can't use a non-string as a C compiler flag"

-- | Get the project's C compiler library flags.
Expand All @@ -73,20 +72,11 @@ projectGetLibFlags proj =
in wrapList (map wrapString ls)

-- | Set the project's C compiler library flags
--
-- NOTE: This retains existing behavior in which one can only add one flag at
-- a time and the flags are append only. A slightly more functional interface
-- would take a list of flags as arguments; e.g. to add *one* flag:
--
-- (Project.config "libflags" (cons "-lmylib" (Project.get-config "libflags")))
--
-- or to wipe the flags whole-cloth (e.g. for a different target)
--
-- (Project.config "libflags" ("-lmy" "-lnew" "-llibflags"))
--
-- likewise for flag removal etc.
projectSetLibFlags :: ProjectSetter
projectSetLibFlags proj (XObj (Str flag) _ _) = Right (proj {projectLibFlags = addIfNotPresent flag (projectLibFlags proj)})
projectSetLibFlags proj (XObj (Lst flags) _ _) =
if not $ all isStr flags
then Left "can't use a non-string as a C compiler library flag"
else Right proj {projectLibFlags = rights $ map unwrapStringXObj flags}
projectSetLibFlags _ _ = Left "can't use non-string as library flag"

-- | Get the pkg-config flags for the project.
Expand All @@ -96,21 +86,11 @@ projectGetPkgConfigFlags proj =
in wrapArray (map wrapString fs)

-- | Set the project's pkg-config flags
--
-- NOTE: This retains existing behavior in which one can only add one flag at
-- a time and the flags are append only. A slightly more functional interface
-- would take a list of flags as arguments; e.g. to add *one* flag:
--
-- (Project.config "pkgconfigflags" (cons "-lmylib" (Project.get-config
-- "pkgconfigflags")))
--
-- or to wipe the flags whole-cloth (e.g. for a different target)
--
-- (Project.config "pkgconfigflags" ("-lmy" "-lnew" "-llibflags"))
--
-- likewise for flag removal etc.
projectSetPkgConfigFlags :: ProjectSetter
projectSetPkgConfigFlags proj (XObj (Str flag) _ _) = Right (proj {projectPkgConfigFlags = addIfNotPresent flag (projectPkgConfigFlags proj)})
projectSetPkgConfigFlags proj (XObj (Lst flags) _ _) =
if not $ all isStr flags
then Left "can't use a non-string as a C compiler library flag"
else Right proj {projectPkgConfigFlags = rights $ map unwrapStringXObj flags}
projectSetPkgConfigFlags _ _ = Left "can't use non-string as pkg-config flag"

projectGetEchoC :: ProjectGetter
Expand Down