Skip to content

Commit

Permalink
Add --debug flag
Browse files Browse the repository at this point in the history
  • Loading branch information
evancz committed Aug 11, 2016
1 parent 0fee899 commit a7d9e3e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/BuildManager.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ data Config = Config
, _output :: Output
, _autoYes :: Bool
, _reportType :: Report.Type
, _debug :: Bool
, _warn :: Bool
, _docs :: Maybe FilePath
, _permissions :: Permissions
Expand Down
10 changes: 10 additions & 0 deletions src/Flags.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ flags =
<*> output
<*> yes
<*> reportFlag
<*> debugFlag
<*> warnFlag
<*> optional docs
<*> capabilities
Expand Down Expand Up @@ -130,6 +131,15 @@ yes =
]


debugFlag :: Opt.Parser Bool
debugFlag =
Opt.switch $
mconcat
[ Opt.long "debug"
, Opt.help "Generate programs in debug mode."
]


warnFlag :: Opt.Parser Bool
warnFlag =
Opt.switch $
Expand Down
24 changes: 16 additions & 8 deletions src/Pipeline/Generate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@ generate config dependencies natives rootModules =
let outputFile = BM.outputFilePath config
liftIO (createDirectoryIfMissing True (dropFileName outputFile))

let debugMode = BM._debug config

case BM._output config of
BM.Html outputFile ->
liftIO $
do js <- mapM File.readTextUtf8 objectFiles
let (TMP.CanonicalModule _ moduleName) = head rootModules
let outputText = html (Text.concat (header : js ++ [footer rootModules])) moduleName
let outputText = html (Text.concat (header : js ++ [footer debugMode rootModules])) moduleName
LazyText.writeFile outputFile outputText

BM.JS outputFile ->
Expand All @@ -78,7 +80,7 @@ generate config dependencies natives rootModules =
do Text.hPutStrLn handle header
forM_ objectFiles $ \jsFile ->
Text.hPutStrLn handle =<< File.readTextUtf8 jsFile
Text.hPutStrLn handle (footer rootModules)
Text.hPutStrLn handle (footer debugMode rootModules)

BM.DevNull ->
return ()
Expand Down Expand Up @@ -148,20 +150,20 @@ html generatedJavaScript moduleName =
-- FOOTER


footer :: [TMP.CanonicalModule] -> Text.Text
footer rootModules =
footer :: Bool -> [TMP.CanonicalModule] -> Text.Text
footer debugMode rootModules =
let
exportChunks =
map export (List.sort (map TMP.simplifyModuleName rootModules))
map (export debugMode) (List.sort (map TMP.simplifyModuleName rootModules))
in
Text.pack $
"var Elm = {};\n"
++ unlines exportChunks
++ footerClose


export :: Module.Canonical -> String
export canonicalName@(Module.Canonical _ moduleName) =
export :: Bool -> Module.Canonical -> String
export debugMode canonicalName@(Module.Canonical _ moduleName) =
let
makeProgram =
Module.qualifiedVar canonicalName "main"
Expand All @@ -171,9 +173,15 @@ export canonicalName@(Module.Canonical _ moduleName) =

name =
Module.nameToString moduleName

debugArg =
if debugMode then
", true"
else
""
in
setup moduleName
++ makeProgram ++ "(" ++ object ++ ", '" ++ name ++ "');"
++ makeProgram ++ "(" ++ object ++ ", '" ++ name ++ "'" ++ debugArg ++ ");"


setup :: [String] -> String
Expand Down

0 comments on commit a7d9e3e

Please sign in to comment.