Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions xbstrap/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2366,17 +2366,18 @@ def run_cbuildrt(
environ=None,
host_environ=None,
):
workspace = _util.find_cbuildrt_workspace()
_util.try_mkdir(workspace, recursive=True)
workspace = _util.ensure_cbuildrt_workspace()

cbuild_json = {
"user": {"uid": 0, "gid": 0},
"process": {
"args": list(args),
"environ": environ or {},
},
"subUid": {"auto": True, "self": site_container_yml["uid"]},
"subGid": {"auto": True, "self": site_container_yml["gid"]},
"mapCurrentUserTo": {
"uid": site_container_yml["uid"],
"gid": site_container_yml["gid"],
},
"bindMounts": bind_mounts or [],
"volumes": volumes or [],
}
Expand All @@ -2399,7 +2400,7 @@ def run_cbuildrt(
)

result = subprocess.call(
["cbuildrt", "--workspace", workspace, f.name],
["cbuildrt", "run", "--workspace", workspace, f.name],
env=host_environ,
)
if result != 0:
Expand Down Expand Up @@ -2842,8 +2843,10 @@ def run_program(
],
}
if is_xbstrap_rootfs:
cbuild_json["subUid"] = {"auto": True, "self": container_yml["uid"]}
cbuild_json["subGid"] = {"auto": True, "self": container_yml["gid"]}
cbuild_json["mapCurrentUserTo"] = {
"uid": container_yml["uid"],
"gid": container_yml["gid"],
}
if sysroot is not None:
if verbosity:
_util.log_info(f"Bind mounting {sysroot} as sysroot")
Expand All @@ -2868,10 +2871,9 @@ def run_program(
environ, "PATH", prepend=[os.path.join(_util.find_home(), "bin")]
)

workspace = _util.find_cbuildrt_workspace()
_util.try_mkdir(workspace, recursive=True)
workspace = _util.ensure_cbuildrt_workspace()
proc = subprocess.Popen(
["cbuildrt", "--workspace", workspace, f.name],
["cbuildrt", "run", "--workspace", workspace, f.name],
env=environ,
)
proc.wait()
Expand Down
15 changes: 15 additions & 0 deletions xbstrap/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import os
import os.path as path
import re
import subprocess
import sys
import urllib.parse
import urllib.request
Expand Down Expand Up @@ -61,6 +62,20 @@ def find_cbuildrt_workspace():
return os.path.join(find_cache_dir(), "cbuildrt")


def ensure_cbuildrt_workspace():
workspace = find_cbuildrt_workspace()
try_mkdir(os.path.dirname(workspace), recursive=True)
meta_path = os.path.join(workspace, "workspace.json")
if not os.path.exists(meta_path):
environ = os.environ.copy()
build_environ_paths(environ, "PATH", prepend=[os.path.join(find_home(), "bin")])
subprocess.check_call(
["cbuildrt", "init", "--workspace", workspace],
env=environ,
)
return workspace


def try_mkdir(path, recursive=False):
try:
if not recursive:
Expand Down
Loading