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 Sep 3, 2023
1 parent afdce7f commit 2a9e026
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
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(map(lambda x: x.containerless, 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
41 changes: 40 additions & 1 deletion xbstrap/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,9 +999,13 @@ def __init__(self, cfg, pkg, inherited, stage_yml):

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

@property
Expand All @@ -1022,6 +1026,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 @@ -1083,14 +1093,21 @@ def __init__(self, cfg, pkg_yml):

if "stages" in self._this_yml:
for stage_yml in self._this_yml["stages"]:
if self.containerless:
stage_yml["containerless"] = True
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"]:
if self.containerless:
step_yml["containerless"] = True
self._configure_steps.append(ScriptStep(step_yml))

if "tasks" in self._this_yml:
Expand All @@ -1115,6 +1132,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 +1749,16 @@ def run_program(
):
pkg_queue = []
pkg_visited = set()
tools_all_containerless = (
all(map(lambda x: x.containerless, tool_pkgs)) if tool_pkgs else containerless
)

tools_some_containerless = (
any(map(lambda x: x.containerless, 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 +1850,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 2a9e026

Please sign in to comment.