From 66508ba2c1f6f9deffe44a40f63d822253ff282c Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Sun, 10 Dec 2023 19:53:11 +0100 Subject: [PATCH] Properly handle output directory. --- src/Futhark/CLI/Literate.hs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Futhark/CLI/Literate.hs b/src/Futhark/CLI/Literate.hs index 8ca9f759e2..ac36b4636b 100644 --- a/src/Futhark/CLI/Literate.hs +++ b/src/Futhark/CLI/Literate.hs @@ -45,6 +45,7 @@ import System.Directory ( copyFile, createDirectoryIfMissing, doesFileExist, + getCurrentDirectory, removePathForcibly, setCurrentDirectory, ) @@ -1160,7 +1161,7 @@ main = mainWithOptions initialOptions commandLineOptions "program" $ \args opts system futhark ["hash", prog] mempty let mdfile = fromMaybe (prog `replaceExtension` "md") $ scriptOutput opts - dir = takeDirectory mdfile + prog_dir = takeDirectory prog imgdir = dropExtension (takeFileName mdfile) <> "-img" run_options = scriptExtraOptions opts onLine "call" l = T.putStrLn l @@ -1173,6 +1174,8 @@ main = mainWithOptions initialOptions commandLineOptions "program" $ \args opts else const . const $ pure () } + orig_dir <- getCurrentDirectory + withScriptServer cfg $ \server -> do let env = Env @@ -1183,10 +1186,10 @@ main = mainWithOptions initialOptions commandLineOptions "program" $ \args opts } when (scriptVerbose opts > 0) $ do - T.hPutStrLn stderr $ "Executing from " <> T.pack dir - setCurrentDirectory dir + T.hPutStrLn stderr $ "Executing from " <> T.pack prog_dir + setCurrentDirectory prog_dir (failure, md) <- processScript env script - T.writeFile mdfile md + T.writeFile (orig_dir mdfile) md when (failure == Failure) exitFailure _ -> Nothing