|
10 | 10 | import os
|
11 | 11 | import shlex
|
12 | 12 | import shutil
|
| 13 | +import subprocess |
13 | 14 | import sys
|
| 15 | +from datetime import datetime, timezone |
14 | 16 | from io import StringIO
|
15 | 17 | from os.path import dirname, exists, isdir, join, lexists, relpath
|
16 | 18 |
|
@@ -168,8 +170,40 @@ def deckdebuild(
|
168 | 170 | build_cmd = f"cd {shlex.quote(source_dir)};"
|
169 | 171 |
|
170 | 172 | 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)} " |
173 | 207 |
|
174 | 208 | if build_source:
|
175 | 209 | build_cmd += (
|
|
0 commit comments