osbuild: introduce Manifest class

The 'Manifest' class represents what to build and the necessary
sources to do so. For now thus it is just a combination of the
pipeline the source options.
This commit is contained in:
Christian Kellner 2020-12-16 18:56:23 +01:00 committed by Tom Gundersen
parent acef7aa4a9
commit 945914b195
6 changed files with 26 additions and 9 deletions

View file

@ -8,11 +8,12 @@ The utility module `osbuild.util` provides access to common functionality
independent of osbuild but used across the osbuild codebase.
"""
from .pipeline import Assembler, Pipeline, Stage
from .pipeline import Assembler, Manifest, Pipeline, Stage
__all__ = [
"Assembler",
"Manifest",
"Pipeline",
"Stage",
]

View file

@ -2,7 +2,7 @@
from typing import Dict
from osbuild.meta import Index, ValidationResult
from ..pipeline import Pipeline, detect_host_runner
from ..pipeline import Manifest, Pipeline, detect_host_runner
def describe(pipeline: Pipeline, *, with_id=False) -> Dict:
@ -63,13 +63,16 @@ def load_pipeline(description: Dict, sources_options: Dict) -> Pipeline:
return pipeline
def load(description: Dict) -> Pipeline:
def load(description: Dict) -> Manifest:
"""Load a manifest description"""
pipeline = description.get("pipeline", {})
sources = description.get("sources", {})
return load_pipeline(pipeline, sources)
pipeline = load_pipeline(pipeline, sources)
manifest = Manifest(pipeline, sources)
return manifest
def validate(manifest: Dict, index: Index) -> ValidationResult:

View file

@ -116,7 +116,8 @@ def osbuild_cli():
show_validation(res, args.manifest_path)
return 2
pipeline = fmt.load(desc)
manifest = fmt.load(desc)
pipeline = manifest.pipeline
if args.checkpoint:
missed = mark_checkpoints(pipeline, args.checkpoint)
@ -142,7 +143,7 @@ def osbuild_cli():
monitor = osbuild.monitor.make(monitor_name, sys.stdout.fileno())
try:
r = pipeline.run(
r = manifest.build(
args.store,
monitor,
args.libdir,

View file

@ -3,6 +3,7 @@ import hashlib
import json
import os
import tempfile
from typing import Dict
from .api import API
from . import buildroot
@ -327,6 +328,17 @@ class Pipeline:
return results
class Manifest:
"""Representation of a pipeline and its sources"""
def __init__(self, pipeline: Pipeline, source_options: Dict):
self.pipeline = pipeline
self.sources = source_options
def build(self, store, monitor, libdir, output_directory):
return self.pipeline.run(store, monitor, libdir, output_directory)
def detect_host_runner():
"""Use os-release(5) to detect the runner for the host"""
osname = osrelease.describe_os(*osrelease.DEFAULT_PATHS)

View file

@ -32,7 +32,7 @@ class TestDescriptions(unittest.TestCase):
for pipeline in cases:
manifest = {"pipeline": pipeline}
with self.subTest(pipeline):
desc = fmt.describe(fmt.load(manifest))
desc = fmt.describe(fmt.load(manifest).pipeline)
self.assertEqual(desc, {})
@unittest.skipUnless(test.TestBase.can_bind_mount(), "root-only")

View file

@ -354,8 +354,8 @@ class OSBuild(contextlib.AbstractContextManager):
manifest_json = json.loads(manifest_data)
manifest_parsed = fmt.load(manifest_json)
return manifest_parsed.tree_id
manifest = fmt.load(manifest_json)
return manifest.pipeline.tree_id
@contextlib.contextmanager
def map_object(self, obj):