From 28e25079b424ac9ba52bff455862289471aacc4f Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Wed, 1 Apr 2020 00:07:22 -0500 Subject: image: Initial work on backend support --- image/backends/CMakeLists.txt | 4 ++++ image/backends/README.rst | 12 ++++++---- image/backends/backends.hh | 33 ++++++++++++++++++++++++++ image/backends/basic.cc | 37 +++++++++++++++++++++++++++++ image/backends/basic.hh | 54 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 135 insertions(+), 5 deletions(-) create mode 100644 image/backends/CMakeLists.txt create mode 100644 image/backends/backends.hh create mode 100644 image/backends/basic.cc create mode 100644 image/backends/basic.hh (limited to 'image/backends') diff --git a/image/backends/CMakeLists.txt b/image/backends/CMakeLists.txt new file mode 100644 index 0000000..f3c7f5d --- /dev/null +++ b/image/backends/CMakeLists.txt @@ -0,0 +1,4 @@ +set(BACKEND_SRCS + ${CMAKE_CURRENT_SOURCE_DIR}/basic.cc + PARENT_SCOPE +) diff --git a/image/backends/README.rst b/image/backends/README.rst index ca510b9..acb44ef 100644 --- a/image/backends/README.rst +++ b/image/backends/README.rst @@ -41,17 +41,19 @@ Design Image creation backends shall derive from the Horizon::Image::BasicBackend class. Concrete backends can exist in any namespace. To be used with the -Image Creation utility, the backend must be registered in the ``backends.hh`` +Image Creation utility, the backend must be registered in the ``basic.cc`` file along with a unique Type Code. This Type Code can then be passed to the Image Creation utility with the ``-t`` parameter for use. The Horizon::Image::BasicBackend is an abstract (pure virtual) class that has a single method that you must implement: ``create()``. This will be -called on a constructed object of your concrete backend class, with two -parameters: ``std::string ir_dir``, which is the base directory for the -installed system (like ``/target`` during a normal installation), and +called on a constructed object of your concrete backend class, which has two +instance variables: ``std::string ir_dir``, which is the base directory for +the installed system (like ``/target`` during a normal installation), and ``std::string out_path``, which is the user's desired output path and file -name. +name. You may also implement ``prepare()``, which is called before create, +and ``finalise()``, which is called after. Default no-op implementations +are provided for you in BasicBackend. diff --git a/image/backends/backends.hh b/image/backends/backends.hh new file mode 100644 index 0000000..3199ee0 --- /dev/null +++ b/image/backends/backends.hh @@ -0,0 +1,33 @@ +/* + * backends.hh - Horizon Image Creation backend table + * image, the image processing utilities for + * Project Horizon + * + * Copyright (c) 2020 Adélie Linux and contributors. All rights reserved. + * This code is licensed under the AGPL 3.0 license, as noted in the + * LICENSE-code file in the root directory of this repository. + * + * SPDX-License-Identifier: AGPL-3.0-only + */ + +#pragma once + +#include +#include +#include + +namespace Horizon { +namespace Image { + +class BasicBackend; + +struct BackendDescriptor { + std::string type_code; + std::string description; + std::function creation_fn; +}; + +extern std::vector known_backends; + +} +} diff --git a/image/backends/basic.cc b/image/backends/basic.cc new file mode 100644 index 0000000..908f1d9 --- /dev/null +++ b/image/backends/basic.cc @@ -0,0 +1,37 @@ +/* + * basic.cc - Implementation of the abstract Horizon Image Creation backend + * image, the image processing utilities for + * Project Horizon + * + * Copyright (c) 2020 Adélie Linux and contributors. All rights reserved. + * This code is licensed under the AGPL 3.0 license, as noted in the + * LICENSE-code file in the root directory of this repository. + * + * SPDX-License-Identifier: AGPL-3.0-only + */ + +#include "basic.hh" +#include "backends.hh" + +namespace Horizon { +namespace Image { + +std::vector known_backends = { + {"tar", "Create a tarball (.tar)", [](std::string, std::string){ return nullptr; } }, + {"squashfs", "Create a SquashFS image (.squashfs)", [](std::string, std::string){ return nullptr; } } +}; + +int BasicBackend::prepare() { + /* The default implementation returns success immediately; + * no preparation is required. */ + return 0; +} + +int BasicBackend::finalise() { + /* The default implementation returns success immediately; + * no finalisation is required. */ + return 0; +} + +} +} diff --git a/image/backends/basic.hh b/image/backends/basic.hh new file mode 100644 index 0000000..d39c57e --- /dev/null +++ b/image/backends/basic.hh @@ -0,0 +1,54 @@ +/* + * basic.hh - Definition of the abstract Horizon Image Creation backend + * image, the image processing utilities for + * Project Horizon + * + * Copyright (c) 2020 Adélie Linux and contributors. All rights reserved. + * This code is licensed under the AGPL 3.0 license, as noted in the + * LICENSE-code file in the root directory of this repository. + * + * SPDX-License-Identifier: AGPL-3.0-only + */ + +#pragma once + +#include + +namespace Horizon { +namespace Image { + +class BasicBackend { +public: + /*! Create the backend object. + * @param _ir_dir The intermediate directory the image should contain. + * @param _out_path The path to write the image. + */ + BasicBackend(const std::string &_ir_dir, const std::string &_out_path) : + ir_dir(_ir_dir), out_path(_out_path) {}; + virtual ~BasicBackend() {}; + + /*! Prepare for creating the image. + * @returns 0 if preparation succeeded; otherwise, an error code. + */ + virtual int prepare(); + + /*! Create the image. + * @returns 0 if the image is created successfully; otherwise, an error + * code which explains the failure. + */ + virtual int create() = 0; + + /*! Finalise the image. + * @returns 0 if the image is finalised; otherwise, an error code. + */ + virtual int finalise(); + + /*! The intermediate directory which contains the sysroot the image + * should contain. */ + const std::string &ir_dir; + /*! The path at which to write the image. */ + const std::string &out_path; +}; + +} +} -- cgit v1.2.3-70-g09d2