Skip to content

Commit

Permalink
version.py: fix build date
Browse files Browse the repository at this point in the history
- Use ctime() instead manual format string. Fixes 12-hour format (%I)
  without AM/PM (%p) specified. It is 24-hours now, as it should be.
- Avoid naive datetime object.
- Fix timestamp type, it is float in Python.
- Remove dummy fallback branch.
- Use f-strings for readability.
- Always rebuild version.h if repository is dirty.
  • Loading branch information
kasper93 authored and Dudemanguy committed Jul 30, 2023
1 parent a2dd78f commit 13b7d77
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions version.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,18 @@
print(version)
sys.exit()

date = datetime.utcfromtimestamp(int(os.environ.get('SOURCE_DATE_EPOCH', time.time())))
if date == "":
date = datetime.now(timezone.utc).astimezone()
date_str = date.strftime("%a %b %d %I:%M:%S %Y")
ts = float(os.environ.get('SOURCE_DATE_EPOCH', time.time()))
date = datetime.fromtimestamp(ts, timezone.utc)

NEW_REVISION = "#define VERSION \"" + version + "\"\n"
OLD_REVISION = ""
BUILDDATE = "#define BUILDDATE \"" + date_str + "\"\n"
MPVCOPYRIGHT = "#define MPVCOPYRIGHT \"Copyright \u00A9 2000-2023 mpv/MPlayer/mplayer2 projects\"" + "\n"
NEW_REVISION = f'#define VERSION "{version}"'
BUILDDATE = f'#define BUILDDATE "{date.ctime()}"'
MPVCOPYRIGHT = f'#define MPVCOPYRIGHT "Copyright © 2000-2023 mpv/MPlayer/mplayer2 projects"'

if os.path.isfile(sys.argv[1]):
with open(sys.argv[1], "r") as f:
OLD_REVISION = f.readline()
OLD_REVISION = f.readline().strip()

if NEW_REVISION != OLD_REVISION:
if NEW_REVISION != OLD_REVISION or NEW_REVISION.endswith('dirty"'):
with open(sys.argv[1], "w", encoding="utf-8") as f:
f.writelines([NEW_REVISION, BUILDDATE, MPVCOPYRIGHT])

f.writelines(f"{l}{os.linesep}" for l in [NEW_REVISION, BUILDDATE, MPVCOPYRIGHT])

0 comments on commit 13b7d77

Please sign in to comment.