on master help sign in
Get rid of Build.Info file, move compiler version to Elm.Internal.Version and use Elm's version conventions
commit26a8c82b6fef15514f905549f7544d7eee692300 authorEvan Czaplicki <info@elm-lang.org> dateTue 17 Dec 2013, 11:36 (13 years ago) parentb905679
8 files changed+24−34
Elm.cabal−2 compiler/Build/Flags.hs+3−3 compiler/Build/Info.hs−11 compiler/Compiler.hs+7−10 compiler/Elm/Internal/Utils.hs+1−1 compiler/Elm/Internal/Version.hs+6 compiler/InterfaceSerialization.hs+4−4 compiler/SourceSyntax/Module.hs+3−3
Elm.cabal−2
@@ -85,7 +85,6 @@ Library
8585 Build.Dependencies,
8686 Build.File,
8787 Build.Flags,
88− Build.Info,
8988 Build.Print,
9089 Build.Source,
9190 Build.Utils,
@@ -165,7 +164,6 @@ Executable elm
165164 Build.Dependencies,
166165 Build.File,
167166 Build.Flags,
168− Build.Info,
169167 Build.Print,
170168 Build.Source,
171169 Build.Utils,
compiler/Build/Flags.hs+3−3
@@ -1,7 +1,7 @@
11{-# LANGUAGE DeriveDataTypeable #-}
22module Build.Flags where
33
4−import qualified Build.Info as Info
4+import qualified Elm.Internal.Version as Version
55import System.Console.CmdArgs
66
77data Flags = Flags
@@ -40,5 +40,5 @@ flags = Flags
4040 &= help "Print out infered types of top-level definitions."
4141 } &= help "Compile Elm programs to HTML, CSS, and JavaScript."
4242 &= helpArg [explicit, name "help", name "h"]
43− &= versionArg [explicit, name "version", name "v", summary Info.version]
44− &= summary ("The Elm Compiler " ++ Info.version ++ ", (c) Evan Czaplicki 2011-2013")
43+ &= versionArg [explicit, name "version", name "v", summary (show Version.elmVersion)]
44+ &= summary ("The Elm Compiler " ++ show Version.elmVersion ++ ", (c) Evan Czaplicki 2011-2013")
compiler/Build/Info.hsdeleted−11
@@ -1,11 +0,0 @@
1−module Build.Info where
2−
3−import qualified Paths_Elm as This
4−import qualified Data.Version as Version
5−
6−version :: String
7−version = Version.showVersion This.version
8−
9−runtime :: IO FilePath
10−runtime = This.getDataFileName "elm-runtime.js"
11−
compiler/Compiler.hs+7−10
@@ -2,6 +2,7 @@ module Main where
22
33import Control.Monad (foldM)
44import qualified Data.Map as Map
5+import qualified Data.Maybe as Maybe
56import qualified Text.Blaze.Html.Renderer.Utf8 as Blaze
67import qualified Data.ByteString.Lazy.Char8 as BS
78import qualified System.Console.CmdArgs as CmdArgs
@@ -13,9 +14,9 @@ import Build.Dependencies (getSortedDependencies)
1314import qualified Generate.Html as Html
1415import qualified Metadata.Prelude as Prelude
1516import qualified Build.Utils as Utils
16−import qualified Build.Info as Info
1717import qualified Build.Flags as Flag
1818import qualified Build.File as File
19+import qualified Elm.Internal.Paths as Path
1920
2021main :: IO ()
2122main = do setNumCapabilities =<< getNumProcessors
@@ -46,7 +47,7 @@ build flags rootFile =
4647 then do putStr "Generating JavaScript ... "
4748 return ("js", js)
4849 else do putStr "Generating HTML ... "
49− makeHtml js moduleName
50+ return (makeHtml js moduleName)
5051
5152 let targetFile = Utils.buildPath flags rootFile extension
5253 createDirectoryIfMissing True (takeDirectory targetFile)
@@ -61,11 +62,7 @@ build flags rootFile =
6162
6263 sources js = map Html.Link (Flag.scripts flags) ++ [ Html.Source js ]
6364
64− makeHtml js moduleName = do
65− rtsPath <- case Flag.runtime flags of
66− Just fp -> return fp
67− Nothing -> Info.runtime
68−
69− let html = Html.generate
70− rtsPath (takeBaseName rootFile) (sources js) moduleName ""
71− return ("html", Blaze.renderHtml html)
65+ makeHtml js moduleName = ("html", Blaze.renderHtml html)
66+ where
67+ rtsPath = Maybe.fromMaybe Path.runtime (Flag.runtime flags)
68+ html = Html.generate rtsPath (takeBaseName rootFile) (sources js) moduleName ""
compiler/Elm/Internal/Utils.hs+1−1
@@ -25,4 +25,4 @@ interfaces = unsafePerformIO $ Prelude.interfaces
2525
2626-- |This function extracts the module name of a given source program.
2727moduleName :: String -> Maybe String
28−moduleName = Parser.getModuleName
28+moduleName = Parser.getModuleName
compiler/Elm/Internal/Version.hs+6
@@ -8,6 +8,12 @@ import Data.Char (isDigit)
88import qualified Data.List as List
99import Data.Typeable
1010import qualified Data.Text as T
11+import qualified Paths_Elm as This
12+import qualified Data.Version as Version
13+
14+elmVersion :: Version
15+elmVersion = V ns ""
16+ where (Version.Version ns _) =This.version
1117
1218-- Data representation
1319
compiler/InterfaceSerialization.hs+4−4
@@ -6,8 +6,7 @@ module InterfaceSerialization ( loadInterface
66import qualified Data.ByteString.Lazy as L
77import qualified Data.Binary as Binary
88
9−import Paths_Elm (version)
10−import Data.Version (showVersion)
9+import qualified Elm.Internal.Version as Version
1110import System.Directory (doesFileExist)
1211import System.IO (hPutStrLn, stderr)
1312import System.Exit (exitFailure)
@@ -42,11 +41,12 @@ interfaceDecode filePath bytes = do
4241validVersion :: FilePath -> (String, ModuleInterface) ->
4342 Either String (String, ModuleInterface)
4443validVersion filePath (name, interface) =
45− if iVersion interface == showVersion version then
44+ if iVersion interface == Version.elmVersion then
4645 Right (name, interface)
4746 else
4847 Left $ concat
4948 [ "Error reading build artifact: ", filePath, "\n"
50− , " It was generated by a different version of the compiler: ", iVersion interface, "\n"
49+ , " It was generated by a different version of the compiler: "
50+ , show (iVersion interface), "\n"
5151 , " Please remove the file and try again.\n"
5252 ]
compiler/SourceSyntax/Module.hs+3−3
@@ -14,7 +14,7 @@ import SourceSyntax.Type
1414import System.FilePath (joinPath)
1515import Control.Monad (liftM)
1616
17−import qualified Build.Info as Info
17+import qualified Elm.Internal.Version as Version
1818
1919data Module tipe var =
2020 Module [String] Exports Imports [Declaration tipe var]
@@ -61,7 +61,7 @@ type Interfaces = Map.Map String ModuleInterface
6161type ADT = (String, [String], [(String,[Type])])
6262
6363data ModuleInterface = ModuleInterface {
64− iVersion :: String,
64+ iVersion :: Version.Version,
6565 iTypes :: Map.Map String Type,
6666 iImports :: [(String, ImportMethod)],
6767 iAdts :: [ADT],
@@ -71,7 +71,7 @@ data ModuleInterface = ModuleInterface {
7171
7272metaToInterface metaModule =
7373 ModuleInterface
74− { iVersion = Info.version
74+ { iVersion = Version.elmVersion
7575 , iTypes = types metaModule
7676 , iImports = imports metaModule
7777 , iAdts = datatypes metaModule