Search code examples
shake-build-system

how can I use the dir created by withTempDir in a rule?


I need to refer to the directory created by withTempDir by name in the Actions. I am guessing that the current working directory is changed by withTempDir, and that would likely work in the simple case. However some of the Actions must do their own (Cwd somewhere).

Is there a way inside an Action to get the full path name of the created temp dir?


Solution

  • withTempDir does not change the current directory. In general, changing the current directory (a global resource) in a multithreaded program is a very bad idea. The name of the temp directory is passed to the function given to withTempDir, so you can do:

    withTempDir $ \mydir -> do putNormal $ "Temp directory is " ++ mydir liftIO $ writeFile (mydir </> "test.txt") "writing out a temp file"

    I agree the docs for withTempDir are a bit lacking so have raised a bug to improve them.