Skip to content

Commit 4f964b5

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 65ac0f7 commit 4f964b5

File tree

2 files changed

+64
-23
lines changed

2 files changed

+64
-23
lines changed

src/xcp_ng_dev/cli.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,22 @@ def buildparser():
120120
add_container_args(parser_build)
121121
add_common_args(parser_build)
122122

123+
# builddep -- fetch/cache builddep of an rpm using a container
124+
parser_builddep = subparsers_container.add_parser(
125+
'builddep',
126+
help="Fetch dependencies for the spec file(s) found in the SPECS/ subdirectory "
127+
"of the directory passed as parameter.")
128+
parser_builddep.add_argument(
129+
'source_dir', nargs='?', default='.',
130+
help="Root path where SPECS/ and SOURCES are available. "
131+
"The default is the working directory")
132+
add_container_args(parser_builddep)
133+
add_common_args(parser_builddep)
134+
parser_builddep.add_argument(
135+
'builddep_dir',
136+
help="Directory where the build-dependency RPMs will be cached. "
137+
"The directory is created if it doesn't exist")
138+
123139
# run -- execute commands inside a container
124140
parser_run = subparsers_container.add_parser(
125141
'run',
@@ -156,11 +172,18 @@ def container(args):
156172

157173
if hasattr(args, 'command') and args.command != []:
158174
docker_args += ["-e", "COMMAND=%s" % ' '.join(args.command)]
159-
if args.action == 'build':
175+
if args.action in ('build', 'builddep'):
160176
build_dir = os.path.abspath(args.source_dir)
161-
docker_args += ["-v", f"{build_dir}:/home/builder/rpmbuild"]
162-
docker_args += ["-e", "BUILD_LOCAL=1"]
163177
print(f"Building directory {build_dir}", file=sys.stderr)
178+
docker_args += ["-v", f"{build_dir}:/home/builder/rpmbuild"]
179+
match args.action:
180+
case 'build':
181+
docker_args += ["-e", "BUILD_LOCAL=1"]
182+
case 'builddep':
183+
docker_args += ["-e", "BUILD_DEPS=1"]
184+
case _:
185+
print(f"unhandled action {args.action}", file=sys.stderr)
186+
sys.exit(1)
164187
if hasattr(args, 'define') and args.define:
165188
docker_args += ["-e", "RPMBUILD_DEFINE=%s" % args.define]
166189
if hasattr(args, 'rpmbuild_opts') and args.rpmbuild_opts:
@@ -174,6 +197,10 @@ def container(args):
174197
os.makedirs(args.output_dir, exist_ok=True)
175198
docker_args += ["-v", "%s:/home/builder/output" %
176199
os.path.abspath(args.output_dir)]
200+
if hasattr(args, 'builddep_dir') and args.builddep_dir:
201+
os.makedirs(args.builddep_dir, exist_ok=True)
202+
docker_args += ["-v", "%s:/home/builder/builddep" %
203+
os.path.abspath(args.builddep_dir)]
177204
if args.no_exit:
178205
docker_args += ["-e", "NO_EXIT=1"]
179206
if args.fail_on_error:

src/xcp_ng_dev/files/init-container.sh

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

70-
if [ -n "$BUILD_LOCAL" ]; then
70+
if [ -n "$BUILD_LOCAL$BUILD_DEPS" ]; then
7171
time (
7272
cd ~/rpmbuild
73-
rm BUILD BUILDROOT RPMS SRPMS -rf
73+
if [ -n "$BUILD_LOCAL" ]; then
74+
rm BUILD BUILDROOT RPMS SRPMS -rf
75+
fi
7476

7577
if specs=$(ls *.spec 2>/dev/null); then
7678
SPECFLAGS=(
@@ -86,28 +88,40 @@ if [ -n "$BUILD_LOCAL" ]; then
8688

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

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

0 commit comments

Comments
 (0)