Skip to content

Commit

Permalink
Properly handle output directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
athas committed Dec 10, 2023
1 parent 16a9ac1 commit 66508ba
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/Futhark/CLI/Literate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import System.Directory
( copyFile,
createDirectoryIfMissing,
doesFileExist,
getCurrentDirectory,
removePathForcibly,
setCurrentDirectory,
)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

0 comments on commit 66508ba

Please sign in to comment.