@@ -305,19 +305,30 @@ buildFile opts file = do
305305 withFileLock lock_file Exclusive $ \ _ -> do
306306 compileFiles opts [file]
307307 Nothing -> do
308- iff (not (quiet opts)) $ do
309- putStrLn (" Building file " ++ file)
310- -- Not in a project, use scratch directory for compilation
311- home <- getHomeDirectory
312- let basePath = joinPath [home, " .cache" , " acton" , " scratch" ]
313- createDirectoryIfMissing True basePath
314- maybeLockInfo <- findAvailableScratch basePath
315- case maybeLockInfo of
316- Nothing -> error " Could not acquire any scratch directory lock"
317- Just (lock, lockPath) -> do
318- let scratchDir = dropExtension lockPath
319- compileFiles (opts { C. tempdir = scratchDir }) [file]
320- unlockFile lock
308+ -- Not in a project, use scratch directory for compilation unless
309+ -- --tempdir is provided - then use that
310+ if (C. tempdir opts /= " " )
311+ then do
312+ iff (not (quiet opts)) $ do
313+ putStrLn (" Building file " ++ file ++ " using temporary directory " ++ C. tempdir opts)
314+ compileFiles opts [file]
315+ else do
316+ iff (not (quiet opts)) $ do
317+ putStrLn (" Building file " ++ file ++ " using temporary scratch directory" )
318+ home <- getHomeDirectory
319+ let basePath = joinPath [home, " .cache" , " acton" , " scratch" ]
320+ createDirectoryIfMissing True basePath
321+ maybeLockInfo <- findAvailableScratch basePath
322+ case maybeLockInfo of
323+ Nothing -> error " Could not acquire any scratch directory lock"
324+ Just (lock, lockPath) -> do
325+ let scratchDir = dropExtension lockPath
326+ removeDirectoryRecursive scratchDir `catch` handleNotExists
327+ compileFiles (opts { C. tempdir = scratchDir }) [file]
328+ unlockFile lock
329+ where
330+ handleNotExists :: IOException -> IO ()
331+ handleNotExists _ = return ()
321332
322333-- Print documentation -------------------------------------------------------------------------------------------
323334
@@ -453,7 +464,6 @@ data Paths = Paths {
453464 binDir :: FilePath ,
454465 srcDir :: FilePath ,
455466 isTmp :: Bool ,
456- rmTmp :: Bool ,
457467 fileExt :: String ,
458468 modName :: A. ModName
459469 }
@@ -502,7 +512,7 @@ findPaths actFile opts = do execDir <- takeDirectory <$> System.Environment.get
502512 sysPath <- canonicalizePath (if null $ C. syspath opts then execDir ++ " /.." else C. syspath opts)
503513 let sysLib = joinPath [sysPath, " lib/" ++ if (C. dev opts) then " dev" else " rel" ]
504514 absSrcFile <- canonicalizePath actFile
505- (isTmp, rmTmp, projPath, dirInSrc) <- analyze (takeDirectory absSrcFile) []
515+ (isTmp, projPath, dirInSrc) <- analyze (takeDirectory absSrcFile) []
506516 let sysTypes = joinPath [sysPath, " base" , " out" , " types" ]
507517 srcDir = if isTmp then takeDirectory absSrcFile else joinPath [projPath, " src" ]
508518 projOut = joinPath [projPath, " out" ]
@@ -518,18 +528,18 @@ findPaths actFile opts = do execDir <- takeDirectory <$> System.Environment.get
518528 createDirectoryIfMissing True projTypes
519529 createDirectoryIfMissing True projLib
520530 createDirectoryIfMissing True (getModPath projTypes modName)
521- return $ Paths sPaths sysPath sysTypes sysLib projPath projOut projTypes projLib binDir srcDir isTmp rmTmp fileExt modName
531+ return $ Paths sPaths sysPath sysTypes sysLib projPath projOut projTypes projLib binDir srcDir isTmp fileExt modName
522532 where (fileBody,fileExt) = splitExtension $ takeFileName actFile
523533
524534 analyze " /" ds = do tmp <- canonicalizePath (C. tempdir opts)
525- return (True , True , tmp, [] )
535+ return (True , tmp, [] )
526536 analyze pre ds = do exists <- doesFileExist (joinPath [pre, " Acton.toml" ])
527537 if not exists
528538 then analyze (takeDirectory pre) (takeFileName pre : ds)
529539 else case ds of
530- [] -> return $ (False , False , pre, [] )
531- " src" : dirs -> return $ (False , False , pre, dirs)
532- " out" : " types" : dirs -> return $ (False , False , pre, dirs)
540+ [] -> return $ (False , pre, [] )
541+ " src" : dirs -> return $ (False , pre, dirs)
542+ " out" : " types" : dirs -> return $ (False , pre, dirs)
533543 _ -> error (" ************* Source file is not in a valid project directory: " ++ joinPath ds)
534544
535545
@@ -632,8 +642,6 @@ compileBins:: C.CompileOptions -> Paths -> Acton.Env.Env0 -> [CompileTask] -> [B
632642compileBins opts paths env tasks binTasks = do
633643 iff (not (altOutput opts)) $ do
634644 zigBuild env opts paths tasks binTasks
635- when (rmTmp paths) $ removeDirectoryRecursive (projPath paths)
636- `catch` handleNotExists
637645 return ()
638646 where
639647 handleNotExists :: IOException -> IO ()
@@ -876,7 +884,6 @@ handleTypeError opts errKind f src paths mn ex = do
876884
877885handleCleanup paths mn = do
878886 removeIfExists (outbase++ " .ty" )
879- when (rmTmp paths) $ removeDirectoryRecursive (projPath paths)
880887 System.Exit. exitFailure
881888 where outbase = outBase paths mn
882889 removeIfExists f = removeFile f `catch` handleNotExists
0 commit comments