1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
From: Agathe Porte <gagath@debian.org>
Date: Mon, 10 Mar 2025 18:06:05 +0100
Subject: scripts/GenerateNLVersion.kt: use SOURCE_DATE_EPOCH for reproducible
builds
Forwarded: https://github.com/JetBrains/JetBrainsMono/pull/720
---
scripts/GenerateNLVersion.kt | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/scripts/GenerateNLVersion.kt b/scripts/GenerateNLVersion.kt
index e3a4fea..4efcbc9 100644
--- a/scripts/GenerateNLVersion.kt
+++ b/scripts/GenerateNLVersion.kt
@@ -4,6 +4,9 @@ import org.w3c.dom.Node
import org.w3c.dom.NodeList
import java.io.File
import java.io.FileOutputStream
+import java.nio.file.Files
+import java.nio.file.attribute.FileTime
+import java.time.Instant
import java.util.concurrent.TimeUnit
import javax.xml.parsers.DocumentBuilderFactory
import javax.xml.transform.TransformerFactory
@@ -68,10 +71,31 @@ fun generateNoLigaturesFont(file: File, doc: Document) {
val ttxFile = File(dir, ttx)
doc.saveAs(ttxFile)
+
+ makeReproducible(dir)
+
"ttx $ttx".runCommand(dir)
ttxFile.deleteAndLog()
}
+fun makeReproducible(dir: File) {
+ val epochString = System.getenv("SOURCE_DATE_EPOCH") ?: return
+ val epochSeconds = epochString.toLongOrNull() ?: return
+ val timestamp = FileTime.from(Instant.ofEpochSecond(epochSeconds))
+
+ if (!dir.isDirectory) return
+
+ dir.walkTopDown()
+ .filter { it.isFile }
+ .forEach { file ->
+ try {
+ Files.setLastModifiedTime(file.toPath(), timestamp)
+ } catch (e: Exception) {
+ println("Failed to update ${file.path}: ${e.message}")
+ }
+ }
+}
+
class NodeListWrapper(val nodeList: NodeList) : AbstractList<Node>(), RandomAccess {
override val size: Int
get() = nodeList.length
|