Blame SOURCES/ghc-Debian-reproducible-tmp-names.patch

a43873
This is an attempt to make GHC build reproducible. The name of .c files may end
a43873
up in the resulting binary (in the debug section), but not the directory.
a43873
a43873
Instead of using the process id, create a hash from the command line arguments,
a43873
and assume that is going to be unique.
a43873
a43873
Index: ghc-8.0.2/compiler/main/SysTools.hs
a43873
===================================================================
a43873
--- ghc-8.0.2.orig/compiler/main/SysTools.hs
a43873
+++ ghc-8.0.2/compiler/main/SysTools.hs
a43873
@@ -65,6 +65,7 @@
a43873
 import Util
a43873
 import DynFlags
a43873
 import Exception
a43873
+import Fingerprint
a43873
 
a43873
 import LlvmCodeGen.Base (llvmVersionStr, supportedLlvmVersion)
a43873
 
a43873
@@ -1145,8 +1146,8 @@
a43873
     mapping <- readIORef dir_ref
a43873
     case Map.lookup tmp_dir mapping of
a43873
         Nothing -> do
a43873
-            pid <- getProcessID
a43873
-            let prefix = tmp_dir  "ghc" ++ show pid ++ "_"
a43873
+            pid <- getStableProcessID
a43873
+            let prefix = tmp_dir  "ghc" ++ pid ++ "_"
a43873
             mask_ $ mkTempDir prefix
a43873
         Just dir -> return dir
a43873
   where
a43873
@@ -1562,6 +1563,13 @@
a43873
 getProcessID = System.Posix.Internals.c_getpid >>= return . fromIntegral
a43873
 #endif
a43873
 
a43873
+-- Debian-specific hack to get reproducible output, by not using the "random"
a43873
+-- pid, but rather something determinisic
a43873
+getStableProcessID :: IO String
a43873
+getStableProcessID = do
a43873
+    args <- getArgs
a43873
+    return $ take 4 $ show $ fingerprintString $ unwords args
a43873
+
a43873
 -- Divvy up text stream into lines, taking platform dependent
a43873
 -- line termination into account.
a43873
 linesPlatform :: String -> [String]