1 /*#############################################################################
3 # Pakfire - The IPFire package management system #
4 # Copyright (C) 2023 Pakfire development team #
6 # This program is free software: you can redistribute it and/or modify #
7 # it under the terms of the GNU General Public License as published by #
8 # the Free Software Foundation, either version 3 of the License, or #
9 # (at your option) any later version. #
11 # This program is distributed in the hope that it will be useful, #
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14 # GNU General Public License for more details. #
16 # You should have received a copy of the GNU General Public License #
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 #############################################################################*/
24 #include <sys/syslog.h>
31 #include <pakfire/build.h>
32 #include <pakfire/pakfire.h>
34 #define MAX_MAKEFILES 32
42 char* makefiles
[MAX_MAKEFILES
];
43 unsigned int num_makefiles
;
47 OPT_DISABLE_CCACHE
= 1,
48 OPT_DISABLE_SNAPSHOT
= 2,
49 OPT_DISABLE_TESTS
= 3,
51 OPT_NON_INTERACTIVE
= 5,
55 static struct argp_option options
[] = {
56 { "disable-ccache", OPT_DISABLE_CCACHE
, NULL
, 0, "Disable the ccache", 0 },
57 { "disable-snapshot", OPT_DISABLE_SNAPSHOT
, NULL
, 0, "Do not use the snapshot", 0 },
58 { "disable-tests", OPT_DISABLE_TESTS
, NULL
, 0, "Do not run tests", 0 },
59 { "id", OPT_ID
, "ID", 0, "Use this build ID", 1 },
60 { "non-interactive", OPT_NON_INTERACTIVE
, NULL
, 0, "Run the build non-interactively", 0 },
61 { "target", OPT_TARGET
, "TARGET", 0, "Output all packages into this directory", 0 },
65 static error_t
parse(int key
, char* arg
, struct argp_state
* state
, void* data
) {
66 struct config
* config
= data
;
69 case OPT_DISABLE_CCACHE
:
70 config
->flags
|= PAKFIRE_BUILD_DISABLE_CCACHE
;
73 case OPT_DISABLE_SNAPSHOT
:
74 config
->flags
|= PAKFIRE_BUILD_DISABLE_SNAPSHOT
;
77 case OPT_DISABLE_TESTS
:
78 config
->flags
|= PAKFIRE_BUILD_DISABLE_TESTS
;
85 case OPT_NON_INTERACTIVE
:
86 config
->flags
&= ~PAKFIRE_BUILD_INTERACTIVE
;
94 if (config
->num_makefiles
>= MAX_MAKEFILES
)
97 config
->makefiles
[config
->num_makefiles
++] = arg
;
101 return ARGP_ERR_UNKNOWN
;
107 static int log_callback(struct pakfire_build
* build
, void* data
,
108 int priority
, int error
, const char* file
, int line
, const char* function
, const char* format
, ...) {
113 // Format the message
114 va_start(args
, format
);
115 r
= vasprintf(&buffer
, format
, args
);
118 // Fail if we could not format the message
123 // Highlight any error messages
125 fprintf(stderr
, "%s%s%s", color_highlight(), buffer
, color_reset());
128 // Print the rest to stdout
130 fprintf(stdout
, "%s", buffer
);
141 int cli_build(void* data
, int argc
, char* argv
[]) {
142 struct pakfire
* pakfire
= NULL
;
143 struct pakfire_build
* build
= NULL
;
144 struct config config
= {
147 .flags
= PAKFIRE_BUILD_INTERACTIVE
,
151 struct cli_config
* cli_config
= data
;
153 // Parse the command line
154 r
= cli_parse(options
, NULL
, NULL
, NULL
, parse
, 0, argc
, argv
, &config
);
159 r
= cli_setup_pakfire(&pakfire
, cli_config
);
163 // Setup the build environment
164 r
= pakfire_build_create(&build
, pakfire
, config
.id
, config
.flags
);
166 fprintf(stderr
, "Could not setup the build environment: %m\n");
171 pakfire_build_set_log_callback(build
, log_callback
, NULL
);
175 r
= pakfire_build_set_target(build
, config
.target
);
177 fprintf(stderr
, "Could not set target directory %s: %m\n", config
.target
);
182 // Process all packages
183 for (unsigned int i
= 0; i
< config
.num_makefiles
; i
++) {
185 r
= pakfire_build_exec(build
, config
.makefiles
[i
]);
187 fprintf(stderr
, "Could not build %s\n", config
.makefiles
[i
]);
194 pakfire_build_unref(build
);
196 pakfire_unref(pakfire
);