libmpm

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

commit 3bdf71ce1bc890f723abb28a7069fdcbb655baa2
parent 17c097a671cd2dd147d12a905c9f16bce9dcc270
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Fri, 19 May 2017 19:18:46 +0200

Add(Compile): Now installing packages

Diffstat:
Minc/compile.h | 2++
Minc/packer.h | 4++--
Msrc/compile.c | 35+++++++++++++++++++++++++++++++++--
Mtests/test_compile.c | 1+
4 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/inc/compile.h b/inc/compile.h @@ -105,4 +105,6 @@ bool configure_package(compile_t *ctx); */ bool make_package(compile_t *ctx); +bool install_package(compile_t *ctx); + #endif /* COMPILE_H */ diff --git a/inc/packer.h b/inc/packer.h @@ -37,8 +37,8 @@ # define PACKER_SCRIPT_DIR "scripts/" # define PACKER_MAKE_DEF "make" -# define PACKER_TEST_DEF "test" -# define PACKER_INST_DEF "install" +# define PACKER_TEST_DEF "make test" +# define PACKER_INST_DEF "make install" typedef enum packer_type_e { PACKER_TYPE_DIRECTORY, diff --git a/src/compile.c b/src/compile.c @@ -48,7 +48,8 @@ bool before_package(compile_t *ctx) { if (file_exist(COMP_BEFORE_SCRIPT) == false) goto end; - exec_line("sh " COMP_BEFORE_SCRIPT); + if (exec_line("sh " COMP_BEFORE_SCRIPT) != 0) + return false; end: ctx->state = INST_STATE_BEFORE; @@ -103,11 +104,41 @@ end: } bool make_package(compile_t *ctx) { + bool status = true; + /* Nothing to compile, we're good */ if (STR_NULL_OR_EMPTY(ctx->package->header->compilation->make)) goto end; + if (chdir(PACKER_SRC_DIR)) + return false; + + if (exec_line(ctx->package->header->compilation->make) != 0) + status = false; + + chdir(".."); + end: ctx->state = INST_STATE_COMPILATION; - return true; + return status; +} + +bool install_package(compile_t *ctx) { + bool status = true; + + /* Nothing to install, we're good */ + if (STR_NULL_OR_EMPTY(ctx->package->header->compilation->install)) + goto end; + + if (chdir(PACKER_SRC_DIR)) + return false; + + if (exec_line(ctx->package->header->compilation->install) != 0) + status = false; + + chdir(".."); + +end: + ctx->state = INST_STATE_INSTALLATION; + return status; } diff --git a/tests/test_compile.c b/tests/test_compile.c @@ -25,6 +25,7 @@ TEST(configure_package) { 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(install_package(ptr) == true, "An error happened"); TEST_ASSERT(package_install_cleanup(ptr) == true, "An error happened"); return TEST_SUCCESS;