From: Michael Tremer Date: Fri, 29 Sep 2023 09:43:10 +0000 (+0000) Subject: cli: pakfire-builder: Implement the build command X-Git-Tag: 0.9.30~1609 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=060a1182d90faaeb7d695b2f5b9a44508280eef0;p=pakfire.git cli: pakfire-builder: Implement the build command Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 2e0356494..baa60a794 100644 --- a/Makefile.am +++ b/Makefile.am @@ -429,6 +429,8 @@ noinst_LTLIBRARIES += \ libcli.la libcli_la_SOURCES = \ + src/cli/lib/build.c \ + src/cli/lib/build.h \ src/cli/lib/check.c \ src/cli/lib/check.h \ src/cli/lib/clean.c \ diff --git a/src/cli/lib/build.c b/src/cli/lib/build.c new file mode 100644 index 000000000..4ddff0d71 --- /dev/null +++ b/src/cli/lib/build.c @@ -0,0 +1,166 @@ +/*############################################################################# +# # +# Pakfire - The IPFire package management system # +# Copyright (C) 2023 Pakfire development team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +#############################################################################*/ + +#include +#include +#include + +#include "build.h" +#include "command.h" + +#include +#include + +struct config { + const char* id; + const char* target; + int flags; +}; + +static void help(void) { + printf( + "%s [OPTIONS...] build [OPTIONS...] MAKEFILE\n\n" + "Options:\n" + " --disable-ccache Disables using ccache\n" + " --disable-snapshot Do not use the snapshot\n" + " --disable-tests Do not run tests\n" + " --non-interactive Run the build non-interactively\n" + " --target Output all packages to this directory\n" + " -h --help Show help\n", + program_invocation_short_name + ); + + exit(0); +} + +static int parse_argv(struct config* config, int argc, char* argv[]) { + enum { + ARG_DISABLE_CCACHE, + ARG_DISABLE_SNAPSHOT, + ARG_DISABLE_TESTS, + ARG_ID, + ARG_NON_INTERACTIVE, + ARG_TARGET, + }; + + static const struct option options[] = { + { "disable-ccache", no_argument, NULL, ARG_DISABLE_CCACHE }, + { "disable-snapshot", no_argument, NULL, ARG_DISABLE_SNAPSHOT }, + { "disable-tests", no_argument, NULL, ARG_DISABLE_TESTS }, + { "id", required_argument, NULL, ARG_ID }, + { "non-interactive", no_argument, NULL, ARG_NON_INTERACTIVE }, + { "target", required_argument, NULL, ARG_TARGET }, + { "help", no_argument, NULL, 'h' }, + { NULL }, + }; + int c; + + for (;;) { + c = getopt_long(argc, argv, "h", options, NULL); + if (c < 0) + break; + + switch (c) { + case 'h': + help(); + + case ARG_DISABLE_CCACHE: + config->flags |= PAKFIRE_BUILD_DISABLE_CCACHE; + break; + + case ARG_DISABLE_SNAPSHOT: + config->flags |= PAKFIRE_BUILD_DISABLE_SNAPSHOT; + break; + + case ARG_DISABLE_TESTS: + config->flags |= PAKFIRE_BUILD_DISABLE_TESTS; + break; + + case ARG_ID: + config->id = optarg; + break; + + case ARG_NON_INTERACTIVE: + config->flags &= ~PAKFIRE_BUILD_INTERACTIVE; + break; + + case ARG_TARGET: + config->target = optarg; + break; + + case '?': + return -EINVAL; + + default: + break; + } + } + + return 0; +} + +int cli_build(struct pakfire* pakfire, int argc, char* argv[]) { + struct pakfire_build* build = NULL; + struct config config = { + .id = NULL, + .target = NULL, + .flags = PAKFIRE_BUILD_INTERACTIVE, + }; + int r; + + // Parse commandline + r = parse_argv(&config, argc, argv); + if (r) + return r; + + // Setup the build environment + r = pakfire_build_create(&build, pakfire, config.id, config.flags); + if (r) { + fprintf(stderr, "Could not setup the build environment: %m\n"); + goto ERROR; + } + + // Set target + if (config.target) { + r = pakfire_build_set_target(build, config.target); + if (r) { + fprintf(stderr, "Could not set target directory %s: %m\n", config.target); + goto ERROR; + } + } + + // Process all packages + for (int i = optind; i < argc; i++) { + // XXX implement dist + + // Run the build + r = pakfire_build_exec(build, argv[i]); + if (r) { + fprintf(stderr, "Could not build %s\n", argv[i]); + goto ERROR; + } + } + +ERROR: + if (build) + pakfire_build_unref(build); + + return r; +} diff --git a/src/cli/lib/build.h b/src/cli/lib/build.h new file mode 100644 index 000000000..8e1220895 --- /dev/null +++ b/src/cli/lib/build.h @@ -0,0 +1,28 @@ +/*############################################################################# +# # +# Pakfire - The IPFire package management system # +# Copyright (C) 2023 Pakfire development team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +#############################################################################*/ + +#ifndef PAKFIRE_CLI_BUILD_H +#define PAKFIRE_CLI_BUILD_H + +#include + +int cli_build(struct pakfire* pakfire, int argc, char* argv[]); + +#endif /* PAKFIRE_CLI_BUILD_H */ diff --git a/src/cli/pakfire-builder.c b/src/cli/pakfire-builder.c index fa57051dd..86fc4f503 100644 --- a/src/cli/pakfire-builder.c +++ b/src/cli/pakfire-builder.c @@ -28,6 +28,7 @@ #include #include +#include "lib/build.h" #include "lib/clean.h" #include "lib/command.h" #include "lib/dist.h" @@ -56,6 +57,7 @@ struct config { static int cli_main(struct pakfire* pakfire, int argc, char* argv[]) { static const struct command commands[] = { + { "build", 0, cli_build }, { "clean", 0, cli_clean }, { "dist", 0, cli_dist }, { "info", 0, cli_info },