7373import logging
7474import os
7575import pathlib
76+ import re
7677import shlex
7778import shutil
7879import subprocess
@@ -179,6 +180,8 @@ def _container_cmd(ctx, args, *, workdir=None, interactive=False):
179180 cmd .append ("--pids-limit=-1" )
180181 if ctx .map_user :
181182 cmd .append ("--user=0" )
183+ if ctx .cli .env_file :
184+ cmd .append (f"--env-file={ ctx .cli .env_file .absolute ()} " )
182185 if workdir :
183186 cmd .append (f"--workdir={ workdir } " )
184187 cwd = pathlib .Path ("." ).absolute ()
@@ -580,12 +583,15 @@ def bc_run_tests(ctx):
580583def bc_make_source_rpm (ctx ):
581584 """Build SPRMs."""
582585 ctx .build .wants (Steps .CONTAINER , ctx )
586+ make_srpm_cmd = f"cd { ctx .cli .homedir } && ./make-srpm.sh"
587+ if ctx .cli .ceph_version :
588+ make_srpm_cmd = f"{ make_srpm_cmd } { ctx .cli .ceph_version } "
583589 cmd = _container_cmd (
584590 ctx ,
585591 [
586592 "bash" ,
587593 "-c" ,
588- f"cd { ctx . cli . homedir } && ./make-srpm.sh" ,
594+ make_srpm_cmd ,
589595 ],
590596 )
591597 with ctx .user_command ():
@@ -597,8 +603,21 @@ def bc_build_rpm(ctx):
597603 """Build RPMs from SRPM."""
598604 srpm_glob = "ceph*.src.rpm"
599605 if ctx .cli .rpm_match_sha :
600- head_sha = _git_current_sha (ctx )
601- srpm_glob = f"ceph*.g{ head_sha } .*.src.rpm"
606+ if not ctx .cli .ceph_version :
607+ head_sha = _git_current_sha (ctx )
608+ srpm_glob = f"ceph*.g{ head_sha } .*.src.rpm"
609+ else :
610+ # Given a tarball with a name like
611+ # ceph-19.3.0-7462-g565e5c65.tar.bz2
612+ # The SRPM name would be:
613+ # ceph-19.3.0-7462.g565e5c65.el9.src.rpm
614+ # This regex replaces the second '-' with a '.'
615+ srpm_version = re .sub (
616+ r"(\d+\.\d+\.\d+-\d+)-(.*)" ,
617+ r"\1.\2" ,
618+ ctx .cli .ceph_version
619+ )
620+ srpm_glob = f"ceph-{ srpm_version } .*.src.rpm"
602621 paths = glob .glob (srpm_glob )
603622 if len (paths ) > 1 :
604623 raise RuntimeError (
@@ -617,12 +636,18 @@ def bc_build_rpm(ctx):
617636 topdir = (
618637 pathlib .Path (ctx .cli .homedir ) / ctx .cli .build_dir / "rpmbuild"
619638 )
639+ rpmbuild_args = [
640+ 'rpmbuild' ,
641+ '--rebuild' ,
642+ f'-D_topdir { topdir } ' ,
643+ ] + list (ctx .cli .rpmbuild_arg ) + [str (srpm_path )]
644+ rpmbuild_cmd = ' ' .join (shlex .quote (cmd ) for cmd in rpmbuild_args )
620645 cmd = _container_cmd (
621646 ctx ,
622647 [
623648 "bash" ,
624649 "-c" ,
625- f"set -x; mkdir -p { topdir } && rpmbuild --rebuild -D'_topdir { topdir } ' { srpm_path } " ,
650+ f"set -x; mkdir -p { topdir } && { rpmbuild_cmd } " ,
626651 ],
627652 )
628653 with ctx .user_command ():
@@ -836,6 +861,16 @@ def parse_cli(build_step_names):
836861 " git checkout. Use any source RPM available."
837862 ),
838863 )
864+ parser .add_argument (
865+ "--rpmbuild-arg" ,
866+ '-R' ,
867+ action = "append" ,
868+ help = "Pass this extra argument to rpmbuild" ,
869+ )
870+ parser .add_argument (
871+ "--ceph-version" ,
872+ help = "Rather than infer the Ceph version, use this value" ,
873+ )
839874 parser .add_argument (
840875 "--execute" ,
841876 "-e" ,
@@ -844,6 +879,11 @@ def parse_cli(build_step_names):
844879 choices = build_step_names ,
845880 help = "Execute the target build step(s)" ,
846881 )
882+ parser .add_argument (
883+ "--env-file" ,
884+ type = pathlib .Path ,
885+ help = "Use this environment file when building" ,
886+ )
847887 parser .add_argument (
848888 "--dry-run" ,
849889 action = "store_true" ,
0 commit comments