on master help sign in
Add Elm.Details.verifyInstall and start using Solver.initEnv
978ed5dEvan Czaplicki
builder/src/Elm/Details.hs+41−49
@@ -5,9 +5,10 @@ module Elm.Details
5 , ValidOutline(..)
5 , ValidOutline(..)
6 , Local(..)
6 , Local(..)
7 , Foreign(..)
7 , Foreign(..)
8− , verify
8+ , load
9 , loadObjects
9 , loadObjects
10 , loadInterfaces
10 , loadInterfaces
11+ , verifyInstall
11 )
12 )
12 where
13 where
13
14
@@ -91,7 +92,7 @@ type Interfaces =
91
92
92
93
93
94
94−-- LOAD
95+-- LOAD ARTIFACTS
95
96
96
97
97loadObjects :: FilePath -> Details -> IO (MVar (Maybe Opt.GlobalGraph))
98loadObjects :: FilePath -> Details -> IO (MVar (Maybe Opt.GlobalGraph))
@@ -109,29 +110,43 @@ loadInterfaces root (Details _ _ _ _ extras) =
109
110
110
111
111
112
112−-- VERIFY
113+-- VERIFY INSTALL -- used by Install
113
114
114
115
116+verifyInstall :: FilePath -> Solver.Env -> Outline.Outline -> IO (Either Exit.Details ())
117+verifyInstall root (Solver.Env cache manager connection registry) outline =
118+ do time <- File.getTime (root </> "elm.json")
119+ let key = Reporting.ignorer
120+ let env = Env key root cache manager connection registry
121+ case outline of
122+ Outline.Pkg pkg -> Task.run (verifyPkg env time pkg >> return ())
123+ Outline.App app -> Task.run (verifyApp env time app >> return ())
124+
125+
126+
127+-- LOAD -- used by Make, Repl, Reactor
128+
129+
115−verify :: Reporting.Style -> FilePath -> IO (Either Exit.Details Details)
130+load :: Reporting.Style -> FilePath -> IO (Either Exit.Details Details)
116−verify style root =
131+load style root =
117 do newTime <- File.getTime (root </> "elm.json")
132 do newTime <- File.getTime (root </> "elm.json")
118 maybeDetails <- File.readBinary (Stuff.details root)
133 maybeDetails <- File.readBinary (Stuff.details root)
119 case maybeDetails of
134 case maybeDetails of
120 Nothing ->
135 Nothing ->
121− verifyFromScratch style root newTime
136+ generate style root newTime
122
137
123 Just details@(Details oldTime _ _ _ _) ->
138 Just details@(Details oldTime _ _ _ _) ->
124 if oldTime == newTime
139 if oldTime == newTime
125 then return (Right details)
140 then return (Right details)
126− else verifyFromScratch style root newTime
141+ else generate style root newTime
127
142
128
143
129
144
130−-- VERIFY FROM SCRATCH
145+-- GENERATE
131
146
132
147
133−verifyFromScratch :: Reporting.Style -> FilePath -> File.Time -> IO (Either Exit.Details Details)
148+generate :: Reporting.Style -> FilePath -> File.Time -> IO (Either Exit.Details Details)
134−verifyFromScratch style root time =
149+generate style root time =
135 Reporting.trackDetails style $ \key ->
150 Reporting.trackDetails style $ \key ->
136 do result <- initEnv key root
151 do result <- initEnv key root
137 case result of
152 case result of
@@ -144,6 +159,10 @@ verifyFromScratch style root time =
144 Outline.App app -> Task.run (verifyApp env time app)
159 Outline.App app -> Task.run (verifyApp env time app)
145
160
146
161
162+
163+-- ENV
164+
165+
147data Env =
166data Env =
148 Env
167 Env
149 { _key :: Reporting.DKey
168 { _key :: Reporting.DKey
@@ -157,47 +176,20 @@ data Env =
157
176
158initEnv :: Reporting.DKey -> FilePath -> IO (Either Exit.Details (Env, Outline.Outline))
177initEnv :: Reporting.DKey -> FilePath -> IO (Either Exit.Details (Env, Outline.Outline))
159initEnv key root =
178initEnv key root =
160− do cacheMVar <- fork Stuff.getPackageCache
179+ do mvar <- fork Solver.initEnv
161− managerMVar <- fork Http.getManager
162− registryMVar <- fork (Registry.read =<< readMVar cacheMVar)
163 eitherOutline <- Outline.read root
180 eitherOutline <- Outline.read root
164− cache <- readMVar cacheMVar
165− manager <- readMVar managerMVar
166− maybeRegistry <- readMVar registryMVar
167 case eitherOutline of
181 case eitherOutline of
168 Left problem ->
182 Left problem ->
169 return $ Left $ Exit.DetailsBadOutline problem
183 return $ Left $ Exit.DetailsBadOutline problem
170
184
171 Right outline ->
185 Right outline ->
172− case maybeRegistry of
186+ do maybeEnv <- readMVar mvar
173− Nothing ->
187+ case maybeEnv of
174− do eitherRegistry <- Registry.fetch manager cache
175− case eitherRegistry of
176− Right latestRegistry ->
177− let
178− conn = Solver.Online manager
179− env = Env key root cache manager conn latestRegistry
180− in
181− return $ Right (env, outline)
182−
183− Left problem ->
188+ Left problem ->
184− return $ Left $ Exit.DetailsCannotGetRegistry problem
189+ return $ Left $ Exit.DetailsCannotGetRegistry problem
185−
190+
186− Just cachedRegistry ->
191+ Right (Solver.Env cache manager connection registry) ->
187− do eitherRegistry <- Registry.update manager cache cachedRegistry
188− case eitherRegistry of
189− Right latestRegistry ->
190− let
191− conn = Solver.Online manager
192− env = Env key root cache manager conn latestRegistry
193− in
194− return $ Right (env, outline)
195−
196− Left _ ->
197− let
198− env = Env key root cache manager Solver.Offline cachedRegistry
192+ return $ Right (Env key root cache manager connection registry, outline)
199− in
200− return $ Right (env, outline)
201
193
202
194
203
195
@@ -573,8 +565,8 @@ crawlModule foreignDeps mvar pkg src name =
573
565
574crawlFile :: Map.Map ModuleName.Raw ForeignInterface -> MVar StatusDict -> Pkg.Name -> FilePath -> ModuleName.Raw -> FilePath -> IO (Maybe Status)
566crawlFile :: Map.Map ModuleName.Raw ForeignInterface -> MVar StatusDict -> Pkg.Name -> FilePath -> ModuleName.Raw -> FilePath -> IO (Maybe Status)
575crawlFile foreignDeps mvar pkg src name path =
567crawlFile foreignDeps mvar pkg src name path =
576− do result <- Parse.fromFile pkg path
568+ do bytes <- File.readUtf8 path
577− case result of
569+ case Parse.fromByteString pkg bytes of
578 Right modul@(Src.Module (Just actualName) _ imports _ _ _ _ _) | name == actualName ->
570 Right modul@(Src.Module (Just actualName) _ imports _ _ _ _ _) | name == actualName ->
579 do deps <- crawlImports foreignDeps mvar pkg src imports
571 do deps <- crawlImports foreignDeps mvar pkg src imports
580 return (Just (SLocal deps modul))
572 return (Just (SLocal deps modul))
@@ -600,8 +592,8 @@ crawlKernel foreignDeps mvar pkg src name =
600 exists <- File.exists path
592 exists <- File.exists path
601 if exists
593 if exists
602 then
594 then
595+ do bytes <- File.readUtf8 path
603− do maybeContent <- Kernel.fromFile pkg (Map.mapMaybe getDepHome foreignDeps) path
596+ case Kernel.fromByteString pkg (Map.mapMaybe getDepHome foreignDeps) bytes of
604− case maybeContent of
605 Nothing ->
597 Nothing ->
606 return Nothing
598 return Nothing
607
599