From: Dirk Eddelbuettel <edd@debian.org>
Date: Oct, 14 2026 21:00:00 -0500
Subject: [PATCH] Make sourceEnvironment class prototype deterministic (reproducible builds)

The 'sourceEnvironment' S4 class prototype embeds 'Sys.time()', which stamps the
wall-clock build time into the methods package's R/methods.rdb (and hence .rdx)
during 'loadNamespace("methods")' at build time.  Prefer the value of
SOURCE_DATE_EPOCH when set (as done for reproducible builds), falling back to
Sys.time() otherwise so upstream behaviour is preserved when it is not set.

--- r-base-4.6.1.orig/src/library/methods/R/trace.R
+++ r-base-4.6.1/src/library/methods/R/trace.R
@@ -461,6 +461,14 @@
 
 
 .InitTraceFunctions <- function(envir)  {
+    ## Reproducible builds: stamp the class prototype with the value of
+    ## SOURCE_DATE_EPOCH when set (as done for reproducible builds), falling
+    ## back to the wall-clock Sys.time() otherwise (upstream behaviour).
+    .dateCreated <- local({
+        t <- Sys.getenv("SOURCE_DATE_EPOCH")
+        if (nzchar(t)) as.POSIXct(as.numeric(t), origin = "1970-01-01", tz = "UTC")
+        else Sys.time()
+    })
     setClass("traceable", representation(original = "PossibleMethod", source = "environment"), contains = "VIRTUAL",
              where = envir); clList <- "traceable"
     ## create the traceable classes
@@ -472,7 +480,7 @@
     }
     setClass("sourceEnvironment", contains = "environment",
              representation(packageName = "character", dateCreated = "POSIXt", sourceFile = "character"),
-             prototype = prototype( packageName = "", dateCreated = Sys.time(), sourceFile = ""))
+             prototype = prototype( packageName = "", dateCreated = .dateCreated, sourceFile = ""))
     clList <- c(clList, "sourceEnvironment")
     assign(".SealedClasses", c(get(".SealedClasses", envir), clList), envir)
     setMethod("initialize", "traceable",
