summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhallgren <hallgren@chalmers.se>2015-05-05 13:51:35 +0000
committerhallgren <hallgren@chalmers.se>2015-05-05 13:51:35 +0000
commitb0e8a49b9aa0764a83bfe88afc55fd29eb915f9e (patch)
tree134dde222cbd775d8d901b430f1e04362b273b21 /src
parent3649412ce26bdbc0ff078350ce0b037cd3774338 (diff)
GF.CompileOne: use random numbers to avoid temporary file name clashes
When using make -j to compile examples/app or examples/phrasebook, since the dependencies are not completely specified in the Makefiles, it can happen that the same file is compiled at the same by more than one process, resulting in an error when they try to write the same .gfo.tmp file. Adding a random number to the temporary file name avoids this problem.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/GF/CompileOne.hs6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/compiler/GF/CompileOne.hs b/src/compiler/GF/CompileOne.hs
index 8443ec932..318d0d3a3 100644
--- a/src/compiler/GF/CompileOne.hs
+++ b/src/compiler/GF/CompileOne.hs
@@ -25,6 +25,7 @@ import GF.Data.Operations(ErrorMonad,liftErr,(+++),done)
import GF.System.Directory(doesFileExist,getCurrentDirectory,renameFile)
import System.FilePath(makeRelative)
+import System.Random(randomIO)
import qualified Data.Map as Map
import GF.Text.Pretty(render,(<+>),($$)) --Doc,
import GF.System.Console(TermColors(..),getTermColors)
@@ -142,11 +143,12 @@ compileSourceModule opts cwd mb_gfFile gr =
--writeGFO :: Options -> InitPath -> FilePath -> SourceModule -> IOE ()
writeGFO opts cwd file mo =
putPointE Normal opts (" write file" +++ rfile) $
- do encodeModule tmp mo2
+ do n <- liftIO randomIO --avoid name clashes when compiling with 'make -j'
+ let tmp = file++".tmp" ++show (n::Int)
+ encodeModule tmp mo2
renameFile tmp file
where
rfile = makeRelative cwd file
- tmp = file++".tmp"
mo2 = (m,mi{jments=Map.filter notAnyInd (jments mi)})
(m,mi) = subexpModule mo