Skip to content

Commit 18e9063

Browse files
committed
New subcommand 'container builddep'
This just downloads the build dependencies that would be installed, with the intent to use this as a cache in a later commit. Signed-off-by: Yann Dirson <[email protected]>
1 parent 102f2fa commit 18e9063

File tree

2 files changed

+61
-20
lines changed

2 files changed

+61
-20
lines changed

container/files/init-container.sh

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,12 @@ ulimit -s 16384
6969
# get the package arch used in the container (eg. "x86_64_v2")
7070
RPMARCH=$(rpm -q glibc --qf "%{arch}")
7171

72-
if [ -n "$BUILD_LOCAL" ]; then
72+
if [ -n "$BUILD_LOCAL$BUILD_DEPS" ]; then
7373
time (
7474
cd ~/rpmbuild
75-
rm BUILD BUILDROOT RPMS SRPMS -rf
75+
if [ -n "$BUILD_LOCAL" ]; then
76+
rm BUILD BUILDROOT RPMS SRPMS -rf
77+
fi
7678

7779
if specs=$(ls *.spec 2>/dev/null); then
7880
SPECFLAGS=(
@@ -88,28 +90,40 @@ if [ -n "$BUILD_LOCAL" ]; then
8890

8991
case "$OS_RELEASE" in
9092
8.2.*|8.3.*) ;; # sources always available via git-lfs
91-
8.99.*|9.*) if [ -r sources ]; then alma_get_sources -i sources; fi ;;
93+
8.99.*|9.*)
94+
if [ -r sources ]; then alma_get_sources -i sources; fi
95+
# FIXME: if [ -n "$BUILD_DEPS" ]; then exfiltrate alma_get_sources
96+
;;
9297
*) echo >&2 "ERROR: unknown release, cannot know package manager"; exit 1 ;;
9398
esac
9499

95-
sudo $BDEP "${SPECFLAGS[@]}" -y $specs
96-
97-
: ${RPMBUILD_STAGE:=a} # default if not specified: -ba
98-
RPMBUILDFLAGS=(
99-
-b${RPMBUILD_STAGE} $specs
100-
--target "$RPMARCH"
101-
$RPMBUILD_OPTS
102-
"${SPECFLAGS[@]}"
103-
)
104-
# in case the build deps contain xs-opam-repo, source the added profile.d file
105-
[ ! -f /etc/profile.d/opam.sh ] || source /etc/profile.d/opam.sh
106-
if [ $? == 0 ]; then
107-
if [ -n "$RPMBUILD_DEFINE" ]; then
108-
RPMBUILDFLAGS+=(--define "$RPMBUILD_DEFINE")
100+
if [ -n "$BUILD_DEPS" ]; then
101+
BDEPFLAGS=()
102+
if [ -d ~/builddep/ ]; then
103+
BDEPFLAGS+=(--downloaddir ~/builddep/)
109104
fi
110-
rpmbuild "${RPMBUILDFLAGS[@]}"
111-
if [ $? == 0 -a -d ~/output/ ]; then
112-
cp -rf RPMS SRPMS ~/output/
105+
sudo $BDEP "${SPECFLAGS[@]}" --downloadonly "${BDEPFLAGS[@]}" -y $specs
106+
fi
107+
108+
if [ -n "$BUILD_LOCAL" ]; then
109+
sudo $BDEP "${SPECFLAGS[@]}" -y $specs
110+
: ${RPMBUILD_STAGE:=a} # default if not specified: -ba
111+
RPMBUILDFLAGS=(
112+
-b${RPMBUILD_STAGE} $specs
113+
--target "$RPMARCH"
114+
$RPMBUILD_OPTS
115+
"${SPECFLAGS[@]}"
116+
)
117+
# in case the build deps contain xs-opam-repo, source the added profile.d file
118+
[ ! -f /etc/profile.d/opam.sh ] || source /etc/profile.d/opam.sh
119+
if [ $? == 0 ]; then
120+
if [ -n "$RPMBUILD_DEFINE" ]; then
121+
RPMBUILDFLAGS+=(--define "$RPMBUILD_DEFINE")
122+
fi
123+
rpmbuild "${RPMBUILDFLAGS[@]}"
124+
if [ $? == 0 -a -d ~/output/ ]; then
125+
cp -rf RPMS SRPMS ~/output/
126+
fi
113127
fi
114128
fi
115129
)

src/xcp_ng_dev/cli.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,23 @@ def buildparser():
119119
'--rpmbuild-stage', action='store',
120120
help=f"Request given -bX stage rpmbuild, X in [{RPMBUILD_STAGES}]")
121121

122+
# builddep -- fetch/cache builddep of an rpm using a container
123+
parser_builddep = subparsers_container.add_parser(
124+
'builddep',
125+
help="Fetch dependencies for the spec file(s) found in the SPECS/ subdirectory "
126+
"of the directory passed as parameter.")
127+
add_container_args(parser_builddep)
128+
add_common_args(parser_builddep)
129+
group_builddep = parser_builddep.add_argument_group("builddep arguments")
130+
group_builddep.add_argument(
131+
'builddep_dir',
132+
help="Directory where the build-dependency RPMs will be cached. "
133+
"The directory is created if it doesn't exist")
134+
group_builddep.add_argument(
135+
'source_dir', nargs='?', default='.',
136+
help="Root path where SPECS/ and SOURCES are available. "
137+
"The default is the working directory")
138+
122139
# run -- execute commands inside a container
123140
parser_run = subparsers_container.add_parser(
124141
'run',
@@ -226,6 +243,16 @@ def container(args):
226243
docker_args += ["-e", "BUILD_LOCAL=1"]
227244
print(f"Building directory {build_dir}", file=sys.stderr)
228245

246+
case 'builddep':
247+
build_dir = os.path.abspath(args.source_dir)
248+
docker_args += ["-v", f"{build_dir}:/home/builder/rpmbuild"]
249+
docker_args += ["-e", "BUILD_DEPS=1"]
250+
251+
if args.builddep_dir:
252+
os.makedirs(args.builddep_dir, exist_ok=True)
253+
docker_args += ["-v", "%s:/home/builder/builddep:rw" %
254+
os.path.abspath(args.builddep_dir)]
255+
229256
case 'run':
230257
docker_args += ["-e", "COMMAND=%s" % ' '.join(args.command)]
231258

0 commit comments

Comments
 (0)