reproducible-tmp-names
authorDebian Haskell Group <pkg-haskell-maintainers@lists.alioth.debian.org>
Mon, 25 Jun 2018 09:24:52 +0000 (10:24 +0100)
committerIlias Tsitsimpis <iliastsi@debian.org>
Mon, 25 Jun 2018 09:24:52 +0000 (10:24 +0100)
This is an attempt to make GHC build reproducible. The name of .c files may end
up in the resulting binary (in the debug section), but not the directory.

Instead of using the process id, create a hash from the command line arguments,
and assume that is going to be unique.

Gbp-Pq: Name reproducible-tmp-names

compiler/main/SysTools.hs

index b2d85a782a95e8ccccf9a1dfde9923c7201266da..a24d009a097076526b10829eca88dc4cf1036167 100644 (file)
@@ -68,6 +68,7 @@ import Platform
 import Util
 import DynFlags
 import Exception
+import Fingerprint
 
 import LlvmCodeGen.Base (llvmVersionStr, supportedLlvmVersion)
 
@@ -1121,8 +1122,8 @@ getTempDir dflags = do
     mapping <- readIORef dir_ref
     case Map.lookup tmp_dir mapping of
         Nothing -> do
-            pid <- getProcessID
-            let prefix = tmp_dir </> "ghc" ++ show pid ++ "_"
+            pid <- getStableProcessID
+            let prefix = tmp_dir </> "ghc" ++ pid ++ "_"
             mask_ $ mkTempDir prefix
         Just dir -> return dir
   where
@@ -1558,6 +1559,13 @@ getProcessID :: IO Int
 getProcessID = System.Posix.Internals.c_getpid >>= return . fromIntegral
 #endif
 
+-- Debian-specific hack to get reproducible output, by not using the "random"
+-- pid, but rather something determinisic
+getStableProcessID :: IO String
+getStableProcessID = do
+    args <- getArgs
+    return $ take 4 $ show $ fingerprintString $ unwords args
+
 -- Divvy up text stream into lines, taking platform dependent
 -- line termination into account.
 linesPlatform :: String -> [String]