Skip to content

Commit

Permalink
base: implement the containerless property for tools
Browse files Browse the repository at this point in the history
Co-authored-by: Fedor Lapshin <[email protected]>
  • Loading branch information
no92 and FedorLap2006 committed Dec 18, 2023
1 parent 6d0f5f6 commit 79857eb
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
3 changes: 3 additions & 0 deletions xbstrap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ def do_runtool(args):
for name in tools:
tool_pkgs.append(cfg.get_tool_pkg(name))

has_containerless = any(x.containerless for x in tool_pkgs)

xbstrap.base.run_program(
cfg,
context,
Expand All @@ -77,6 +79,7 @@ def do_runtool(args):
tool_pkgs=tool_pkgs,
workdir=workdir,
for_package=for_package,
containerless=has_containerless,
)


Expand Down
44 changes: 38 additions & 6 deletions xbstrap/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,9 @@ def get_target_pkg(self, name):


class ScriptStep:
def __init__(self, step_yml):
def __init__(self, step_yml, containerless=False):
self._step_yml = step_yml
self._containerless = containerless

@property
def args(self):
Expand All @@ -574,7 +575,7 @@ def workdir(self):

@property
def containerless(self):
return self._step_yml.get("containerless", False)
return self._step_yml.get("containerless", False) or self._containerless

@property
def quiet(self):
Expand Down Expand Up @@ -999,10 +1000,10 @@ def __init__(self, cfg, pkg, inherited, stage_yml):

if "compile" in self._this_yml:
for step_yml in self._this_yml["compile"]:
self._compile_steps.append(ScriptStep(step_yml))
self._compile_steps.append(ScriptStep(step_yml, pkg.containerless))
if "install" in self._this_yml:
for step_yml in self._this_yml["install"]:
self._install_steps.append(ScriptStep(step_yml))
self._install_steps.append(ScriptStep(step_yml, pkg.containerless))

@property
def pkg(self):
Expand All @@ -1022,6 +1023,12 @@ def subject_id(self):
def subject_type(self):
return "tool stage"

@property
def containerless(self):
if "containerless" not in self._this_yml:
return False
return self._this_yml["containerless"]

@property
def compile_steps(self):
yield from self._compile_steps
Expand Down Expand Up @@ -1086,12 +1093,15 @@ def __init__(self, cfg, pkg_yml):
stage = HostStage(self._cfg, self, False, stage_yml)
self._stages[stage.stage_name] = stage
else:
stage = HostStage(self._cfg, self, True, self._this_yml)
step_yml = self._this_yml
if self.containerless:
step_yml["containerless"] = True
stage = HostStage(self._cfg, self, True, step_yml)
self._stages[stage.stage_name] = stage

if "configure" in self._this_yml:
for step_yml in self._this_yml["configure"]:
self._configure_steps.append(ScriptStep(step_yml))
self._configure_steps.append(ScriptStep(step_yml, self.containerless))

if "tasks" in self._this_yml:
for task_yml in self._this_yml["tasks"]:
Expand All @@ -1115,6 +1125,12 @@ def exports_aclocal(self):
return False
return self._this_yml["exports_aclocal"]

@property
def containerless(self):
if "containerless" not in self._this_yml:
return False
return self._this_yml["containerless"]

@property
def source(self):
if "from_source" in self._this_yml:
Expand Down Expand Up @@ -1726,6 +1742,16 @@ def run_program(
):
pkg_queue = []
pkg_visited = set()
tools_all_containerless = (
all(x.containerless for x in tool_pkgs) if tool_pkgs else containerless
)

tools_some_containerless = (
any(x.containerless for x in tool_pkgs) if tool_pkgs else containerless
)

if tools_some_containerless is not tools_all_containerless:
raise GenericError("mixing containerless with non-containerless tools is not supported")

for pkg in tool_pkgs:
assert pkg.name not in pkg_visited
Expand Down Expand Up @@ -1817,6 +1843,12 @@ def run_program(
if runtime is None:
use_container = False

if tools_all_containerless and use_container:
raise GenericError("running containerless is not allowed by your configuration")

if containerless is not tools_all_containerless:
raise GenericError("containerless steps can only use containerless tools")

if use_container:
if runtime == "dummy":
manifest["source_root"] = cfg.source_root
Expand Down
2 changes: 2 additions & 0 deletions xbstrap/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ properties:
type: boolean
'exports_shared_libs':
type: boolean
'containerless':
type: boolean
'architecture': { type: string }
'configure': { $ref: '#/definitions/build_steps' }
'compile': { $ref: '#/definitions/build_steps' }
Expand Down

0 comments on commit 79857eb

Please sign in to comment.