Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions hs-bindgen/app/HsBindgen/Cli/Info.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import HsBindgen.App
import HsBindgen.Cli.Info.IncludeGraph qualified as IncludeGraph
import HsBindgen.Cli.Info.Libclang qualified as Libclang
import HsBindgen.Cli.Info.ResolveHeader qualified as ResolveHeader
import HsBindgen.Cli.Info.UseDeclGraph qualified as UseDeclGraph

{-------------------------------------------------------------------------------
CLI help
Expand All @@ -36,6 +37,7 @@ data Cmd =
CmdIncludeGraph IncludeGraph.Opts
| CmdLibclang Libclang.Opts
| CmdResolveHeader ResolveHeader.Opts
| CmdUseDeclGraph UseDeclGraph.Opts

parseCmd :: Parser Cmd
parseCmd = subparser $ mconcat [
Expand All @@ -54,6 +56,11 @@ parseCmd = subparser $ mconcat [
CmdResolveHeader
ResolveHeader.parseOpts
ResolveHeader.info
, cmd
"use-decl-graph"
CmdUseDeclGraph
UseDeclGraph.parseOpts
UseDeclGraph.info
]

{-------------------------------------------------------------------------------
Expand All @@ -65,3 +72,4 @@ exec gopts = \case
CmdIncludeGraph opts -> IncludeGraph.exec gopts opts
CmdLibclang opts -> Libclang.exec gopts opts
CmdResolveHeader opts -> ResolveHeader.exec gopts opts
CmdUseDeclGraph opts -> UseDeclGraph.exec gopts opts
67 changes: 67 additions & 0 deletions hs-bindgen/app/HsBindgen/Cli/Info/UseDeclGraph.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
-- | @hs-bindgen-cli info use-decl-graph@ command
--
-- Intended for qualified import.
--
-- > import HsBindgen.Cli.Info.UseDeclGraph qualified as UseDeclGraph
module HsBindgen.Cli.Info.UseDeclGraph (
-- * CLI help
info
-- * Options
, Opts(..)
, parseOpts
-- * Execution
, exec
) where

import Options.Applicative hiding (info)

import HsBindgen.App
import HsBindgen.Config
import HsBindgen.Frontend.RootHeader
import HsBindgen.Imports

import HsBindgen

{-------------------------------------------------------------------------------
CLI help
-------------------------------------------------------------------------------}

info :: InfoMod a
info = progDesc "Output the use-decl graph"

{-------------------------------------------------------------------------------
Options
-------------------------------------------------------------------------------}

data Opts = Opts {
config :: Config
, configPP :: ConfigPP
, output :: Maybe FilePath
, inputs :: [UncheckedHashIncludeArg]
}

parseOpts :: Parser Opts
parseOpts =
Opts
<$> parseConfig
<*> parseConfigPP
<*> optional parseOutput'
<*> parseInputs

parseOutput' :: Parser FilePath
parseOutput' = strOption $ mconcat [
short 'o'
, long "output"
, metavar "PATH"
, help "Output path for the graph"
]

{-------------------------------------------------------------------------------
Execution
-------------------------------------------------------------------------------}

exec :: GlobalOpts -> Opts -> IO ()
exec GlobalOpts{..} Opts{..} = do
let artefacts = writeUseDeclGraph output :* Nil
bindgenConfig = toBindgenConfigPP config configPP
void $ hsBindgen tracerConfig bindgenConfig inputs artefacts
1 change: 1 addition & 0 deletions hs-bindgen/hs-bindgen.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ executable hs-bindgen-cli
HsBindgen.Cli.Info.IncludeGraph
HsBindgen.Cli.Info.Libclang
HsBindgen.Cli.Info.ResolveHeader
HsBindgen.Cli.Info.UseDeclGraph
HsBindgen.Cli.Internal
HsBindgen.Cli.Internal.Frontend
HsBindgen.Cli.Preprocess
Expand Down
6 changes: 3 additions & 3 deletions hs-bindgen/src-internal/HsBindgen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ writeIncludeGraph mPath = Lift (IncludeGraph :* Nil) $
write "include graph" mPath $ IncludeGraph.dumpMermaid p includeGraph

-- | Write @use-decl@ graph to file.
writeUseDeclGraph :: FilePath -> Artefact ()
writeUseDeclGraph path = Lift (DeclIndex :* UseDeclGraph :* Nil) $
writeUseDeclGraph :: Maybe FilePath -> Artefact ()
writeUseDeclGraph mPath = Lift (DeclIndex :* UseDeclGraph :* Nil) $
\(I index :* I useDeclGraph :* Nil) ->
write "use-decl graph" (Just path) (UseDeclGraph.dumpMermaid index useDeclGraph)
write "use-decl graph" mPath $ UseDeclGraph.dumpMermaid index useDeclGraph

-- | Get bindings (single module).
getBindings :: Safety -> Artefact String
Expand Down