Skip to content

Commit 3c39fae

Browse files
committed
cbuild: remove separate cli.call_chroot
Fold the functionality into cli.call, drop unnecessary things.
1 parent 6eb4cd6 commit 3c39fae

3 files changed

Lines changed: 48 additions & 75 deletions

File tree

src/cbuild/apk/cli.py

Lines changed: 31 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from cbuild.core import logger, paths, chroot, profile
1+
from cbuild.core import logger, paths, chroot as cbroot, profile
22

33
from . import sign as asign
44

@@ -29,14 +29,14 @@ def collect_repos(mrepo, intree, arch, use_altrepo, use_stage, use_net):
2929
srepos = mrepo.rparent.source_repositories
3030

3131
if not arch:
32-
arch = chroot.host_cpu()
32+
arch = cbroot.host_cpu()
3333

3434
prof = profile.get_profile(arch)
3535
use_cache = False
3636

3737
rrepos = set(prof.repos)
3838

39-
for r in chroot.get_confrepos():
39+
for r in cbroot.get_confrepos():
4040
if not r.startswith("/"):
4141
# should be a remote repository, skip outright if we
4242
# know that remote repos will not be used during this run
@@ -81,7 +81,7 @@ def collect_repos(mrepo, intree, arch, use_altrepo, use_stage, use_net):
8181
# alt repository comes last in order to be lower priority
8282
# also, always ignore stage for altrepo, as it should be considered opaque
8383
if paths.alt_repository() and use_altrepo:
84-
for r in chroot.get_confrepos():
84+
for r in cbroot.get_confrepos():
8585
if not r.startswith("/"):
8686
continue
8787
r = r.lstrip("/")
@@ -125,34 +125,50 @@ def call(
125125
use_stage=True,
126126
allow_network=True,
127127
return_repos=False,
128+
chroot=False,
128129
):
129130
if allow_network:
130131
allow_network = _use_net
131132
cmd = [
132-
paths.apk(),
133133
subcmd,
134134
"--no-interactive",
135-
"--root",
136-
root if root else paths.bldroot(),
137135
"--repositories-file",
138136
"/dev/null",
139137
]
138+
if not chroot:
139+
cmd += ["--root", root if root else paths.bldroot()]
140140
if arch:
141141
cmd += ["--arch", arch]
142142
if not allow_network:
143143
cmd += ["--no-network"]
144144
if allow_untrusted:
145-
cmd.append("--allow-untrusted")
145+
cmd += ["--allow-untrusted"]
146146
if subcmd in ["add", "del", "fix", "upgrade"]:
147-
cmd.append("--clean-protected")
147+
cmd += ["--clean-protected"]
148148

149149
crepos = collect_repos(
150-
mrepo, False, arch, use_altrepo, use_stage, allow_network
151-
)
152-
153-
retv = subprocess.run(
154-
cmd + crepos + args, cwd=cwd, env=env, capture_output=capture_output
150+
mrepo, chroot, arch, use_altrepo, use_stage, allow_network
155151
)
152+
cmd += crepos
153+
154+
if chroot:
155+
retv = cbroot.enter(
156+
"apk",
157+
*cmd,
158+
*args,
159+
capture_output=capture_output,
160+
fakeroot=True,
161+
mount_binpkgs=True,
162+
mount_cbuild_cache=subcmd
163+
in ["add", "del", "fix", "update", "upgrade"],
164+
)
165+
else:
166+
retv = subprocess.run(
167+
[paths.apk(), *cmd, *args],
168+
cwd=cwd,
169+
env=env,
170+
capture_output=capture_output,
171+
)
156172
if return_repos:
157173
return retv, crepos
158174
return retv
@@ -177,55 +193,6 @@ def query(fields, args, mrepo, return_repos=False, **kwargs):
177193
return outv
178194

179195

180-
# should never be called during stage 0 builds, only with a real chroot
181-
def call_chroot(
182-
subcmd,
183-
args,
184-
mrepo,
185-
capture_output=False,
186-
check=False,
187-
arch=None,
188-
allow_untrusted=False,
189-
use_stage=True,
190-
full_chroot=False,
191-
allow_network=True,
192-
):
193-
from cbuild.core import chroot
194-
195-
if allow_network:
196-
allow_network = _use_net
197-
198-
mount_cache = subcmd in ["add", "del", "fix", "update", "upgrade"]
199-
200-
if full_chroot:
201-
cmd = [subcmd]
202-
else:
203-
cmd = [subcmd, "--repositories-file", "/dev/null"]
204-
cmd.append("--no-interactive")
205-
if arch:
206-
cmd += ["--arch", arch]
207-
if not allow_network:
208-
cmd += ["--no-network"]
209-
if allow_untrusted:
210-
cmd.append("--allow-untrusted")
211-
if mount_cache and subcmd != "update":
212-
cmd.append("--clean-protected")
213-
214-
if not full_chroot:
215-
cmd += collect_repos(mrepo, True, arch, True, use_stage, allow_network)
216-
217-
return chroot.enter(
218-
"apk",
219-
*cmd,
220-
*args,
221-
capture_output=capture_output,
222-
check=check,
223-
fakeroot=True,
224-
mount_binpkgs=True,
225-
mount_cbuild_cache=mount_cache,
226-
)
227-
228-
229196
def get_provider(pkgn, pkg=None):
230197
cpf = pkg.rparent.profile() if pkg else None
231198

@@ -338,10 +305,8 @@ def summarize_repo(repopath, olist, quiet=False):
338305

339306

340307
def prune(repopath, arch=None, dry=False):
341-
from cbuild.core import chroot
342-
343308
if not arch:
344-
arch = chroot.host_cpu()
309+
arch = cbroot.host_cpu()
345310

346311
repopath = repopath / arch
347312

src/cbuild/core/chroot.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,12 @@ def shell_update(rnet, dirty):
270270

271271
with flock.lock(flock.apklock(hcpu)):
272272
if (
273-
apki.call_chroot(
274-
"update", [], None, full_chroot=True, allow_network=rnet
273+
enter(
274+
"apk",
275+
"update",
276+
fakeroot=True,
277+
mount_binpkgs=True,
278+
mount_cbuild_cache=True,
275279
).returncode
276280
!= 0
277281
):
@@ -575,12 +579,13 @@ def cleanup_world(bootstrapping, prof=None, perform=True):
575579
outf.write(f"{ep}\n")
576580

577581
# perform transaction
578-
f_ret = apki.call_chroot(
582+
f_ret = apki.call(
579583
"fix",
580584
[],
581585
template.get_cats(),
582586
capture_output=True,
583587
allow_untrusted=True,
588+
chroot=True,
584589
)
585590

586591
if f_ret.returncode != 0:
@@ -608,10 +613,11 @@ def update(pkg):
608613
_prepare_etc()
609614

610615
with flock.lock(flock.apklock(host_cpu())):
611-
apki.call_chroot("update", ["-q"], pkg, check=True, use_stage=True)
612-
apki.call_chroot(
613-
"upgrade", ["--available"], pkg, check=True, use_stage=True
614-
)
616+
fret = apki.call("update", ["-q"], pkg, use_stage=True)
617+
if fret.returncode == 0:
618+
fret = apki.call("upgrade", ["--available"], pkg, use_stage=True)
619+
if fret.returncode != 0:
620+
raise errors.CbuildException("failed to update bldroot")
615621

616622
# this is bootstrap-update
617623
if isinstance(pkg, str):

src/cbuild/core/dependencies.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def _install_from_repo(pkg, pkglist, cross=False):
171171
allow_untrusted=not signkey,
172172
)
173173
elif cross and pkg.profile().cross:
174-
ret = apki.call_chroot(
174+
ret = apki.call(
175175
"add",
176176
[
177177
"--root",
@@ -183,6 +183,7 @@ def _install_from_repo(pkg, pkglist, cross=False):
183183
capture_output=True,
184184
arch=pkg.profile().arch,
185185
allow_untrusted=not signkey,
186+
chroot=True,
186187
)
187188
else:
188189
# write world file and fix instead of adding to account for previous
@@ -193,12 +194,13 @@ def _install_from_repo(pkg, pkglist, cross=False):
193194
for pkgn in pkglist:
194195
wf.write(f"{pkgn}\n")
195196
# and then perform the transaction
196-
ret = apki.call_chroot(
197+
ret = apki.call(
197198
"fix",
198199
[],
199200
pkg,
200201
capture_output=True,
201202
allow_untrusted=not signkey,
203+
chroot=True,
202204
)
203205
if ret.returncode != 0:
204206
outl = ret.stderr.strip().decode()

0 commit comments

Comments
 (0)