git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Fix #1246
3ff09c1Phil Freeman
psc/Main.hs+1−1
@@ -84,7 +84,7 @@ readInput InputOptions{..} = forM ioInputFiles $ \inFile -> (Right inFile, ) <$>
84parseInputs :: (Functor m, Applicative m, MonadError P.MultipleErrors m, MonadWriter P.MultipleErrors m)
84parseInputs :: (Functor m, Applicative m, MonadError P.MultipleErrors m, MonadWriter P.MultipleErrors m)
85 => [(Either P.RebuildPolicy FilePath, String)]
85 => [(Either P.RebuildPolicy FilePath, String)]
86 -> [(FilePath, P.ForeignJS)]
86 -> [(FilePath, P.ForeignJS)]
87− -> m ([(Either P.RebuildPolicy FilePath, P.Module)], M.Map P.ModuleName (FilePath, P.ForeignJS))
87+ -> m ([(Either P.RebuildPolicy FilePath, P.Module)], M.Map P.ModuleName FilePath)
88parseInputs modules foreigns =
88parseInputs modules foreigns =
89 (,) <$> P.parseModulesFromFiles (either (const "") id) modules
89 (,) <$> P.parseModulesFromFiles (either (const "") id) modules
90 <*> P.parseForeignModulesFromFiles foreigns
90 <*> P.parseForeignModulesFromFiles foreigns
psci/Types.hs+2−2
@@ -35,7 +35,7 @@ data PSCiState = PSCiState
35 { psciImportedFilenames :: [FilePath]
35 { psciImportedFilenames :: [FilePath]
36 , psciImportedModules :: [ImportedModule]
36 , psciImportedModules :: [ImportedModule]
37 , psciLoadedModules :: [(Either P.RebuildPolicy FilePath, P.Module)]
37 , psciLoadedModules :: [(Either P.RebuildPolicy FilePath, P.Module)]
38− , psciForeignFiles :: M.Map P.ModuleName (FilePath, P.ForeignJS)
38+ , psciForeignFiles :: M.Map P.ModuleName FilePath
39 , psciLetBindings :: [P.Declaration]
39 , psciLetBindings :: [P.Declaration]
40 , psciNodeFlags :: [String]
40 , psciNodeFlags :: [String]
41 }
41 }
@@ -91,7 +91,7 @@ updateLets ds st = st { psciLetBindings = psciLetBindings st ++ ds }
91-- |
91-- |
92-- Updates the state to have more let bindings.
92-- Updates the state to have more let bindings.
93--
93--
94−updateForeignFiles :: M.Map P.ModuleName (FilePath, P.ForeignJS) -> PSCiState -> PSCiState
94+updateForeignFiles :: M.Map P.ModuleName FilePath -> PSCiState -> PSCiState
95updateForeignFiles fs st = st { psciForeignFiles = psciForeignFiles st `M.union` fs }
95updateForeignFiles fs st = st { psciForeignFiles = psciForeignFiles st `M.union` fs }
96
96
97-- |
97-- |
src/Language/PureScript/Make.hs+5−6
@@ -59,7 +59,6 @@ import System.Directory
59import System.FilePath ((</>), takeDirectory)
59import System.FilePath ((</>), takeDirectory)
60import System.IO.Error (tryIOError)
60import System.IO.Error (tryIOError)
61
61
62−
63import Language.PureScript.AST
62import Language.PureScript.AST
64import Language.PureScript.CodeGen.Externs (moduleToPs)
63import Language.PureScript.CodeGen.Externs (moduleToPs)
65import Language.PureScript.Environment
64import Language.PureScript.Environment
@@ -245,8 +244,8 @@ traverseEither f (Right y) = Right <$> f y
245-- A set of make actions that read and write modules from the given directory.
244-- A set of make actions that read and write modules from the given directory.
246--
245--
247buildMakeActions :: FilePath -- ^ the output directory
246buildMakeActions :: FilePath -- ^ the output directory
248− -> M.Map ModuleName (Either RebuildPolicy String) -- ^ a map between module names and paths to the file containing the PureScript module
247+ -> M.Map ModuleName (Either RebuildPolicy FilePath) -- ^ a map between module names and paths to the file containing the PureScript module
249− -> M.Map ModuleName (FilePath, ForeignJS) -- ^ a map between module name and the file containing the foreign javascript for the module
248+ -> M.Map ModuleName FilePath -- ^ a map between module name and the file containing the foreign javascript for the module
250 -> Bool -- ^ Generate a prefix comment?
249 -> Bool -- ^ Generate a prefix comment?
251 -> MakeActions Make
250 -> MakeActions Make
252buildMakeActions outputDir filePathMap foreigns usePrefix =
251buildMakeActions outputDir filePathMap foreigns usePrefix =
@@ -257,7 +256,7 @@ buildMakeActions outputDir filePathMap foreigns usePrefix =
257 getInputTimestamp mn = do
256 getInputTimestamp mn = do
258 let path = fromMaybe (error "Module has no filename in 'make'") $ M.lookup mn filePathMap
257 let path = fromMaybe (error "Module has no filename in 'make'") $ M.lookup mn filePathMap
259 e1 <- traverseEither getTimestamp path
258 e1 <- traverseEither getTimestamp path
260− fPath <- maybe (return Nothing) (getTimestamp . fst) $ M.lookup mn foreigns
259+ fPath <- maybe (return Nothing) getTimestamp $ M.lookup mn foreigns
261 return $ fmap (max fPath) e1
260 return $ fmap (max fPath) e1
262
261
263 getOutputTimestamp :: ModuleName -> Make (Maybe UTCTime)
262 getOutputTimestamp :: ModuleName -> Make (Maybe UTCTime)
@@ -276,7 +275,7 @@ buildMakeActions outputDir filePathMap foreigns usePrefix =
276 codegen m _ exts = do
275 codegen m _ exts = do
277 let mn = CF.moduleName m
276 let mn = CF.moduleName m
278 foreignInclude <- case mn `M.lookup` foreigns of
277 foreignInclude <- case mn `M.lookup` foreigns of
279− Just (path, _)
278+ Just path
280 | not $ requiresForeign m -> do
279 | not $ requiresForeign m -> do
281 tell $ errorMessage $ UnnecessaryFFIModule mn path
280 tell $ errorMessage $ UnnecessaryFFIModule mn path
282 return Nothing
281 return Nothing
@@ -292,7 +291,7 @@ buildMakeActions outputDir filePathMap foreigns usePrefix =
292 js = unlines $ map ("// " ++) prefix ++ [pjs]
291 js = unlines $ map ("// " ++) prefix ++ [pjs]
293 lift $ do
292 lift $ do
294 writeTextFile jsFile js
293 writeTextFile jsFile js
295− maybe (return ()) (writeTextFile foreignFile . snd) $ mn `M.lookup` foreigns
294+ for_ (mn `M.lookup` foreigns) (readTextFile >=> writeTextFile foreignFile)
296 writeTextFile externsFile exts
295 writeTextFile externsFile exts
297
296
298 requiresForeign :: CF.Module a -> Bool
297 requiresForeign :: CF.Module a -> Bool
src/Language/PureScript/Parser/JS.hs+3−3
@@ -37,17 +37,17 @@ type ForeignJS = String
37
37
38parseForeignModulesFromFiles :: (Functor m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
38parseForeignModulesFromFiles :: (Functor m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
39 => [(FilePath, ForeignJS)]
39 => [(FilePath, ForeignJS)]
40− -> m (M.Map ModuleName (FilePath, ForeignJS))
40+ -> m (M.Map ModuleName FilePath)
41parseForeignModulesFromFiles files = do
41parseForeignModulesFromFiles files = do
42 foreigns <- parU files $ \(path, file) ->
42 foreigns <- parU files $ \(path, file) ->
43 case findModuleName (lines file) of
43 case findModuleName (lines file) of
44− Just name -> return (name, (path, file))
44+ Just name -> return (name, path)
45 Nothing -> throwError (errorMessage $ ErrorParsingFFIModule path)
45 Nothing -> throwError (errorMessage $ ErrorParsingFFIModule path)
46 let grouped = groupBy ((==) `on` fst) $ sortBy (compare `on` fst) foreigns
46 let grouped = groupBy ((==) `on` fst) $ sortBy (compare `on` fst) foreigns
47 forM_ grouped $ \grp ->
47 forM_ grouped $ \grp ->
48 when (length grp > 1) $ do
48 when (length grp > 1) $ do
49 let mn = fst (head grp)
49 let mn = fst (head grp)
50− paths = map (fst . snd) grp
50+ paths = map snd grp
51 tell $ errorMessage $ MultipleFFIModules mn paths
51 tell $ errorMessage $ MultipleFFIModules mn paths
52 return $ M.fromList foreigns
52 return $ M.fromList foreigns
53
53
tests/Main.hs+5−5
@@ -69,7 +69,7 @@ import Text.Parsec (ParseError)
69modulesDir :: FilePath
69modulesDir :: FilePath
70modulesDir = ".test_modules" </> "node_modules"
70modulesDir = ".test_modules" </> "node_modules"
71
71
72−makeActions :: M.Map P.ModuleName (FilePath, P.ForeignJS) -> P.MakeActions P.Make
72+makeActions :: M.Map P.ModuleName FilePath -> P.MakeActions P.Make
73makeActions foreigns = (P.buildMakeActions modulesDir (error "makeActions: input file map was read.") foreigns False)
73makeActions foreigns = (P.buildMakeActions modulesDir (error "makeActions: input file map was read.") foreigns False)
74 { P.getInputTimestamp = getInputTimestamp
74 { P.getInputTimestamp = getInputTimestamp
75 , P.getOutputTimestamp = getOutputTimestamp
75 , P.getOutputTimestamp = getOutputTimestamp
@@ -98,14 +98,14 @@ type TestM = WriterT [(FilePath, String)] IO
98runTest :: P.Make a -> IO (Either P.MultipleErrors a)
98runTest :: P.Make a -> IO (Either P.MultipleErrors a)
99runTest = fmap (fmap fst) . P.runMake P.defaultOptions
99runTest = fmap (fmap fst) . P.runMake P.defaultOptions
100
100
101−compile :: [FilePath] -> M.Map P.ModuleName (FilePath, P.ForeignJS) -> IO (Either P.MultipleErrors P.Environment)
101+compile :: [FilePath] -> M.Map P.ModuleName FilePath -> IO (Either P.MultipleErrors P.Environment)
102compile inputFiles foreigns = runTest $ do
102compile inputFiles foreigns = runTest $ do
103 fs <- liftIO $ readInput inputFiles
103 fs <- liftIO $ readInput inputFiles
104 ms <- P.parseModulesFromFiles id fs
104 ms <- P.parseModulesFromFiles id fs
105 P.make (makeActions foreigns) (map snd ms)
105 P.make (makeActions foreigns) (map snd ms)
106
106
107assert :: [FilePath] ->
107assert :: [FilePath] ->
108− M.Map P.ModuleName (FilePath, P.ForeignJS) ->
108+ M.Map P.ModuleName FilePath ->
109 (Either P.MultipleErrors P.Environment -> IO (Maybe String)) ->
109 (Either P.MultipleErrors P.Environment -> IO (Maybe String)) ->
110 TestM ()
110 TestM ()
111assert inputFiles foreigns f = do
111assert inputFiles foreigns f = do
@@ -115,7 +115,7 @@ assert inputFiles foreigns f = do
115 Just err -> tell [(last inputFiles, err)]
115 Just err -> tell [(last inputFiles, err)]
116 Nothing -> return ()
116 Nothing -> return ()
117
117
118−assertCompiles :: [FilePath] -> M.Map P.ModuleName (FilePath, P.ForeignJS) -> TestM ()
118+assertCompiles :: [FilePath] -> M.Map P.ModuleName FilePath -> TestM ()
119assertCompiles inputFiles foreigns = do
119assertCompiles inputFiles foreigns = do
120 liftIO . putStrLn $ "Assert " ++ last inputFiles ++ " compiles successfully"
120 liftIO . putStrLn $ "Assert " ++ last inputFiles ++ " compiles successfully"
121 assert inputFiles foreigns $ \e ->
121 assert inputFiles foreigns $ \e ->
@@ -131,7 +131,7 @@ assertCompiles inputFiles foreigns = do
131 Just (ExitFailure _, _, err) -> return $ Just err
131 Just (ExitFailure _, _, err) -> return $ Just err
132 Nothing -> return $ Just "Couldn't find node.js executable"
132 Nothing -> return $ Just "Couldn't find node.js executable"
133
133
134−assertDoesNotCompile :: [FilePath] -> M.Map P.ModuleName (FilePath, P.ForeignJS) -> TestM ()
134+assertDoesNotCompile :: [FilePath] -> M.Map P.ModuleName FilePath -> TestM ()
135assertDoesNotCompile inputFiles foreigns = do
135assertDoesNotCompile inputFiles foreigns = do
136 let testFile = last inputFiles
136 let testFile = last inputFiles
137 liftIO . putStrLn $ "Assert " ++ testFile ++ " does not compile"
137 liftIO . putStrLn $ "Assert " ++ testFile ++ " does not compile"