on master help sign in
add filelock when compiling with make, reactor, and repl
commitf57012c90ad2cf535c99431f1e8d951431af84b1 authorEvan Czaplicki <evancz@users.noreply.github.com> dateThu 27 Jun 2019, 16:16 (7 years ago) parent22e7413
4 files changed+68−61
builder/src/Stuff.hs+3−10 terminal/src/Develop.hs+14−8 terminal/src/Make.hs+50−42 terminal/src/Repl.hs+1−1
builder/src/Stuff.hs+3−10
@@ -8,8 +8,7 @@ module Stuff
88 , elmo
99 , temp
1010 , findRoot
11− , withProjectLock
12− , withCacheLock
11+ , withRootLock
1312 , PackageCache
1413 , getPackageCache
1514 , registry
@@ -120,19 +119,13 @@ findRootHelp dirs =
120119-- LOCKS
121120
122121
123−withProjectLock :: FilePath -> IO a -> IO a
124−withProjectLock root work =
122+withRootLock :: FilePath -> IO a -> IO a
123+withRootLock root work =
125124 do let dir = stuff root
126125 Dir.createDirectoryIfMissing True dir
127126 Lock.withFileLock (dir </> "project.lock") Lock.Exclusive (\_ -> work)
128127
129128
130−withCacheLock :: PackageCache -> IO a -> IO a
131−withCacheLock (PackageCache dir) work =
132− Lock.withFileLock (dir </> "cache.lock") Lock.Exclusive (\_ -> work)
133−
134−
135−
136129
137130-- PACKAGE CACHES
138131
terminal/src/Develop.hs+14−8
@@ -138,7 +138,7 @@ serveElm :: FilePath -> Snap ()
138138serveElm path =
139139 do guard (takeExtension path == ".elm")
140140 modifyResponse (setContentType "text/html")
141− result <- liftIO $ Task.run $ compile path
141+ result <- liftIO $ compile path
142142 case result of
143143 Right builder ->
144144 writeBuilder builder
@@ -148,14 +148,20 @@ serveElm path =
148148 Exit.toJson $ Exit.reactorToReport exit
149149
150150
151−compile :: FilePath -> Task.Task Exit.Reactor B.Builder
151+compile :: FilePath -> IO (Either Exit.Reactor B.Builder)
152152compile path =
153− do root <- Task.mio Exit.ReactorNoOutline Stuff.findRoot
154− details <- Task.eio Exit.ReactorBadDetails $ Details.load Reporting.silent root
155− artifacts <- Task.eio Exit.ReactorBadBuild $ Build.fromMains Reporting.silent root details (NE.List path [])
156− javascript <- Task.mapError Exit.ReactorBadGenerate $ Generate.dev root details artifacts
157− let (NE.List name _) = Build.getMainNames artifacts
158− return $ Html.sandwich name javascript
153+ do maybeRoot <- Stuff.findRoot
154+ case maybeRoot of
155+ Nothing ->
156+ return $ Left $ Exit.ReactorNoOutline
157+
158+ Just root ->
159+ Stuff.withRootLock root $ Task.run $
160+ do details <- Task.eio Exit.ReactorBadDetails $ Details.load Reporting.silent root
161+ artifacts <- Task.eio Exit.ReactorBadBuild $ Build.fromMains Reporting.silent root details (NE.List path [])
162+ javascript <- Task.mapError Exit.ReactorBadGenerate $ Generate.dev root details artifacts
163+ let (NE.List name _) = Build.getMainNames artifacts
164+ return $ Html.sandwich name javascript
159165
160166
161167
terminal/src/Make.hs+50−42
@@ -62,49 +62,57 @@ type Task a = Task.Task Exit.Make a
6262
6363
6464run :: [FilePath] -> Flags -> IO ()
65−run paths (Flags debug optimize maybeOutput report maybeDocs) =
65+run paths flags@(Flags _ _ _ report _) =
6666 do style <- getStyle report
67− Reporting.attemptWithStyle style Exit.makeToReport $ Task.run $
68− do root <- Task.mio Exit.MakeNoOutline Stuff.findRoot
69− desiredMode <- getMode debug optimize
70− details <- Task.eio Exit.MakeBadDetails (Details.load style root)
71− case paths of
72− [] ->
73− do exposed <- getExposed details
74− buildExposed style root details maybeDocs exposed
75−
76− p:ps ->
77− do artifacts <- buildPaths style root details (NE.List p ps)
78− case maybeOutput of
79− Nothing ->
80− case getMains artifacts of
81− [] ->
82− return ()
83−
84− [name] ->
85− do builder <- toBuilder root details desiredMode artifacts
86− generate style "index.html" (Html.sandwich name builder) (NE.List name [])
87−
88− name:names ->
89− do builder <- toBuilder root details desiredMode artifacts
90− generate style "elm.js" builder (NE.List name names)
91−
92− Just DevNull ->
93− return ()
94−
95− Just (JS target) ->
96− case getNoMains artifacts of
97− [] ->
98− do builder <- toBuilder root details desiredMode artifacts
99− generate style target builder (Build.getMainNames artifacts)
100−
101− name:names ->
102− Task.throw (Exit.MakeNonMainFilesIntoJavaScript name names)
103−
104− Just (Html target) ->
105− do name <- hasOneMain artifacts
106− builder <- toBuilder root details desiredMode artifacts
107− generate style target (Html.sandwich name builder) (NE.List name [])
67+ maybeRoot <- Stuff.findRoot
68+ Reporting.attemptWithStyle style Exit.makeToReport $
69+ case maybeRoot of
70+ Just root -> runHelp root paths style flags
71+ Nothing -> return $ Left $ Exit.MakeNoOutline
72+
73+
74+runHelp :: FilePath -> [FilePath] -> Reporting.Style -> Flags -> IO (Either Exit.Make ())
75+runHelp root paths style (Flags debug optimize maybeOutput _ maybeDocs) =
76+ Stuff.withRootLock root $ Task.run $
77+ do desiredMode <- getMode debug optimize
78+ details <- Task.eio Exit.MakeBadDetails (Details.load style root)
79+ case paths of
80+ [] ->
81+ do exposed <- getExposed details
82+ buildExposed style root details maybeDocs exposed
83+
84+ p:ps ->
85+ do artifacts <- buildPaths style root details (NE.List p ps)
86+ case maybeOutput of
87+ Nothing ->
88+ case getMains artifacts of
89+ [] ->
90+ return ()
91+
92+ [name] ->
93+ do builder <- toBuilder root details desiredMode artifacts
94+ generate style "index.html" (Html.sandwich name builder) (NE.List name [])
95+
96+ name:names ->
97+ do builder <- toBuilder root details desiredMode artifacts
98+ generate style "elm.js" builder (NE.List name names)
99+
100+ Just DevNull ->
101+ return ()
102+
103+ Just (JS target) ->
104+ case getNoMains artifacts of
105+ [] ->
106+ do builder <- toBuilder root details desiredMode artifacts
107+ generate style target builder (Build.getMainNames artifacts)
108+
109+ name:names ->
110+ Task.throw (Exit.MakeNonMainFilesIntoJavaScript name names)
111+
112+ Just (Html target) ->
113+ do name <- hasOneMain artifacts
114+ builder <- toBuilder root details desiredMode artifacts
115+ generate style target (Html.sandwich name builder) (NE.List name [])
108116
109117
110118
terminal/src/Repl.hs+1−1
@@ -377,7 +377,7 @@ data Output
377377
378378attemptEval :: Env -> State -> State -> Output -> IO State
379379attemptEval (Env root interpreter ansi) oldState newState output =
380− do result <- Task.run $
380+ do result <- Stuff.withRootLock root $ Task.run $
381381 do details <-
382382 Task.eio Exit.ReplBadDetails $
383383 Details.load Reporting.silent root