Skip to content

Commit

Permalink
base: implement the containerless property for tools
Browse files Browse the repository at this point in the history
  • Loading branch information
no92 committed Sep 3, 2023
1 parent afdce7f commit e4a228a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
6 changes: 6 additions & 0 deletions xbstrap/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# SPDX-License-Identifier: MIT

import argparse
import functools
import json
import os
import shutil
Expand Down Expand Up @@ -69,6 +70,10 @@ def do_runtool(args):
for name in tools:
tool_pkgs.append(cfg.get_tool_pkg(name))

has_containerless = functools.reduce(
lambda x, y: x or y, map(lambda x: x.containerless, tool_pkgs)
)

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


Expand Down
46 changes: 45 additions & 1 deletion xbstrap/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import collections
import errno
import filecmp
import functools
import json
import os
import re
Expand Down Expand Up @@ -999,9 +1000,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 +1027,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 +1094,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 +1133,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 +1750,20 @@ def run_program(
):
pkg_queue = []
pkg_visited = set()
tools_all_containerless = (
functools.reduce(lambda x, y: x and y, map(lambda x: x.containerless, tool_pkgs))
if tool_pkgs
else containerless
)

tools_some_containerless = (
functools.reduce(lambda x, y: x or y, 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 +1855,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 e4a228a

Please sign in to comment.