Skip to content

Commit a421fb0

Browse files
committed
get reliable timestamp for faketime
1 parent 287caf8 commit a421fb0

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

libdeckdebuild/__init__.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
import os
1111
import shlex
1212
import shutil
13+
import subprocess
1314
import sys
15+
from datetime import datetime, timezone
1416
from io import StringIO
1517
from os.path import dirname, exists, isdir, join, lexists, relpath
1618

@@ -168,8 +170,40 @@ def deckdebuild(
168170
build_cmd = f"cd {shlex.quote(source_dir)};"
169171

170172
if faketime:
171-
faketime_fmt = debsource.get_mtime(path).strftime("%Y-%m-%d %H:%M:%S")
172-
build_cmd += f"faketime -f {shlex.quote(faketime_fmt)} "
173+
dt_format = "%Y-%m-%d %H:%M:%S"
174+
print("getting timestamp to use with faketime")
175+
# set a timestamp for use with faketime
176+
git_dir = join(chr_source_dir, ".git")
177+
if isdir(git_dir):
178+
# if source is a git repo, use the real mtime of the
179+
# 'debian/control' file via git log - the rationale is:
180+
# - TKL pkg changelog is dynamically generated so last changelog
181+
# date is not reproducable
182+
# - filesystem mtime of git controlled files is also not
183+
# reproducable
184+
get_time_cmd = [
185+
"/usr/bin/git",
186+
f"--git-dir={git_dir}",
187+
"log",
188+
"-1",
189+
"--format=%ad",
190+
"--date=iso",
191+
"--",
192+
"debian/control",
193+
]
194+
iso_timestamp = subprocess.run(
195+
get_time_cmd, capture_output=True, text=True
196+
).stdout.strip()
197+
fake_dt = (
198+
datetime.fromisoformat(iso_timestamp)
199+
.astimezone(timezone.utc)
200+
.strftime(dt_format)
201+
)
202+
else:
203+
# fallback to using the last changelog entry date
204+
fake_dt = debsource.get_mtime(path).strftime(dt_format)
205+
print(f"using timestamp {fake_dt}")
206+
build_cmd += f"faketime -f {shlex.quote(fake_dt)} "
173207

174208
if build_source:
175209
build_cmd += (

0 commit comments

Comments
 (0)