1
0

build.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #! /bin/env python
  2. from __future__ import print_function
  3. import argparse
  4. import os
  5. import sys
  6. import tarfile
  7. from os.path import abspath, dirname, join
  8. from shutil import copy
  9. from subprocess import check_call
  10. parser = argparse.ArgumentParser(description="Build salt rpms",)
  11. parser.add_argument(
  12. "buildid",
  13. help="The build id to use i.e. the bit after the salt version in the package name",
  14. )
  15. args = parser.parse_args()
  16. src = abspath(join(dirname(__file__), "../.."))
  17. sys.path.append(src)
  18. import salt.version # isort:skip
  19. salt_version = salt.version.__saltstack_version__.string
  20. rpmbuild = join(os.environ["HOME"], "rpmbuild")
  21. copy(join(src, "pkg/rpm/salt.spec"), join(rpmbuild, "SPECS"))
  22. for f in os.listdir(join(src, "pkg/rpm")):
  23. if f in ["salt.spec", "build.py"]:
  24. continue
  25. copy(join(src, "pkg/rpm", f), join(rpmbuild, "SOURCES"))
  26. def srcfilter(ti):
  27. if "/.git" in ti.name:
  28. return None
  29. return ti
  30. with tarfile.open(
  31. join(rpmbuild, "SOURCES/salt-%s.tar.gz" % salt_version), "w|gz"
  32. ) as tf:
  33. tf.add(src, arcname="salt-%s" % salt_version, filter=srcfilter)
  34. cmd = [
  35. "rpmbuild",
  36. "-bb",
  37. "--define=salt_version %s" % salt_version,
  38. "--define=buildid %s" % args.buildid,
  39. "salt.spec",
  40. ]
  41. print("Executing: %s" % " ".join('"%s"' % c for c in cmd))
  42. check_call(cmd, cwd=join(rpmbuild, "SPECS"))