Skip to content

Commit 75dc71b

Browse files
authored
Merge pull request #2118 from actonlang/actonc-tempdir
Reintroduce --tempdir
2 parents 8db4449 + 2383a44 commit 75dc71b

38 files changed

Lines changed: 67 additions & 60 deletions

compiler/actonc/Main.hs

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -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
632642
compileBins 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

877885
handleCleanup 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

compiler/actonc/test/syntaxerrors/err1.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Building file test/syntaxerrors/err1.act
1+
Building file test/syntaxerrors/err1.act using temporary scratch directory
22

33
ERROR: Error when compiling err1 module: Syntax error
44

compiler/actonc/test/syntaxerrors/err2.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Building file test/syntaxerrors/err2.act
1+
Building file test/syntaxerrors/err2.act using temporary scratch directory
22

33
ERROR: Error when compiling err2 module: Context error
44

compiler/actonc/test/syntaxerrors/err3.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Building file test/syntaxerrors/err3.act
1+
Building file test/syntaxerrors/err3.act using temporary scratch directory
22

33
ERROR: Error when compiling err3 module: Syntax error
44

compiler/actonc/test/syntaxerrors/err4.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Building file test/syntaxerrors/err4.act
1+
Building file test/syntaxerrors/err4.act using temporary scratch directory
22

33
ERROR: Error when compiling err4 module: Syntax error
44

compiler/actonc/test/syntaxerrors/err5.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Building file test/syntaxerrors/err5.act
1+
Building file test/syntaxerrors/err5.act using temporary scratch directory
22

33
ERROR: Error when compiling err5 module: Syntax error
44

compiler/actonc/test/syntaxerrors/err6.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Building file test/syntaxerrors/err6.act
1+
Building file test/syntaxerrors/err6.act using temporary scratch directory
22

33
ERROR: Error when compiling err6 module: Syntax error
44

compiler/actonc/test/syntaxerrors/err7.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Building file test/syntaxerrors/err7.act
1+
Building file test/syntaxerrors/err7.act using temporary scratch directory
22

33
ERROR: Error when compiling err7 module: Syntax error
44

compiler/actonc/test/syntaxerrors/err8.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Building file test/syntaxerrors/err8.act
1+
Building file test/syntaxerrors/err8.act using temporary scratch directory
22

33
ERROR: Error when compiling err8 module: Indentation error
44
|

compiler/actonc/test/syntaxerrors/err9.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Building file test/syntaxerrors/err9.act
1+
Building file test/syntaxerrors/err9.act using temporary scratch directory
22

33
ERROR: Error when compiling err9 module: Syntax error
44

0 commit comments

Comments
 (0)