libmpm

morphux C package management library
Log | Files | Refs | Submodules | README | LICENSE | git clone https://git.ne02ptzero.me/git/libmpm

commit f2bb0c0f3f71422bcdb4f87490daa23103228897
parent 6979e76ac170f351d6e529c92d394586f6792f50
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Wed, 17 May 2017 18:23:07 +0200

Add(Compile): Add function for before scripts, with more states in the installation process

Diffstat:
Minc/compile.h | 16++++++++++++++++
Msrc/compile.c | 9+++++++++
Mtests/test_compile.c | 1+
3 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/inc/compile.h b/inc/compile.h @@ -19,11 +19,18 @@ # include <packer.h> +# define COMP_BEFORE_SCRIPT PACKER_SRC_DIR "before.sh" +# define COMP_AFTER_SCRIPT PACKER_SRC_DIR "after.sh" + typedef enum { INST_STATE_NONE = 0, + INST_STATE_BEFORE, + INST_STATE_PATCHING, INST_STATE_CONFIGURATION, INST_STATE_COMPILATION, INST_STATE_INSTALLATION, + INST_STATE_AFTER, + INST_STATE_DB, INST_STATE_DONE } install_state_t; @@ -61,6 +68,15 @@ compile_t *package_install_init(packer_t *ctx); bool package_install_cleanup(compile_t *ctx); /*! + * \brief Execute before script, if there is any + * + * \param[in] ctx Current package + * + * \return true on success, false on failure + */ +bool before_package(compile_t *ctx); + +/*! * \brief Configure a package * * \param[in] ctx Package to configure diff --git a/src/compile.c b/src/compile.c @@ -44,6 +44,15 @@ bool package_install_cleanup(compile_t *ctx) { return true; } +bool before_package(compile_t *ctx) { + if (file_exist(COMP_BEFORE_SCRIPT) == false) + goto end; + +end: + ctx->state = INST_STATE_BEFORE; + return true; +} + bool configure_package(compile_t *ctx) { /* Nothing to configure, we're good */ if (ctx->package->header->compilation->configure == NULL) diff --git a/tests/test_compile.c b/tests/test_compile.c @@ -21,6 +21,7 @@ TEST(configure_package) { packer_extract_archive(ctx, "/tmp"); ptr = package_install_init(ctx); TEST_ASSERT(ptr != NULL, "An error happened"); + TEST_ASSERT(before_package(ptr) == true, "An error happened"); TEST_ASSERT(configure_package(ptr) == true, "An error happened"); TEST_ASSERT(make_package(ptr) == true, "An error happened"); TEST_ASSERT(package_install_cleanup(ptr) == true, "An error happened");