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 #############################################################################*/
23 #include <pakfire/buildservice.h>
25 #include "client-build.h"
29 static const char* args_doc
= "[OPTIONS...] MAKEFILES...";
31 static const char* doc
= "Build packages remotely";
34 #define MAX_UPLOADS 32
35 #define MAX_PACKAGES 32
36 #define MAX_MAKEFILES 32
42 const char* arches
[MAX_ARCHES
];
43 unsigned int num_arches
;
46 char* packages
[MAX_PACKAGES
];
47 unsigned int num_packages
;
50 char* uploads
[MAX_UPLOADS
];
51 unsigned int num_uploads
;
56 OPT_DISABLE_TESTS
= 2,
60 static struct argp_option options
[] = {
61 { "arch", OPT_ARCH
, "ARCH", 0, "Build for this architecture", 0 },
62 { "disable-tests", OPT_DISABLE_TESTS
, NULL
, 0, "Do not run tests", 0 },
63 { "repo", OPT_REPO
, "REPO", 0, "Build against this repository", 0 },
67 static error_t
parse(int key
, char* arg
, struct argp_state
* state
, void* data
) {
68 struct config
* config
= data
;
72 if (config
->num_arches
>= MAX_ARCHES
)
75 config
->arches
[config
->num_arches
++] = arg
;
78 case OPT_DISABLE_TESTS
:
79 config
->flags
|= PAKFIRE_BUILD_DISABLE_TESTS
;
87 if (config
->num_packages
>= MAX_PACKAGES
)
90 config
->packages
[config
->num_packages
++] = arg
;
94 return ARGP_ERR_UNKNOWN
;
100 int cli_client_build(void* data
, int argc
, char* argv
[]) {
101 struct pakfire_buildservice
* service
= NULL
;
102 struct config config
= {};
106 struct cli_config
* cli_config
= data
;
108 // Parse the command line
109 r
= cli_parse(options
, NULL
, args_doc
, doc
, parse
, argc
, argv
, &config
);
113 // Connect to the build service
114 r
= pakfire_buildservice_create(&service
, cli_config
->ctx
);
118 // Upload all packages
119 for (unsigned int i
= 0; i
< config
.num_packages
; i
++) {
120 r
= pakfire_buildservice_upload(service
, config
.packages
[i
], NULL
, &upload
);
124 // Store the upload ID
125 config
.uploads
[config
.num_uploads
++] = upload
;
129 if (!config
.num_uploads
)
132 // Build all the things
133 for (unsigned int i
= 0; i
< config
.num_uploads
; i
++) {
134 r
= pakfire_buildservice_build(service
, config
.uploads
[i
], config
.repo
,
135 config
.arches
, config
.flags
);
140 free(config
.uploads
[i
]);
141 config
.uploads
[i
] = NULL
;
145 // Delete & free all uploads that could not be processed
146 for (unsigned int i
= 0; i
< config
.num_uploads
; i
++) {
147 if (config
.uploads
[i
]) {
148 pakfire_buildservice_delete_upload(service
, config
.uploads
[i
]);
149 free(config
.uploads
[i
]);
153 pakfire_buildservice_unref(service
);