libmpm

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

commit e127a347262dd8c1107b47811c5602fc2cbb4438
parent 9ce25754017a3ef442899ab561d7468fdff896ce
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Fri, 19 May 2017 19:02:05 +0200

Add(Compile): Now applying patch before compilation

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

diff --git a/inc/compile.h b/inc/compile.h @@ -22,6 +22,8 @@ # define COMP_BEFORE_SCRIPT PACKER_SCRIPT_DIR "before.sh" # define COMP_AFTER_SCRIPT PACKER_SCRIPT_DIR "after.sh" +# define PATCH_CMD "patch -Ni" + typedef enum { INST_STATE_NONE = 0, INST_STATE_BEFORE, @@ -77,6 +79,15 @@ bool package_install_cleanup(compile_t *ctx); bool before_package(compile_t *ctx); /*! + * \brief Apply system and user patch + * + * \param[in] ctx Current paco + * + * \return true on succes, false on failure + */ +bool patch_package(compile_t *ctx); + +/*! * \brief Configure a package * * \param[in] ctx Package to configure diff --git a/src/compile.c b/src/compile.c @@ -55,6 +55,36 @@ end: return true; } +bool patch_package(compile_t *ctx) { + DIR *dir = opendir(PACKER_PATCH_DIR); + struct dirent *dinfo = NULL; + char *cmd = NULL; + + /* Nothing to patch, we're good */ + if (dir == NULL) + return true; + + chdir(PACKER_SRC_DIR); + while ((dinfo = readdir(dir))) + { + /* Skip .* files */ + if (strlen(dinfo->d_name) > 0 && dinfo->d_name[0] == '.') + continue ; + + if (dinfo->d_type != DT_DIR) + { + asprintf(&cmd, "%s ../%s%s", PATCH_CMD, PACKER_PATCH_DIR, dinfo->d_name); + exec_line(cmd); + free(cmd); + } + } + + chdir(".."); + closedir(dir); + ctx->state = INST_STATE_PATCHING; + 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 @@ -22,6 +22,7 @@ TEST(configure_package) { ptr = package_install_init(ctx); TEST_ASSERT(ptr != NULL, "An error happened"); TEST_ASSERT(before_package(ptr) == true, "An error happened"); + TEST_ASSERT(patch_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");