mergerfs/buildtools/build-release

198 lines
6.5 KiB
Text
Raw Normal View History

#!/usr/bin/env python3
import subprocess
import sys
import os
import argparse
import time
2025-08-29 08:51:05 -04:00
def build(git_repo,
branch,
containerfile,
pkgdirpath):
timestamp = time.time_ns()
args = ['podman',
'build',
'--pull=always',
2025-08-29 08:51:05 -04:00
'--force-rm']
if os.path.exists(git_repo):
git_repo = os.path.realpath(git_repo)
build: make NDEBUG=1 and make release build the release profile - The RELEASE=1 profile replaced 2.42.0's NDEBUG=1 one, but the static archives and the container image still build with NDEBUG=1, which therefore selected the debug profile: -O0 -g3 with assertions on. Both Makefiles accept NDEBUG=1 again, as -O3 -DNDEBUG, and the debug profile defines DEBUG. The vendored libfuse follows the same profile as mergerfs. - make release first removes the objects, binaries and stamp under build/ and cleans vendored/libfuse, because make only compares timestamps: objects from an earlier debug build were otherwise linked into the release binary unchanged. Packages and build reports in build/pkgs are kept; TEST_release_pkg_preservation checks both. - make release also builds preload.so. It takes the release defines through its own PRELOAD_CPPFLAGS: the global CPPFLAGS add _FILE_OFFSET_BITS=64, which would hide its unsuffixed open/openat/fopen/creat interposers. - mergerfs.spec builds the release target, as debian/rules does. The distribution's CFLAGS, CXXFLAGS and LDFLAGS still apply. - The release driver mounts the repository with ":ro,z", not ":ro:z", which Podman read as an extra field instead of a mount option. TEST_release_metadata runs the driver against a fake podman and checks the volume argument and the build report. - Remove release-installer: build-release has no installer target. - make help printed a literal "\n" where /bin/sh is bash. Match the build.md transcript to its output and document the profiles. Performance: static archives and the container image go from -O0 with assertions back to optimized builds, now -O3 -DNDEBUG (2.42.0: -O2 -DNDEBUG). RPM packages keep the distribution's -O2 and no longer evaluate assertions. A plain make is unoptimized, as before.
2026-11-29 23:10:53 -05:00
args += ['-v',f'{git_repo}:/tmp/mergerfs.git:ro,z']
args += ['--build-arg=GIT_REPO=file:///tmp/mergerfs.git']
2025-08-29 08:51:05 -04:00
else:
args += [f'--build-arg=GIT_REPO={git_repo}']
os.makedirs(pkgdirpath,exist_ok=True)
args += ['-v',f'{os.path.realpath(pkgdirpath)}:/pkgs:ro']
2025-08-29 08:51:05 -04:00
args += ['-o',pkgdirpath,
'-f',containerfile,
f'--build-arg=BRANCH={branch}',
f'--build-arg=BUILD_TIMESTAMP={timestamp}',
'buildtools/']
# TODO: Capture output and write to log
print(args)
build: make the release driver and Debian changelogs dependable - The container release driver wrote rv=fail but returned success to CI. Run every selected target, keep its report line, and exit nonzero if any target fails or its builder can't run. A missing podman during --cleanup is reported per target instead of aborting the run. Reject a target name that matches no containerfile. - --branch silently defaulted to master, and the tarball containerfile did too, so a release could package a moving branch instead of the intended tag. Require --branch and --git-repo for direct calls. - Remove the static installer target. Its makeself command printed "foo", and it copied whatever static archives the output directory held, possibly from an older release or missing one built later in the same run. The static archives themselves are unchanged. - git2debcl enumerated every tag and used symmetric differences, so a private tag could become a package version and commits from another branch could be listed. Take release and release-candidate tags reachable from the requested revision, ordered by version with each final after its candidates, with one-sided ranges between ancestor boundaries. Keep the requested version when tags share a revision or a range is empty. A tagless snapshot gets 0~git.<count>.<hash>; a shallow tagless checkout must give --version. - Debian versions for candidates are printed as 2.42.0~~rc1, so dpkg orders them below the 2.42.0 final. The raw -rc1 form sorted above it, making the final release look like a downgrade. - TEST_release_metadata covers the driver's results and arguments, sibling and merged histories, non-release tags, candidates, tagless and shallow checkouts, and dpkg version ordering. - Document the static and release targets and the driver's arguments.
2026-11-25 13:36:10 -05:00
try:
returncode = subprocess.run(args).returncode
except OSError as exc:
print(f"{args[0]}: {exc}",file=sys.stderr)
returncode = 127
report_filepath = os.path.join(pkgdirpath,"build-report.txt")
with open(report_filepath,"a+") as f:
build = os.path.basename(containerfile)
f.write(build + ": ")
f.write(f"branch={branch}; ")
f.write(f"timestamp={timestamp}; ")
f.write("rv=")
build: make the release driver and Debian changelogs dependable - The container release driver wrote rv=fail but returned success to CI. Run every selected target, keep its report line, and exit nonzero if any target fails or its builder can't run. A missing podman during --cleanup is reported per target instead of aborting the run. Reject a target name that matches no containerfile. - --branch silently defaulted to master, and the tarball containerfile did too, so a release could package a moving branch instead of the intended tag. Require --branch and --git-repo for direct calls. - Remove the static installer target. Its makeself command printed "foo", and it copied whatever static archives the output directory held, possibly from an older release or missing one built later in the same run. The static archives themselves are unchanged. - git2debcl enumerated every tag and used symmetric differences, so a private tag could become a package version and commits from another branch could be listed. Take release and release-candidate tags reachable from the requested revision, ordered by version with each final after its candidates, with one-sided ranges between ancestor boundaries. Keep the requested version when tags share a revision or a range is empty. A tagless snapshot gets 0~git.<count>.<hash>; a shallow tagless checkout must give --version. - Debian versions for candidates are printed as 2.42.0~~rc1, so dpkg orders them below the 2.42.0 final. The raw -rc1 form sorted above it, making the final release look like a downgrade. - TEST_release_metadata covers the driver's results and arguments, sibling and merged histories, non-release tags, candidates, tagless and shallow checkouts, and dpkg version ordering. - Document the static and release targets and the driver's arguments.
2026-11-25 13:36:10 -05:00
if returncode == 0:
f.write("success;")
else:
f.write("fail;")
f.write("\n")
build: make the release driver and Debian changelogs dependable - The container release driver wrote rv=fail but returned success to CI. Run every selected target, keep its report line, and exit nonzero if any target fails or its builder can't run. A missing podman during --cleanup is reported per target instead of aborting the run. Reject a target name that matches no containerfile. - --branch silently defaulted to master, and the tarball containerfile did too, so a release could package a moving branch instead of the intended tag. Require --branch and --git-repo for direct calls. - Remove the static installer target. Its makeself command printed "foo", and it copied whatever static archives the output directory held, possibly from an older release or missing one built later in the same run. The static archives themselves are unchanged. - git2debcl enumerated every tag and used symmetric differences, so a private tag could become a package version and commits from another branch could be listed. Take release and release-candidate tags reachable from the requested revision, ordered by version with each final after its candidates, with one-sided ranges between ancestor boundaries. Keep the requested version when tags share a revision or a range is empty. A tagless snapshot gets 0~git.<count>.<hash>; a shallow tagless checkout must give --version. - Debian versions for candidates are printed as 2.42.0~~rc1, so dpkg orders them below the 2.42.0 final. The raw -rc1 form sorted above it, making the final release look like a downgrade. - TEST_release_metadata covers the driver's results and arguments, sibling and merged histories, non-release tags, candidates, tagless and shallow checkouts, and dpkg version ordering. - Document the static and release targets and the driver's arguments.
2026-11-25 13:36:10 -05:00
return returncode
def setup():
2026-03-13 15:46:18 -05:00
# Detect distribution
if os.path.exists('/usr/bin/apt-get'):
args = ['sudo',
'apt-get',
'install',
'-fy',
'qemu-user-static',
'qemu-user-binfmt']
elif os.path.exists('/usr/bin/pacman'):
args = ['sudo',
'pacman',
'-Sy',
'--noconfirm',
'qemu-user-static']
else:
print("Unsupported distribution for setup")
sys.exit(1)
print(args)
subprocess.run(args)
setup_binfmt()
def setup_binfmt():
"""Register qemu-user-static binfmt handlers (needed on Arch, etc.)."""
binfmt_conf = """\
:qemu-aarch64:M::\\x7fELF\\x02\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\xb7\\x00:\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xfe\\xff\\xff\\xff:/usr/bin/qemu-aarch64-static:F
:qemu-arm:M::\\x7fELF\\x01\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\x28\\x00:\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xfe\\xff\\xff\\xff:/usr/bin/qemu-arm-static:F
:qemu-armeb:M::\\x7fELF\\x01\\x02\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\x28:\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xfe\\xff\\xff:/usr/bin/qemu-armeb-static:F
:qemu-riscv64:M::\\x7fELF\\x02\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\xf3\\x00:\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xfe\\xff\\xff\\xff:/usr/bin/qemu-riscv64-static:F
:qemu-i386:M::\\x7fELF\\x01\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\x03\\x00:\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xfe\\xff\\xff\\xff:/usr/bin/qemu-i386-static:F
"""
conf_path = '/etc/binfmt.d/qemu-static.conf'
print(f"Writing {conf_path}")
try:
with open(conf_path, 'w') as f:
f.write(binfmt_conf)
except PermissionError:
print(f"Permission denied writing {conf_path}; trying with sudo...")
subprocess.run(['sudo', 'tee', conf_path],
input=binfmt_conf.encode(), check=True)
print("Restarting systemd-binfmt...")
subprocess.run(['sudo', 'systemctl', 'restart', 'systemd-binfmt'])
def podman_cleanup():
args = ['podman',
'system',
'prune',
'-af']
print(args)
build: make the release driver and Debian changelogs dependable - The container release driver wrote rv=fail but returned success to CI. Run every selected target, keep its report line, and exit nonzero if any target fails or its builder can't run. A missing podman during --cleanup is reported per target instead of aborting the run. Reject a target name that matches no containerfile. - --branch silently defaulted to master, and the tarball containerfile did too, so a release could package a moving branch instead of the intended tag. Require --branch and --git-repo for direct calls. - Remove the static installer target. Its makeself command printed "foo", and it copied whatever static archives the output directory held, possibly from an older release or missing one built later in the same run. The static archives themselves are unchanged. - git2debcl enumerated every tag and used symmetric differences, so a private tag could become a package version and commits from another branch could be listed. Take release and release-candidate tags reachable from the requested revision, ordered by version with each final after its candidates, with one-sided ranges between ancestor boundaries. Keep the requested version when tags share a revision or a range is empty. A tagless snapshot gets 0~git.<count>.<hash>; a shallow tagless checkout must give --version. - Debian versions for candidates are printed as 2.42.0~~rc1, so dpkg orders them below the 2.42.0 final. The raw -rc1 form sorted above it, making the final release look like a downgrade. - TEST_release_metadata covers the driver's results and arguments, sibling and merged histories, non-release tags, candidates, tagless and shallow checkouts, and dpkg version ordering. - Document the static and release targets and the driver's arguments.
2026-11-25 13:36:10 -05:00
try:
subprocess.run(args)
except OSError as exc:
print(f"{args[0]}: {exc}",file=sys.stderr)
def parse_args():
p = argparse.ArgumentParser()
p.add_argument('--target',
2025-08-29 08:51:05 -04:00
default='debian:13.amd64')
p.add_argument('--pkgdirpath',
default='build/pkgs/')
p.add_argument('--branch',
build: make the release driver and Debian changelogs dependable - The container release driver wrote rv=fail but returned success to CI. Run every selected target, keep its report line, and exit nonzero if any target fails or its builder can't run. A missing podman during --cleanup is reported per target instead of aborting the run. Reject a target name that matches no containerfile. - --branch silently defaulted to master, and the tarball containerfile did too, so a release could package a moving branch instead of the intended tag. Require --branch and --git-repo for direct calls. - Remove the static installer target. Its makeself command printed "foo", and it copied whatever static archives the output directory held, possibly from an older release or missing one built later in the same run. The static archives themselves are unchanged. - git2debcl enumerated every tag and used symmetric differences, so a private tag could become a package version and commits from another branch could be listed. Take release and release-candidate tags reachable from the requested revision, ordered by version with each final after its candidates, with one-sided ranges between ancestor boundaries. Keep the requested version when tags share a revision or a range is empty. A tagless snapshot gets 0~git.<count>.<hash>; a shallow tagless checkout must give --version. - Debian versions for candidates are printed as 2.42.0~~rc1, so dpkg orders them below the 2.42.0 final. The raw -rc1 form sorted above it, making the final release look like a downgrade. - TEST_release_metadata covers the driver's results and arguments, sibling and merged histories, non-release tags, candidates, tagless and shallow checkouts, and dpkg version ordering. - Document the static and release targets and the driver's arguments.
2026-11-25 13:36:10 -05:00
required=False)
p.add_argument('--setup',
required=False,
action='store_true')
p.add_argument('--cleanup',
required=False,
action='store_true')
2025-08-29 08:51:05 -04:00
p.add_argument('--git-repo',
required=False,
2025-08-29 08:51:05 -04:00
type=str)
return p.parse_args()
def should_skip(filename):
if filename.endswith('~'):
return True
return False
def main():
args = parse_args()
print(args)
if args.setup:
setup()
sys.exit(0)
build: make the release driver and Debian changelogs dependable - The container release driver wrote rv=fail but returned success to CI. Run every selected target, keep its report line, and exit nonzero if any target fails or its builder can't run. A missing podman during --cleanup is reported per target instead of aborting the run. Reject a target name that matches no containerfile. - --branch silently defaulted to master, and the tarball containerfile did too, so a release could package a moving branch instead of the intended tag. Require --branch and --git-repo for direct calls. - Remove the static installer target. Its makeself command printed "foo", and it copied whatever static archives the output directory held, possibly from an older release or missing one built later in the same run. The static archives themselves are unchanged. - git2debcl enumerated every tag and used symmetric differences, so a private tag could become a package version and commits from another branch could be listed. Take release and release-candidate tags reachable from the requested revision, ordered by version with each final after its candidates, with one-sided ranges between ancestor boundaries. Keep the requested version when tags share a revision or a range is empty. A tagless snapshot gets 0~git.<count>.<hash>; a shallow tagless checkout must give --version. - Debian versions for candidates are printed as 2.42.0~~rc1, so dpkg orders them below the 2.42.0 final. The raw -rc1 form sorted above it, making the final release look like a downgrade. - TEST_release_metadata covers the driver's results and arguments, sibling and merged histories, non-release tags, candidates, tagless and shallow checkouts, and dpkg version ordering. - Document the static and release targets and the driver's arguments.
2026-11-25 13:36:10 -05:00
if not args.branch:
print("error: the following arguments are required: --branch")
sys.exit(1)
if not args.git_repo:
print("error: the following arguments are required: --git-repo")
sys.exit(1)
containerfiles = []
basepath = 'buildtools/containerfiles'
if os.path.exists(f'{basepath}/{args.target}'):
containerfiles.append(f'{basepath}/{args.target}')
elif args.target == 'all':
for root,dirnames,filenames in os.walk(basepath):
filenames.sort()
for filename in filenames:
if should_skip(filename):
continue
containerfile = f'buildtools/containerfiles/{filename}'
containerfiles.append(containerfile)
else:
for root,dirnames,filenames in os.walk(basepath):
filenames.sort()
for filename in filenames:
if args.target not in filename:
continue
if should_skip(filename):
continue
containerfile = f'buildtools/containerfiles/{filename}'
containerfiles.append(containerfile)
build: make the release driver and Debian changelogs dependable - The container release driver wrote rv=fail but returned success to CI. Run every selected target, keep its report line, and exit nonzero if any target fails or its builder can't run. A missing podman during --cleanup is reported per target instead of aborting the run. Reject a target name that matches no containerfile. - --branch silently defaulted to master, and the tarball containerfile did too, so a release could package a moving branch instead of the intended tag. Require --branch and --git-repo for direct calls. - Remove the static installer target. Its makeself command printed "foo", and it copied whatever static archives the output directory held, possibly from an older release or missing one built later in the same run. The static archives themselves are unchanged. - git2debcl enumerated every tag and used symmetric differences, so a private tag could become a package version and commits from another branch could be listed. Take release and release-candidate tags reachable from the requested revision, ordered by version with each final after its candidates, with one-sided ranges between ancestor boundaries. Keep the requested version when tags share a revision or a range is empty. A tagless snapshot gets 0~git.<count>.<hash>; a shallow tagless checkout must give --version. - Debian versions for candidates are printed as 2.42.0~~rc1, so dpkg orders them below the 2.42.0 final. The raw -rc1 form sorted above it, making the final release look like a downgrade. - TEST_release_metadata covers the driver's results and arguments, sibling and merged histories, non-release tags, candidates, tagless and shallow checkouts, and dpkg version ordering. - Document the static and release targets and the driver's arguments.
2026-11-25 13:36:10 -05:00
if not containerfiles:
sys.exit(f"no package targets match {args.target!r}")
failed = False
for containerfile in containerfiles:
if args.cleanup:
podman_cleanup()
build: make the release driver and Debian changelogs dependable - The container release driver wrote rv=fail but returned success to CI. Run every selected target, keep its report line, and exit nonzero if any target fails or its builder can't run. A missing podman during --cleanup is reported per target instead of aborting the run. Reject a target name that matches no containerfile. - --branch silently defaulted to master, and the tarball containerfile did too, so a release could package a moving branch instead of the intended tag. Require --branch and --git-repo for direct calls. - Remove the static installer target. Its makeself command printed "foo", and it copied whatever static archives the output directory held, possibly from an older release or missing one built later in the same run. The static archives themselves are unchanged. - git2debcl enumerated every tag and used symmetric differences, so a private tag could become a package version and commits from another branch could be listed. Take release and release-candidate tags reachable from the requested revision, ordered by version with each final after its candidates, with one-sided ranges between ancestor boundaries. Keep the requested version when tags share a revision or a range is empty. A tagless snapshot gets 0~git.<count>.<hash>; a shallow tagless checkout must give --version. - Debian versions for candidates are printed as 2.42.0~~rc1, so dpkg orders them below the 2.42.0 final. The raw -rc1 form sorted above it, making the final release look like a downgrade. - TEST_release_metadata covers the driver's results and arguments, sibling and merged histories, non-release tags, candidates, tagless and shallow checkouts, and dpkg version ordering. - Document the static and release targets and the driver's arguments.
2026-11-25 13:36:10 -05:00
rv = build(git_repo=args.git_repo,
branch=args.branch,
containerfile=containerfile,
pkgdirpath=args.pkgdirpath)
if rv != 0:
failed = True
sys.exit(1 if failed else 0)
if __name__ == '__main__':
main()