Skip to content

Commit 75f70ae

Browse files
authored
Merge pull request #1306 from well-typed/dom/1046/th-binding-specs
Client and TH configuration types
2 parents 7327dd5 + 8abff4e commit 75f70ae

File tree

42 files changed

+320
-349
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+320
-349
lines changed

hs-bindgen/app/HsBindgen/App.hs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ module HsBindgen.App (
1111
-- ** Bindgen configuration
1212
, Config
1313
, parseConfig
14-
, parseConfigPP
1514
-- ** Clang arguments
1615
, parseClangArgsConfig
16+
-- ** Translation option
17+
, parseUniqueId
1718
-- ** Module option
1819
, parseHsModuleName
1920
-- ** Output options
20-
, OutputDirPolicy(..)
2121
, parseHsOutputDir
2222
, parseOutputDirPolicy
2323
, parseGenBindingSpec
@@ -56,7 +56,7 @@ import HsBindgen.Util.Tracer
5656
-------------------------------------------------------------------------------}
5757

5858
data GlobalOpts = GlobalOpts {
59-
tracerConfig :: TracerConfig IO Level TraceMsg
59+
tracerConfig :: TracerConfig Level TraceMsg
6060
}
6161

6262
parseGlobalOpts :: Parser GlobalOpts
@@ -66,7 +66,7 @@ parseGlobalOpts = GlobalOpts <$> parseTracerConfig
6666
Tracer configuration
6767
-------------------------------------------------------------------------------}
6868

69-
parseTracerConfig :: Parser (TracerConfig IO Level TraceMsg)
69+
parseTracerConfig :: Parser (TracerConfig Level TraceMsg)
7070
parseTracerConfig =
7171
TracerConfig
7272
<$> parseVerbosity
@@ -162,9 +162,6 @@ parseConfig = Config
162162
<*> parseProgramSlicing
163163
<*> parsePathStyle
164164

165-
parseConfigPP :: Parser ConfigPP
166-
parseConfigPP = ConfigPP <$> optional parseUniqueId
167-
168165
{-------------------------------------------------------------------------------
169166
Binding specifications
170167
-------------------------------------------------------------------------------}
@@ -473,6 +470,7 @@ parseUniqueId :: Parser UniqueId
473470
parseUniqueId = fmap UniqueId . strOption $ mconcat [
474471
long "unique-id"
475472
, metavar "ID"
473+
, value ""
476474
, help $ concat [
477475
"Use unique ID to discriminate global C identifiers"
478476
, " (default: empty string)"
@@ -488,7 +486,7 @@ parseHsModuleName = strOption $ mconcat [
488486
long "module"
489487
, metavar "NAME"
490488
, showDefault
491-
, value defModuleName
489+
, value defHsModuleName
492490
, help "Base name of the generated Haskell modules"
493491
]
494492

@@ -503,11 +501,6 @@ parseHsOutputDir = strOption $ mconcat [
503501
, help "Output directory of generated Haskell modules"
504502
]
505503

506-
data OutputDirPolicy
507-
= CreateDirStructure
508-
| DoNotCreateDirStructure
509-
deriving (Show, Eq)
510-
511504
parseOutputDirPolicy :: Parser OutputDirPolicy
512505
parseOutputDirPolicy = flag DoNotCreateDirStructure CreateDirStructure $ mconcat [
513506
long "create-output-dirs"

hs-bindgen/app/HsBindgen/Cli/GenTests.hs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import Options.Applicative hiding (info)
1818

1919
import HsBindgen
2020
import HsBindgen.App
21+
import HsBindgen.Backend.HsModule.Translation
22+
import HsBindgen.Backend.UniqueId
2123
import HsBindgen.Config
2224
import HsBindgen.Frontend.RootHeader
2325
import HsBindgen.Language.Haskell qualified as Hs
@@ -35,7 +37,7 @@ info = progDesc "Generate tests for generated Haskell code"
3537

3638
data Opts = Opts {
3739
config :: Config
38-
, configPP :: ConfigPP
40+
, uniqueId :: UniqueId
3941
, hsModuleName :: Hs.ModuleName
4042
, output :: FilePath
4143
, inputs :: [UncheckedHashIncludeArg]
@@ -45,7 +47,7 @@ parseOpts :: Parser Opts
4547
parseOpts =
4648
Opts
4749
<$> parseConfig
48-
<*> parseConfigPP
50+
<*> parseUniqueId
4951
<*> parseHsModuleName
5052
<*> parseGenTestsOutput
5153
<*> parseInputs
@@ -56,6 +58,6 @@ parseOpts =
5658

5759
exec :: GlobalOpts -> Opts -> IO ()
5860
exec GlobalOpts{..} Opts{..} = do
59-
let artefacts = writeTests output :* Nil
60-
bindgenConfig = toBindgenConfigPP config configPP
61-
void $ hsBindgen tracerConfig bindgenConfig hsModuleName inputs artefacts
61+
let artefact = writeTests output
62+
bindgenConfig = toBindgenConfig config uniqueId defHsModuleName
63+
void $ hsBindgen tracerConfig bindgenConfig inputs artefact

hs-bindgen/app/HsBindgen/Cli/Info/IncludeGraph.hs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import Options.Applicative hiding (info)
1717

1818
import HsBindgen
1919
import HsBindgen.App
20+
import HsBindgen.Backend.UniqueId
2021
import HsBindgen.Config
2122
import HsBindgen.Frontend.RootHeader
2223
import HsBindgen.Imports
@@ -35,7 +36,7 @@ info = progDesc "Output the include graph"
3536

3637
data Opts = Opts {
3738
config :: Config
38-
, configPP :: ConfigPP
39+
, uniqueId :: UniqueId
3940
, hsModuleName :: Hs.ModuleName
4041
, output :: Maybe FilePath
4142
, inputs :: [UncheckedHashIncludeArg]
@@ -45,7 +46,7 @@ parseOpts :: Parser Opts
4546
parseOpts =
4647
Opts
4748
<$> parseConfig
48-
<*> parseConfigPP
49+
<*> parseUniqueId
4950
<*> parseHsModuleName
5051
<*> optional parseOutput'
5152
<*> parseInputs
@@ -64,6 +65,6 @@ parseOutput' = strOption $ mconcat [
6465

6566
exec :: GlobalOpts -> Opts -> IO ()
6667
exec GlobalOpts{..} Opts{..} = do
67-
let artefacts = writeIncludeGraph output :* Nil
68-
bindgenConfig = toBindgenConfigPP config configPP
69-
void $ hsBindgen tracerConfig bindgenConfig hsModuleName inputs artefacts
68+
let artefact = writeIncludeGraph output
69+
bindgenConfig = toBindgenConfig config uniqueId hsModuleName
70+
void $ hsBindgen tracerConfig bindgenConfig inputs artefact

hs-bindgen/app/HsBindgen/Cli/Info/ResolveHeader.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ exec GlobalOpts{..} Opts{..} = do
7676
Right True -> throwIO (ExitFailure 1)
7777
Left e -> throwIO e
7878
where
79-
tracerConfig' :: TracerConfig IO Level TraceMsg
79+
tracerConfig' :: TracerConfig Level TraceMsg
8080
tracerConfig' = tracerConfig{
8181
tCustomLogLevel = customLogLevel <> tCustomLogLevel tracerConfig
8282
}
@@ -89,7 +89,7 @@ exec GlobalOpts{..} Opts{..} = do
8989

9090
-- | Check the @#include@ arguments, emitting trace messages
9191
checkInputs ::
92-
Tracer IO TraceMsg
92+
Tracer TraceMsg
9393
-> [UncheckedHashIncludeArg]
9494
-> IO [HashIncludeArg]
9595
checkInputs tracer = mapM $

hs-bindgen/app/HsBindgen/Cli/Info/UseDeclGraph.hs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import Options.Applicative hiding (info)
1717

1818
import HsBindgen
1919
import HsBindgen.App
20+
import HsBindgen.Backend.UniqueId
2021
import HsBindgen.Config
2122
import HsBindgen.Frontend.RootHeader
2223
import HsBindgen.Imports
@@ -35,7 +36,7 @@ info = progDesc "Output the use-decl graph"
3536

3637
data Opts = Opts {
3738
config :: Config
38-
, configPP :: ConfigPP
39+
, uniqueId :: UniqueId
3940
, hsModuleName :: Hs.ModuleName
4041
, output :: Maybe FilePath
4142
, inputs :: [UncheckedHashIncludeArg]
@@ -45,7 +46,7 @@ parseOpts :: Parser Opts
4546
parseOpts =
4647
Opts
4748
<$> parseConfig
48-
<*> parseConfigPP
49+
<*> parseUniqueId
4950
<*> parseHsModuleName
5051
<*> optional parseOutput'
5152
<*> parseInputs
@@ -64,6 +65,6 @@ parseOutput' = strOption $ mconcat [
6465

6566
exec :: GlobalOpts -> Opts -> IO ()
6667
exec GlobalOpts{..} Opts{..} = do
67-
let artefacts = writeUseDeclGraph output :* Nil
68-
bindgenConfig = toBindgenConfigPP config configPP
69-
void $ hsBindgen tracerConfig bindgenConfig hsModuleName inputs artefacts
68+
let artefact = writeUseDeclGraph output
69+
bindgenConfig = toBindgenConfig config uniqueId hsModuleName
70+
void $ hsBindgen tracerConfig bindgenConfig inputs artefact

hs-bindgen/app/HsBindgen/Cli/Internal/Frontend.hs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ module HsBindgen.Cli.Internal.Frontend (
1313
, exec
1414
) where
1515

16+
import Control.Monad.IO.Class
1617
import Options.Applicative hiding (info)
1718

1819
import HsBindgen
1920
import HsBindgen.App
21+
import HsBindgen.Backend.UniqueId
2022
import HsBindgen.Config
2123
import HsBindgen.Frontend.RootHeader
2224
import HsBindgen.Language.Haskell qualified as Hs
@@ -34,7 +36,7 @@ info = progDesc "Parse C headers (all Frontend passes)"
3436

3537
data Opts = Opts {
3638
config :: Config
37-
, configPP :: ConfigPP
39+
, uniqueId :: UniqueId
3840
, hsModuleName :: Hs.ModuleName
3941
, inputs :: [UncheckedHashIncludeArg]
4042
}
@@ -43,7 +45,7 @@ parseOpts :: Parser Opts
4345
parseOpts =
4446
Opts
4547
<$> parseConfig
46-
<*> parseConfigPP
48+
<*> parseUniqueId
4749
<*> parseHsModuleName
4850
<*> parseInputs
4951

@@ -53,8 +55,6 @@ parseOpts =
5355

5456
exec :: GlobalOpts -> Opts -> IO ()
5557
exec GlobalOpts{..} Opts{..} = do
56-
let artefacts = ReifiedC :* Nil
57-
bindgenConfig = toBindgenConfigPP config configPP
58-
(I decls :* Nil) <-
59-
hsBindgen tracerConfig bindgenConfig hsModuleName inputs artefacts
60-
print decls
58+
let artefact = ReifiedC >>= liftIO . print
59+
bindgenConfig = toBindgenConfig config uniqueId hsModuleName
60+
hsBindgen tracerConfig bindgenConfig inputs artefact

hs-bindgen/app/HsBindgen/Cli/Preprocess.hs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,18 @@ module HsBindgen.Cli.Preprocess (
1313
, exec
1414
) where
1515

16-
import Control.Exception (Exception (..), throwIO)
17-
import Control.Monad (unless, void)
18-
import Data.Maybe (maybeToList)
19-
import GHC.Generics (Generic)
16+
import Control.Exception (Exception (..))
2017
import Options.Applicative hiding (info)
2118
import System.Directory (createDirectoryIfMissing, doesDirectoryExist)
2219

2320
import HsBindgen
2421
import HsBindgen.App
25-
import HsBindgen.Artefact
22+
import HsBindgen.Backend.UniqueId
2623
import HsBindgen.Config
2724
import HsBindgen.Config.Internal
2825
import HsBindgen.Errors
2926
import HsBindgen.Frontend.RootHeader
27+
import HsBindgen.Imports
3028
import HsBindgen.Language.Haskell qualified as Hs
3129

3230
{-------------------------------------------------------------------------------
@@ -42,21 +40,21 @@ info = progDesc "Generate Haskell module from C headers"
4240

4341
data Opts = Opts {
4442
config :: Config
45-
, configPP :: ConfigPP
43+
, uniqueId :: UniqueId
4644
, hsModuleName :: Hs.ModuleName
4745
, hsOutputDir :: FilePath
4846
, outputDirPolicy :: OutputDirPolicy
4947
, outputBindingSpec :: Maybe FilePath
48+
-- NOTE: Inputs (arguments) must be last, options must go before it.
5049
, inputs :: [UncheckedHashIncludeArg]
51-
-- NOTE inputs (arguments) must be last, options must go before it
5250
}
5351
deriving (Generic)
5452

5553
parseOpts :: Parser Opts
5654
parseOpts =
5755
Opts
5856
<$> parseConfig
59-
<*> parseConfigPP
57+
<*> parseUniqueId
6058
<*> parseHsModuleName
6159
<*> parseHsOutputDir
6260
<*> parseOutputDirPolicy
@@ -78,18 +76,18 @@ exec GlobalOpts{..} Opts{..} = do
7876
unless exists $
7977
throwIO (OutputDirectoryMissingException hsOutputDir)
8078

81-
void $ run $ (sequenceArtefacts artefacts) :* Nil
79+
void $ run $ artefacts
8280
where
8381
bindgenConfig :: BindgenConfig
84-
bindgenConfig = toBindgenConfigPP config configPP
82+
bindgenConfig = toBindgenConfig config uniqueId hsModuleName
8583

86-
run :: Artefacts as -> IO (NP I as)
87-
run = hsBindgen tracerConfig bindgenConfig hsModuleName inputs
84+
run :: Artefact a -> IO a
85+
run = hsBindgen tracerConfig bindgenConfig inputs
8886

89-
artefacts :: [Artefact ()]
90-
artefacts =
91-
writeBindingsMultiple hsOutputDir
92-
: [ writeBindingSpec file | file <- maybeToList outputBindingSpec ]
87+
artefacts :: Artefact ()
88+
artefacts = do
89+
writeBindingsMultiple hsOutputDir
90+
forM_ outputBindingSpec writeBindingSpec
9391

9492
{-------------------------------------------------------------------------------
9593
Exception

hs-bindgen/app/HsBindgen/Cli/ToolSupport/Literate.hs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import Text.Read (readMaybe)
2525
import HsBindgen
2626
import HsBindgen.App
2727
import HsBindgen.Backend.SHs.AST
28+
import HsBindgen.Backend.UniqueId
2829
import HsBindgen.Config
2930
import HsBindgen.Errors
3031
import HsBindgen.Frontend.RootHeader
@@ -72,7 +73,7 @@ parseOpts = do
7273
data Lit = Lit {
7374
globalOpts :: GlobalOpts
7475
, config :: Config
75-
, configPP :: ConfigPP
76+
, uniqueId :: UniqueId
7677
, hsModuleName :: Hs.ModuleName
7778
, safety :: Safety
7879
, inputs :: [UncheckedHashIncludeArg]
@@ -82,7 +83,7 @@ parseLit :: Parser Lit
8283
parseLit = Lit
8384
<$> parseGlobalOpts
8485
<*> parseConfig
85-
<*> parseConfigPP
86+
<*> parseUniqueId
8687
<*> parseHsModuleName
8788
<*> parseSafety
8889
<*> parseInputs
@@ -111,9 +112,9 @@ exec literateOpts = do
111112
Lit{..} <- maybe (throwIO' "cannot parse arguments in literate file") return $
112113
pureParseLit args
113114
let GlobalOpts{..} = globalOpts
114-
bindgenConfig = toBindgenConfigPP config configPP
115-
void $ hsBindgen tracerConfig bindgenConfig hsModuleName inputs $
116-
writeBindings safety (Just literateOpts.output) :* Nil
115+
bindgenConfig = toBindgenConfig config uniqueId hsModuleName
116+
void $ hsBindgen tracerConfig bindgenConfig inputs $
117+
writeBindings safety (Just literateOpts.output)
117118
where
118119
throwIO' :: String -> IO a
119120
throwIO' = throwIO . LiterateFileException literateOpts.input

hs-bindgen/clang-ast-dump/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ clangAstDump opts@Options{..} = do
9999
Left e -> throwIO e
100100
Right _ -> pure ()
101101
where
102-
tracerConf :: TracerConfig IO Level DumpTrace
102+
tracerConf :: TracerConfig Level DumpTrace
103103
tracerConf = def {
104104
tVerbosity = Verbosity Debug
105105
}

hs-bindgen/hs-bindgen.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ library internal
206206
, directory >=1.3.6.2 && <1.4
207207
, filepath >=1.4 && <1.6
208208
, fin >=0.3.2 && <0.4
209-
, generics-sop >=0.5.1.4 && <0.6
210209
, language-c >=0.10 && <0.11
211210
, mtl >=2.2 && <2.4
212211
, optics-core >=0.4 && <0.5

0 commit comments

Comments
 (0)