]> git.ipfire.org Git - pakfire.git/commitdiff
cli: Fix enabling the snapshot
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 13 Oct 2024 13:42:25 +0000 (13:42 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 13 Oct 2024 13:42:25 +0000 (13:42 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/cli/lib/build.c
src/cli/lib/shell.c

index b787f040b616192a3d6f459606d77cb241c2a431..d21c124f4aa0a2ca0b93675eef93312eb7e357c8 100644 (file)
 struct config {
        const char* id;
        const char* target;
-       int flags;
+       enum {
+               BUILD_INTERACTIVE     = (1 << 0),
+               BUILD_ENABLE_CCACHE   = (1 << 1),
+               BUILD_ENABLE_SNAPSHOT = (1 << 2),
+               BUILD_ENABLE_TESTS    = (1 << 3),
+       } flags;
 
        // Makefiles
        char* makefiles[MAX_MAKEFILES];
@@ -67,15 +72,15 @@ static error_t parse(int key, char* arg, struct argp_state* state, void* data) {
 
        switch (key) {
                case OPT_DISABLE_CCACHE:
-                       config->flags |= PAKFIRE_BUILD_DISABLE_CCACHE;
+                       config->flags &= ~BUILD_ENABLE_CCACHE;
                        break;
 
                case OPT_DISABLE_SNAPSHOT:
-                       config->flags |= PAKFIRE_BUILD_DISABLE_SNAPSHOT;
+                       config->flags &= ~BUILD_ENABLE_SNAPSHOT;
                        break;
 
                case OPT_DISABLE_TESTS:
-                       config->flags |= PAKFIRE_BUILD_DISABLE_TESTS;
+                       config->flags &= ~BUILD_ENABLE_TESTS;
                        break;
 
                case OPT_ID:
@@ -83,7 +88,7 @@ static error_t parse(int key, char* arg, struct argp_state* state, void* data) {
                        break;
 
                case OPT_NON_INTERACTIVE:
-                       config->flags &= ~PAKFIRE_BUILD_INTERACTIVE;
+                       config->flags &= ~BUILD_INTERACTIVE;
                        break;
 
                case OPT_TARGET:
@@ -139,8 +144,13 @@ int cli_build(void* data, int argc, char* argv[]) {
        struct config config = {
                .id     = NULL,
                .target = NULL,
-               .flags  = PAKFIRE_USE_SNAPSHOT,
+               .flags  =
+                       BUILD_INTERACTIVE |
+                       BUILD_ENABLE_CCACHE |
+                       BUILD_ENABLE_SNAPSHOT |
+                       BUILD_ENABLE_TESTS,
        };
+       int build_flags = 0;
        int r;
 
        struct cli_config* cli_config = data;
@@ -153,13 +163,29 @@ int cli_build(void* data, int argc, char* argv[]) {
        // Replace the logger
        pakfire_ctx_set_log_callback(cli_config->ctx, log_callback, NULL);
 
+       // Set Pakfire flags
+       if (config.flags & BUILD_ENABLE_SNAPSHOT)
+               cli_config->flags |= PAKFIRE_USE_SNAPSHOT;
+
        // Setup pakfire
        r = cli_setup_pakfire(&pakfire, cli_config);
        if (r)
                goto ERROR;
 
+       // Is the build interactive?
+       if (config.flags & BUILD_INTERACTIVE)
+               build_flags |=  PAKFIRE_BUILD_INTERACTIVE;
+
+       // Enable ccache?
+       if (!(config.flags & BUILD_ENABLE_CCACHE))
+               build_flags |= PAKFIRE_BUILD_DISABLE_CCACHE;
+
+       // Enable tests?
+       if (!(config.flags & BUILD_ENABLE_TESTS))
+               build_flags |= PAKFIRE_BUILD_DISABLE_TESTS;
+
        // Setup the build environment
-       r = pakfire_build_create(&build, pakfire, config.id, config.flags);
+       r = pakfire_build_create(&build, pakfire, config.id, build_flags);
        if (r) {
                fprintf(stderr, "Could not setup the build environment: %m\n");
                goto ERROR;
index 31a43e8e97d5bef2cf01f9c0b1096d106998c2c5..d13972ec6ff131758e5f553c96a5b422c2b23a4a 100644 (file)
@@ -31,7 +31,9 @@
 #define MAX_PACKAGES 128
 
 struct config {
-       int flags;
+       enum {
+               SHELL_ENABLE_SNAPSHOT = (1 << 0),
+       } flags;
 
        // Arguments
        const char* argv[MAX_ARGS + 1];
@@ -61,7 +63,7 @@ static error_t parse(int key, char* arg, struct argp_state* state, void* data) {
 
        switch (key) {
                case OPT_DISABLE_SNAPSHOT:
-                       config->flags |= PAKFIRE_BUILD_DISABLE_SNAPSHOT;
+                       config->flags &= ~SHELL_ENABLE_SNAPSHOT;
                        break;
 
                case OPT_INSTALL:
@@ -92,11 +94,8 @@ int cli_shell(void* data, int argc, char* argv[]) {
 
        struct cli_config* cli_config = data;
 
-       // XXX DEBUG
-       cli_config->flags |= PAKFIRE_USE_SNAPSHOT;
-
        struct config config = {
-               .flags        = PAKFIRE_BUILD_INTERACTIVE,
+               .flags        = SHELL_ENABLE_SNAPSHOT,
                .argv         = {},
                .argc         = 0,
                .packages     = {},
@@ -108,13 +107,17 @@ int cli_shell(void* data, int argc, char* argv[]) {
        if (r)
                goto ERROR;
 
+       // Enable snapshots?
+       if (config.flags & SHELL_ENABLE_SNAPSHOT)
+               cli_config->flags |= PAKFIRE_USE_SNAPSHOT;
+
        // Setup pakfire
        r = cli_setup_pakfire(&pakfire, cli_config);
        if (r)
                goto ERROR;
 
        // Setup the build environment
-       r = pakfire_build_create(&build, pakfire, NULL, config.flags);
+       r = pakfire_build_create(&build, pakfire, NULL, PAKFIRE_BUILD_INTERACTIVE);
        if (r) {
                fprintf(stderr, "Could not setup the build environment: %m\n");
                goto ERROR;