git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Prefix output with a 'Generated by psc version X.Y.Z' comment #557
147a460Phil Freeman
psc-make/Main.hs+15−7
@@ -66,24 +66,28 @@ instance P.MonadMake Make where
66 liftError = either throwError return
66 liftError = either throwError return
67 progress = makeIO . U.putStrLn
67 progress = makeIO . U.putStrLn
68
68
69−compile :: FilePath -> [FilePath] -> FilePath -> P.Options -> IO ()
69+compile :: FilePath -> [FilePath] -> FilePath -> P.Options -> Bool -> IO ()
70−compile prelude input outputDir opts = do
70+compile prelude input outputDir opts usePrefix = do
71 modules <- readInput allInputFiles
71 modules <- readInput allInputFiles
72 case modules of
72 case modules of
73 Left err -> do
73 Left err -> do
74 U.print err
74 U.print err
75 exitFailure
75 exitFailure
76 Right ms -> do
76 Right ms -> do
77− e <- runMake $ P.make outputDir opts ms
77+ e <- runMake $ P.make outputDir opts ms prefix
78 case e of
78 case e of
79 Left err -> do
79 Left err -> do
80 U.putStrLn err
80 U.putStrLn err
81 exitFailure
81 exitFailure
82 Right _ -> do
82 Right _ -> do
83 exitSuccess
83 exitSuccess
84− where
84+ where
85+ prefix = if usePrefix
86+ then ["Generated by psc-make version " ++ showVersion Paths.version]
87+ else []
88+
85− allInputFiles | P.optionsNoPrelude opts = input
89+ allInputFiles | P.optionsNoPrelude opts = input
86− | otherwise = prelude : input
90+ | otherwise = prelude : input
87
91
88mkdirp :: FilePath -> IO ()
92mkdirp :: FilePath -> IO ()
89mkdirp = createDirectoryIfMissing True . takeDirectory
93mkdirp = createDirectoryIfMissing True . takeDirectory
@@ -123,8 +127,12 @@ verboseErrors = value $ flag $ (optInfo [ "v", "verbose-errors" ])
123options :: Term P.Options
127options :: Term P.Options
124options = P.Options <$> noPrelude <*> noTco <*> performRuntimeTypeChecks <*> noMagicDo <*> pure Nothing <*> noOpts <*> pure Nothing <*> pure [] <*> pure [] <*> verboseErrors
128options = P.Options <$> noPrelude <*> noTco <*> performRuntimeTypeChecks <*> noMagicDo <*> pure Nothing <*> noOpts <*> pure Nothing <*> pure [] <*> pure [] <*> verboseErrors
125
129
130+noPrefix :: Term Bool
131+noPrefix = value $ flag $ (optInfo ["p", "no-prefix" ])
132+ { optDoc = "Do not include comment header"}
133+
126term :: FilePath -> Term (IO ())
134term :: FilePath -> Term (IO ())
127−term prelude = compile prelude <$> inputFiles <*> outputDirectory <*> options
135+term prelude = compile prelude <$> inputFiles <*> outputDirectory <*> options <*> (not <$> noPrefix)
128
136
129termInfo :: TermInfo
137termInfo :: TermInfo
130termInfo = defTI
138termInfo = defTI
psc/Main.hs+11−4
@@ -44,15 +44,15 @@ readInput (Just input) = fmap collect $ forM input $ \inputFile -> do
44 collect :: [(FilePath, Either ParseError [P.Module])] -> Either ParseError [(FilePath, P.Module)]
44 collect :: [(FilePath, Either ParseError [P.Module])] -> Either ParseError [(FilePath, P.Module)]
45 collect = fmap concat . sequence . map (\(fp, e) -> fmap (map ((,) fp)) e)
45 collect = fmap concat . sequence . map (\(fp, e) -> fmap (map ((,) fp)) e)
46
46
47−compile :: FilePath -> P.Options -> Bool -> [FilePath] -> Maybe FilePath -> Maybe FilePath -> IO ()
47+compile :: FilePath -> P.Options -> Bool -> [FilePath] -> Maybe FilePath -> Maybe FilePath -> Bool -> IO ()
48−compile prelude opts stdin input output externs = do
48+compile prelude opts stdin input output externs usePrefix = do
49 modules <- readInput stdInOrInputFiles
49 modules <- readInput stdInOrInputFiles
50 case modules of
50 case modules of
51 Left err -> do
51 Left err -> do
52 U.hPutStr stderr $ show err
52 U.hPutStr stderr $ show err
53 exitFailure
53 exitFailure
54 Right ms -> do
54 Right ms -> do
55− case P.compile opts (map snd ms) of
55+ case P.compile opts (map snd ms) prefix of
56 Left err -> do
56 Left err -> do
57 U.hPutStrLn stderr err
57 U.hPutStrLn stderr err
58 exitFailure
58 exitFailure
@@ -69,6 +69,9 @@ compile prelude opts stdin input output externs = do
69 stdInOrInputFiles | stdin = Nothing
69 stdInOrInputFiles | stdin = Nothing
70 | P.optionsNoPrelude opts = Just input
70 | P.optionsNoPrelude opts = Just input
71 | otherwise = Just $ prelude : input
71 | otherwise = Just $ prelude : input
72+ prefix = if usePrefix
73+ then ["Generated by psc version " ++ showVersion Paths.version]
74+ else []
72
75
73mkdirp :: FilePath -> IO ()
76mkdirp :: FilePath -> IO ()
74mkdirp = createDirectoryIfMissing True . takeDirectory
77mkdirp = createDirectoryIfMissing True . takeDirectory
@@ -129,11 +132,15 @@ verboseErrors :: Term Bool
129verboseErrors = value $ flag $ (optInfo [ "v", "verbose-errors" ])
132verboseErrors = value $ flag $ (optInfo [ "v", "verbose-errors" ])
130 { optDoc = "Display verbose error messages" }
133 { optDoc = "Display verbose error messages" }
131
134
135+noPrefix :: Term Bool
136+noPrefix = value $ flag $ (optInfo ["no-prefix" ])
137+ { optDoc = "Do not include comment header"}
138+
132options :: Term P.Options
139options :: Term P.Options
133options = P.Options <$> noPrelude <*> noTco <*> performRuntimeTypeChecks <*> noMagicDo <*> runMain <*> noOpts <*> (Just <$> browserNamespace) <*> dceModules <*> codeGenModules <*> verboseErrors
140options = P.Options <$> noPrelude <*> noTco <*> performRuntimeTypeChecks <*> noMagicDo <*> runMain <*> noOpts <*> (Just <$> browserNamespace) <*> dceModules <*> codeGenModules <*> verboseErrors
134
141
135term :: FilePath -> Term (IO ())
142term :: FilePath -> Term (IO ())
136−term prelude = compile prelude <$> options <*> useStdIn <*> inputFiles <*> outputFile <*> externsFile
143+term prelude = compile prelude <$> options <*> useStdIn <*> inputFiles <*> outputFile <*> externsFile <*> (not <$> noPrefix)
137
144
138termInfo :: TermInfo
145termInfo :: TermInfo
139termInfo = defTI
146termInfo = defTI
psci/Main.hs+3−3
@@ -276,7 +276,7 @@ handleDeclaration :: P.Expr -> PSCI ()
276handleDeclaration value = do
276handleDeclaration value = do
277 st <- PSCI $ lift get
277 st <- PSCI $ lift get
278 let m = createTemporaryModule True st value
278 let m = createTemporaryModule True st value
279− e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st ++ [("$PSCI.purs", m)])
279+ e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st ++ [("$PSCI.purs", m)]) []
280 case e of
280 case e of
281 Left err -> PSCI $ outputStrLn err
281 Left err -> PSCI $ outputStrLn err
282 Right _ -> do
282 Right _ -> do
@@ -295,7 +295,7 @@ handleTypeOf :: P.Expr -> PSCI ()
295handleTypeOf value = do
295handleTypeOf value = do
296 st <- PSCI $ lift get
296 st <- PSCI $ lift get
297 let m = createTemporaryModule False st value
297 let m = createTemporaryModule False st value
298− e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st ++ [("$PSCI.purs", m)])
298+ e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st ++ [("$PSCI.purs", m)]) []
299 case e of
299 case e of
300 Left err -> PSCI $ outputStrLn err
300 Left err -> PSCI $ outputStrLn err
301 Right env' ->
301 Right env' ->
@@ -311,7 +311,7 @@ handleKindOf typ = do
311 st <- PSCI $ lift get
311 st <- PSCI $ lift get
312 let m = createTemporaryModuleForKind st typ
312 let m = createTemporaryModuleForKind st typ
313 mName = P.ModuleName [P.ProperName "$PSCI"]
313 mName = P.ModuleName [P.ProperName "$PSCI"]
314− e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st ++ [("$PSCI.purs", m)])
314+ e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st ++ [("$PSCI.purs", m)]) []
315 case e of
315 case e of
316 Left err -> PSCI $ outputStrLn err
316 Left err -> PSCI $ outputStrLn err
317 Right env' ->
317 Right env' ->
src/Language/PureScript.hs+10−8
@@ -67,11 +67,11 @@ import System.FilePath (pathSeparator)
67--
67--
68-- * Pretty-print the generated Javascript
68-- * Pretty-print the generated Javascript
69--
69--
70−compile :: Options -> [Module] -> Either String (String, String, Environment)
70+compile :: Options -> [Module] -> [String] -> Either String (String, String, Environment)
71compile = compile' initEnvironment
71compile = compile' initEnvironment
72
72
73−compile' :: Environment -> Options -> [Module] -> Either String (String, String, Environment)
73+compile' :: Environment -> Options -> [Module] -> [String] -> Either String (String, String, Environment)
74−compile' env opts ms = do
74+compile' env opts ms prefix = do
75 (sorted, _) <- sortModules $ map importPrim $ if optionsNoPrelude opts then ms else (map importPrelude ms)
75 (sorted, _) <- sortModules $ map importPrim $ if optionsNoPrelude opts then ms else (map importPrelude ms)
76 (desugared, nextVar) <- stringifyErrorStack True $ runSupplyT 0 $ desugar sorted
76 (desugared, nextVar) <- stringifyErrorStack True $ runSupplyT 0 $ desugar sorted
77 (elaborated, env') <- runCheck' opts env $ forM desugared $ typeCheckModule mainModuleIdent
77 (elaborated, env') <- runCheck' opts env $ forM desugared $ typeCheckModule mainModuleIdent
@@ -84,7 +84,8 @@ compile' env opts ms = do
84 let js = evalSupply nextVar $ concat <$> mapM (\m -> moduleToJs Globals opts m env') modulesToCodeGen
84 let js = evalSupply nextVar $ concat <$> mapM (\m -> moduleToJs Globals opts m env') modulesToCodeGen
85 let exts = intercalate "\n" . map (`moduleToPs` env') $ modulesToCodeGen
85 let exts = intercalate "\n" . map (`moduleToPs` env') $ modulesToCodeGen
86 js' <- generateMain env' opts js
86 js' <- generateMain env' opts js
87− return (prettyPrintJS js', exts, env')
87+ let pjs = unlines $ map ("// " ++) prefix ++ [prettyPrintJS js']
88+ return (pjs, exts, env')
88 where
89 where
89 mainModuleIdent = moduleNameFromString <$> optionsMain opts
90 mainModuleIdent = moduleNameFromString <$> optionsMain opts
90
91
@@ -169,8 +170,8 @@ class MonadMake m where
169-- If timestamps have not changed, the externs file can be used to provide the module's types without
170-- If timestamps have not changed, the externs file can be used to provide the module's types without
170-- having to typecheck the module again.
171-- having to typecheck the module again.
171--
172--
172−make :: (Functor m, Applicative m, Monad m, MonadMake m) => FilePath -> Options -> [(FilePath, Module)] -> m Environment
173+make :: (Functor m, Applicative m, Monad m, MonadMake m) => FilePath -> Options -> [(FilePath, Module)] -> [String] -> m Environment
173−make outputDir opts ms = do
174+make outputDir opts ms prefix = do
174 let filePathMap = M.fromList (map (\(fp, Module mn _ _) -> (mn, fp)) ms)
175 let filePathMap = M.fromList (map (\(fp, Module mn _ _) -> (mn, fp)) ms)
175
176
176 (sorted, graph) <- liftError $ sortModules $ map importPrim $ if optionsNoPrelude opts then map snd ms else (map (importPrelude . snd) ms)
177 (sorted, graph) <- liftError $ sortModules $ map importPrim $ if optionsNoPrelude opts then map snd ms else (map (importPrelude . snd) ms)
@@ -217,8 +218,9 @@ make outputDir opts ms = do
217 let mod' = Module moduleName' regrouped exps
218 let mod' = Module moduleName' regrouped exps
218 let [renamed] = renameInModules [mod']
219 let [renamed] = renameInModules [mod']
219
220
220− js <- prettyPrintJS <$> moduleToJs CommonJS opts renamed env'
221+ pjs <- prettyPrintJS <$> moduleToJs CommonJS opts renamed env'
222+ let js = unlines $ map ("// " ++) prefix ++ [pjs]
221− let exts = moduleToPs renamed env'
223+ let exts = unlines $ map ("-- " ++ ) prefix ++ [moduleToPs renamed env']
222
224
223 lift $ writeTextFile jsFile js
225 lift $ writeTextFile jsFile js
224 lift $ writeTextFile externsFile exts
226 lift $ writeTextFile externsFile exts
src/Language/PureScript/Options.hs+1
@@ -61,6 +61,7 @@ data Options = Options {
61 -- Verbose error message
61 -- Verbose error message
62 --
62 --
63 , optionsVerboseErrors :: Bool
63 , optionsVerboseErrors :: Bool
64+
64 } deriving Show
65 } deriving Show
65
66
66-- |
67-- |
tests/Main.hs+1−1
@@ -40,7 +40,7 @@ compile opts inputFiles = do
40 case modules of
40 case modules of
41 Left parseError ->
41 Left parseError ->
42 return (Left $ show parseError)
42 return (Left $ show parseError)
43− Right ms -> return $ P.compile opts ms
43+ Right ms -> return $ P.compile opts ms []
44
44
45assert :: FilePath -> P.Options -> FilePath -> (Either String (String, String, P.Environment) -> IO (Maybe String)) -> IO ()
45assert :: FilePath -> P.Options -> FilePath -> (Either String (String, String, P.Environment) -> IO (Maybe String)) -> IO ()
46assert preludeExterns opts inputFile f = do
46assert preludeExterns opts inputFile f = do