-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-srpm
executable file
·56 lines (43 loc) · 1.65 KB
/
build-srpm
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
#!/usr/bin/python3
# SPDX-FileCopyrightText: Red Hat Inc
# SPDX-License-Identifier: LGPL-2.1-or-later
import datetime
import glob
import json
import os
import subprocess
def run(*args):
return subprocess.check_call(args)
def run_output(*args):
return subprocess.check_output(args).decode().strip()
with open("build/meson-info/intro-projectinfo.json") as f:
version = json.load(f)["version"]
# Get a human readable name of this commit:
# - build from tag: v2.4.5
# - build without a tag: v2.4.5-3-gc238eff
commit_name = run_output("git", "describe", "--tags", "--match", "v[0-9]*")
if "-" in commit_name:
# Build without a tag - make this build newer than previous build
# with a UTC timestamp, and add commit hash to make it easy to
# locate the commit.
utc_timestamp = datetime.datetime.utcnow().strftime("%Y%m%d%H%M")
commit_hash = run_output("git", "rev-parse", "--short", "HEAD")
release = f"0.{utc_timestamp}.git{commit_hash}"
else:
# Build from tag - make this build newer than previous builds
# without a tag.
release = "1"
rpm_dir = os.path.abspath("build/rpm")
sources_dir = os.path.join(rpm_dir, "SOURCES")
run("rm", "-rf", "build/meson-dist")
run("meson", "dist", "--no-tests", "--include-subprojects", "-C", "build")
run("rm", "-rf", rpm_dir)
os.makedirs(sources_dir)
run("mv", f"build/meson-dist/blkhash-{version}.tar.xz", sources_dir)
with open("blkhash.spec.in") as f:
spec = f.read()
spec = spec.replace("@VERSION@", version)
spec = spec.replace("@RELEASE@", release)
with open("build/blkhash.spec", "w") as f:
f.write(spec)
run("rpmbuild", "-bs", f"--define=_topdir {rpm_dir}", "build/blkhash.spec")