Skip to content

Commit f2bcc55

Browse files
committed
Return to ~/.elm for ELM_HOME and start namespacing package artifact caches instead for built-with-elm-first-so-missing-wire compilation issue
1 parent e19c817 commit f2bcc55

File tree

17 files changed

+181
-21
lines changed

17 files changed

+181
-21
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ travis.log
1313
extra/node_modules
1414
extra/.cache
1515
.stack-work
16+
17+
# @TESTS
18+
elm-home
19+

builder/src/Elm/Details.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ verifyDep (Env key _ _ cache manager _ _) depsMVar solution pkg details@(Solver.
390390
then
391391
do Reporting.report key Reporting.DCached
392392
maybeCache <- File.readBinary (Stuff.package cache pkg vsn </> "artifacts.dat")
393+
& Lamdera.alternativeImplementation (File.readBinary (Stuff.package cache pkg vsn </> "artifacts.x.dat"))
393394
case maybeCache of
394395
Nothing ->
395396
build key cache depsMVar pkg details fingerprint Set.empty
@@ -484,6 +485,7 @@ build key cache depsMVar pkg (Solver.Details vsn _) f fs =
484485
Just results ->
485486
let
486487
path = Stuff.package cache pkg vsn </> "artifacts.dat"
488+
& Lamdera.alternativeImplementation (Stuff.package cache pkg vsn </> "artifacts.x.dat")
487489
ifaces = gatherInterfaces exposedDict results
488490
objects = gatherObjects results
489491
artifacts = Artifacts ifaces objects

builder/src/Stuff.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,19 @@ stuff root =
4646
details :: FilePath -> FilePath
4747
details root =
4848
stuff root </> "d.dat"
49+
& Lamdera.alternativeImplementation (stuff root </> "d.x.dat")
4950

5051

5152
interfaces :: FilePath -> FilePath
5253
interfaces root =
5354
stuff root </> "i.dat"
55+
& Lamdera.alternativeImplementation (stuff root </> "i.x.dat")
5456

5557

5658
objects :: FilePath -> FilePath
5759
objects root =
5860
stuff root </> "o.dat"
61+
& Lamdera.alternativeImplementation (stuff root </> "o.x.dat")
5962

6063

6164
prepublishDir :: FilePath -> FilePath
@@ -180,4 +183,4 @@ getElmHome =
180183
case maybeCustomHome of
181184
Just customHome -> return customHome
182185
Nothing -> Dir.getAppUserDataDirectory "elm"
183-
& Lamdera.alternativeImplementation (Dir.getAppUserDataDirectory "lamdera")
186+
-- & Lamdera.alternativeImplementation (Dir.getAppUserDataDirectory "lamdera")

elm.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ Executable lamdera
299299
-- Testing:
300300
EasyTest
301301
Test
302+
Test.Caching
302303
Test.Check
303304
Test.Helpers
304305
Test.Lamdera

ext-common/Ext/Common.hs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ atomicPutStrLn :: String -> IO ()
221221
atomicPutStrLn str =
222222
withMVar printLock (\_ -> hPutStr stdout (str <> "\n") >> hFlush stdout)
223223

224+
atomicPutStrLn_ :: Text -> IO ()
225+
atomicPutStrLn_ text =
226+
atomicPutStrLn $ T.unpack text
227+
224228
atomicPutStrLnDebug :: String -> IO ()
225229
atomicPutStrLnDebug s = do
226230
onlyWhen (isDebug_) $ atomicPutStrLn s
@@ -380,23 +384,29 @@ bashq command =
380384
c_ :: String -> [String] -> String -> IO String
381385
c_ bin args input = do
382386
atomicPutStrLnDebug $ "🤖 " <> bin <> " " <> show args <> " " <> input
383-
(exit, stdout, stderr) <- System.Process.readProcessWithExitCode bin args input
387+
(exit, stdOut, stdErr) <- System.Process.readProcessWithExitCode bin args input
384388
res <-
385-
if Prelude.length stderr > 0
386-
then pure stderr
387-
else pure stdout
388-
atomicPutStrLnDebug $ "└── " <> res
389-
pure res
389+
if Prelude.length stdErr > 0
390+
then pure stdErr
391+
else pure stdOut
392+
-- This doesn't quite work for debugging because bash will honour the sequence codes of the output
393+
-- which gives us confusing results. I.e. Elm compilation clears the buffer during operation
394+
-- onlyWhen (Prelude.length stdErr > 0) $ atomicPutStrLnDebug $ "└── stdErr: " <> stdErr
395+
-- onlyWhen (Prelude.length stdOut > 0) $ atomicPutStrLnDebug $ "└── stdOut: " <> stdOut
396+
-- This doesn't happen with the show instance as it escapes sequences inside the string
397+
atomicPutStrLnDebug $ "└── " <> show (exit, stdOut, stdErr)
398+
pure $ show (exit, stdOut, stdErr)
399+
390400

391401
cq_ :: String -> [String] -> String -> IO String
392402
cq_ bin args input = do
393403
atomicPutStrLnDebug $ "🤖 " <> bin <> " " <> show args <> " " <> input
394-
(exit, stdout, stderr) <- System.Process.readProcessWithExitCode bin args input
404+
(exit, stdOut, stdErr) <- System.Process.readProcessWithExitCode bin args input
395405
res <-
396-
if Prelude.length stderr > 0
397-
then pure stderr
398-
else pure stdout
399-
pure res
406+
if Prelude.length stdErr > 0
407+
then pure stdErr
408+
else pure stdOut
409+
pure $ show (exit, stdOut, stdErr)
400410

401411

402412
requireBinary :: String -> IO FilePath

extra/Lamdera.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,14 +211,17 @@ debug str =
211211
debugT text =
212212
liftIO $ debug_ (T.unpack text)
213213

214+
alternativeImplementation :: a -> a -> a
214215
alternativeImplementation fn ignored =
215216
fn
216217

218+
alternativeImplementationWhen :: Bool -> a -> a -> a
217219
alternativeImplementationWhen cond fn original =
218220
if cond
219221
then fn
220222
else original
221223

224+
alternativeImplementationPassthrough :: (a -> b) -> a -> b
222225
alternativeImplementationPassthrough fn original =
223226
fn original
224227

extra/Lamdera/CLI/Reset.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ run () () = do
5555
then do
5656
progress $ "Removing artifacts in " <> elmHome
5757
let packageDir = elmHome </> Lamdera.Version.elm </> "packages"
58-
onlyWhen_ (doesDirectoryExist packageDir) $
58+
onlyWhen_ (doesDirectoryExist packageDir) $ do
5959
c $ "find " <> packageDir <> " | grep artifacts.dat | xargs rm"
60+
c $ "find " <> packageDir <> " | grep artifacts.x.dat | xargs rm"
6061

6162
else do
6263
nukeDir elmHome

test/Test.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import EasyTest
1414
import Lamdera
1515
import qualified Test.Snapshot
1616
import qualified Test.Lamdera
17+
import qualified Test.Caching
1718
import qualified Test.Check
1819
import qualified Test.Wire
1920
import qualified Test.Ext.ElmPages.Check

test/Test/Caching.hs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{-# LANGUAGE OverloadedStrings #-}
2+
{-# LANGUAGE BangPatterns #-}
3+
{-# LANGUAGE QuasiQuotes #-}
4+
5+
module Test.Caching where
6+
7+
import EasyTest
8+
import NeatInterpolation
9+
10+
import Test.Helpers
11+
import Lamdera hiding ((&))
12+
import Ext.Common
13+
14+
import Lamdera.Compile
15+
16+
17+
all = EasyTest.run suite
18+
19+
suite :: Test ()
20+
suite = tests $
21+
let
22+
project = "./test/scenario-empty-elm-init"
23+
24+
bashInScenario c = bash $ "cd " ++ project ++ " && " ++ c
25+
in
26+
[ scope "a package compiled with Elm first will gracefully recompile with Lamdera" $ do
27+
io $ do
28+
rmdir $ project ++ "/elm-home"
29+
setEnv "ELM_HOME" $ project ++ "/elm-home"
30+
-- @TODO remove this?
31+
setEnv "LDEBUG" "1"
32+
33+
elmCompilation <- io $ do
34+
rmdir $ project ++ "/elm-stuff"
35+
writeUtf8 (project ++ "/src/Main.elm") [text|
36+
module Main exposing (main)
37+
38+
import Html
39+
40+
41+
main =
42+
Html.text "hello!"
43+
|]
44+
bashInScenario "ELM_HOME=./elm-home ~/.local/bin/elm-0.19.1-official make src/Main.elm --output=/dev/null"
45+
46+
expect $ elmCompilation & stringContains "Success!"
47+
48+
lamderaCompilation <- io $ do
49+
rmdir $ project ++ "/elm-stuff"
50+
writeUtf8 (project ++ "/src/Main.elm") [text|
51+
module Main exposing (main)
52+
53+
import Html
54+
55+
56+
main =
57+
Html.text "hello!"
58+
59+
60+
will_fail_on_elm_caches =
61+
Html.w2_encode_Html
62+
|]
63+
64+
withDebug $ captureProcessOutput $ Lamdera.Compile.makeDev project ["src/Main.elm"]
65+
66+
io $ atomicPutStrLn_ lamderaCompilation
67+
expect $ lamderaCompilation & textContains "Success!"
68+
69+
io $ bashInScenario "git checkout src/Main.elm"
70+
71+
pure ()
72+
]

test/Test/Helpers.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,8 @@ catchOutputStdErr action = do
8585
pr <- EasyTest.io $ captureProcessResult action
8686
-- @TODO improve this to actually pull out values
8787
pure $ T.decodeUtf8 $ Test.Main.prStderr pr
88+
89+
90+
captureProcessOutput action = do
91+
pr <- captureProcessResult action
92+
hindent pr

0 commit comments

Comments
 (0)