Skip to content

Commit 3ee0fa5

Browse files
committed
Use real filePathMap
1 parent 46dd0a6 commit 3ee0fa5

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

psc-make/Main.hs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
--
1313
-----------------------------------------------------------------------------
1414

15-
{-# LANGUAGE DataKinds, GeneralizedNewtypeDeriving, TupleSections, RecordWildCards #-}
15+
{-# LANGUAGE DataKinds #-}
16+
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
17+
{-# LANGUAGE TupleSections #-}
18+
{-# LANGUAGE RecordWildCards #-}
1619

1720
module Main where
1821

@@ -91,11 +94,10 @@ compile :: PSCMakeOptions -> IO ()
9194
compile (PSCMakeOptions input outputDir opts usePrefix) = do
9295
modules <- P.parseModulesFromFiles (either (const "") id) <$> readInput (InputOptions (P.optionsNoPrelude opts) input)
9396
case modules of
94-
Left err -> do
95-
print err
96-
exitFailure
97+
Left err -> print err >> exitFailure
9798
Right ms -> do
98-
e <- runMake opts $ P.make getInputTimestamp getOutputTimestamp readExterns codegen ms
99+
let filePathMap = M.fromList $ map (\(fp, P.Module _ mn _ _) -> (mn, fp)) ms
100+
e <- runMake opts $ P.make (getInputTimestamp filePathMap) getOutputTimestamp readExterns codegen ms
99101
case e of
100102
Left errs -> do
101103
putStrLn (P.prettyPrintMultipleErrors (P.optionsVerboseErrors opts) errs)
@@ -105,16 +107,11 @@ compile (PSCMakeOptions input outputDir opts usePrefix) = do
105107
putStrLn (P.prettyPrintMultipleWarnings (P.optionsVerboseErrors opts) warnings)
106108
exitSuccess
107109
where
108-
prefix = if usePrefix
109-
then ["Generated by psc-make version " ++ showVersion Paths.version]
110-
else []
111110

112-
filePathMap = M.empty -- M.fromList (map (\(fp, Module _ mn _ _) -> (mn, fp)) ms)
113-
114-
getInputTimestamp :: P.ModuleName -> Make (Either P.RebuildPolicy (Maybe UTCTime))
115-
getInputTimestamp mn = do
116-
let inputFile = fromMaybe (error "Module has no filename in 'make'") $ M.lookup mn filePathMap
117-
traverseEither P.getTimestamp inputFile
111+
getInputTimestamp :: M.Map P.ModuleName (Either P.RebuildPolicy String) -> P.ModuleName -> Make (Either P.RebuildPolicy (Maybe UTCTime))
112+
getInputTimestamp filePathMap mn = do
113+
let path = fromMaybe (error "Module has no filename in 'make'") $ M.lookup mn filePathMap
114+
traverseEither P.getTimestamp path
118115

119116
getOutputTimestamp :: P.ModuleName -> Make (Maybe UTCTime)
120117
getOutputTimestamp mn = do
@@ -129,12 +126,13 @@ compile (PSCMakeOptions input outputDir opts usePrefix) = do
129126
(path, ) <$> P.readTextFile path
130127

131128
codegen :: CoreFn.Module CoreFn.Ann -> String -> P.Environment -> Integer -> Make ()
132-
codegen m exts env nextVar = do
129+
codegen m exts _ nextVar = do
130+
pjs <- P.evalSupplyT nextVar $ P.prettyPrintJS <$> J.moduleToJs m Nothing
133131
let filePath = P.runModuleName $ CoreFn.moduleName m
134132
jsFile = outputDir </> filePath </> "index.js"
135133
externsFile = outputDir </> filePath </> "externs.purs"
136-
pjs <- P.evalSupplyT nextVar $ P.prettyPrintJS <$> J.moduleToJs m Nothing
137-
let js = unlines $ map ("// " ++) prefix ++ [pjs]
134+
prefix = ["Generated by psc-make version " ++ showVersion Paths.version | usePrefix]
135+
js = unlines $ map ("// " ++) prefix ++ [pjs]
138136
P.writeTextFile jsFile js
139137
P.writeTextFile externsFile exts
140138

0 commit comments

Comments
 (0)