1
0
Fork 0
mirror of https://github.com/pygos/pkg-utils.git synced 2024-11-24 21:40:43 +01:00

Add options for default repo dir & default install dir

This should make working with the pkg program in the toolchain build
system much cleaner.

Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
This commit is contained in:
David Oberhollenzer 2019-04-28 16:36:10 +02:00
parent 5df2d5f730
commit f95f02f6be
5 changed files with 57 additions and 14 deletions

View file

@ -39,6 +39,21 @@ UL_WARN_ADD([-pedantic])
AC_SUBST([WARN_CFLAGS])
##### configuration options #####
AC_DEFINE([REPODIR], ["./"], [Default package repository directory])
AC_DEFINE([INSTALLROOT], ["./"], [Default package installation root])
AC_ARG_WITH([repo-dir],
[AS_HELP_STRING([--with-repo-dir],
[Set the default package repository directory])],
[AC_DEFINE_UNQUOTED([REPODIR], "$withval")])
AC_ARG_WITH([install-root],
[AS_HELP_STRING([--with-install-root],
[Set the default package installation directory])],
[AC_DEFINE_UNQUOTED([INSTALLROOT], "$withval")])
##### search for dependencies #####
have_zlib="no"

View file

@ -9,6 +9,7 @@
#include "depgraph.h"
#include "command.h"
#include "config.h"
static const struct option long_opts[] = {
{ "no-dependencies", no_argument, NULL, 'd' },
@ -37,7 +38,7 @@ static void print_dot_graph(struct pkg_dep_list *list)
static int cmd_depgraph(int argc, char **argv)
{
int i, repofd = AT_FDCWD, ret = EXIT_FAILURE;
int i, repofd = -1, ret = EXIT_FAILURE;
struct pkg_dep_list list;
bool resolve_deps = true;
@ -53,7 +54,7 @@ static int cmd_depgraph(int argc, char **argv)
resolve_deps = false;
break;
case 'R':
if (repofd != AT_FDCWD) {
if (repofd != -1) {
fputs("repo specified more than once\n",
stderr);
tell_read_help(argv[0]);
@ -71,6 +72,14 @@ static int cmd_depgraph(int argc, char **argv)
}
}
if (repofd == -1) {
repofd = open(REPODIR, O_RDONLY | O_DIRECTORY);
if (repofd < 0) {
perror(REPODIR);
goto out;
}
}
for (i = optind; i < argc; ++i) {
if (append_pkg(&list, argv[i]) == NULL)
goto out;
@ -84,7 +93,7 @@ static int cmd_depgraph(int argc, char **argv)
print_dot_graph(&list);
ret = EXIT_SUCCESS;
out:
if (repofd != AT_FDCWD)
if (repofd != -1)
close(repofd);
pkg_list_cleanup(&list);
return ret;
@ -101,6 +110,7 @@ static command_t depgraph = {
"Possible options:\n"
" --repo-dir, -R <path> Specify the input repository path to fetch the\n"
" packages from.\n"
" If not set, defaults to " REPODIR ".\n"
" --no-dependencies, -d Do not resolve dependencies, only process the\n"
" packages listed on the command line.\n",
.run_cmd = cmd_depgraph,

View file

@ -11,6 +11,7 @@
#include "util/util.h"
#include "depgraph.h"
#include "command.h"
#include "config.h"
enum {
INSTALL_MODE_INSTALL = 0,
@ -95,8 +96,8 @@ static int list_files(int repofd, const char *rootdir, TOC_FORMAT format,
static int cmd_install(int argc, char **argv)
{
int i, rootfd = AT_FDCWD, repofd = AT_FDCWD, flags = 0;
int ret = EXIT_FAILURE, mode = INSTALL_MODE_INSTALL;
int i, rootfd = -1, repofd = -1, flags = 0;
TOC_FORMAT format = TOC_FORMAT_PRETTY;
const char *rootdir = NULL;
struct pkg_dep_list list;
@ -131,7 +132,7 @@ static int cmd_install(int argc, char **argv)
}
break;
case 'R':
if (repofd != AT_FDCWD) {
if (repofd != -1) {
fputs("repo specified more than once\n",
stderr);
tell_read_help(argv[0]);
@ -144,7 +145,7 @@ static int cmd_install(int argc, char **argv)
}
break;
case 'r':
if (rootfd != AT_FDCWD) {
if (rootfd != -1) {
fputs("root specified more than once\n",
stderr);
tell_read_help(argv[0]);
@ -180,6 +181,22 @@ static int cmd_install(int argc, char **argv)
}
}
if (repofd == -1) {
repofd = open(REPODIR, O_RDONLY | O_DIRECTORY);
if (repofd < 0) {
perror(REPODIR);
goto out;
}
}
if (rootfd == -1) {
rootfd = open(INSTALLROOT, O_RDONLY | O_DIRECTORY);
if (rootfd < 0) {
perror(INSTALLROOT);
goto out;
}
}
for (i = optind; i < argc; ++i) {
if (append_pkg(&list, argv[i]) == NULL)
goto out;
@ -209,9 +226,9 @@ static int cmd_install(int argc, char **argv)
ret = EXIT_SUCCESS;
out:
if (rootfd != AT_FDCWD)
if (rootfd != -1)
close(rootfd);
if (repofd != AT_FDCWD)
if (repofd != -1)
close(repofd);
pkg_list_cleanup(&list);
return ret;
@ -229,11 +246,12 @@ static command_t install = {
"Possible options:\n"
" --repo-dir, -R <path> Specify the input repository path to fetch the\n"
" packages from.\n"
" --root, -r <path> A root directory to unpack the package. Default\n"
" if not set is the current working directory.\n"
" If not set, defaults to " REPODIR ".\n"
" --root, -r <path> A root directory to unpack the package.\n"
" If not set, defaults to " INSTALLROOT ".\n"
" --no-chown, -o Do not change ownership of the extracted data.\n"
" Keep the uid/gid of the user who runs the \n"
" program."
" program.\n"
" --no-chmod, -m Do not change permission flags of the extarcted\n"
" data. Use 0644 for all files and 0755 for all\n"
" directories.\n"

View file

@ -65,9 +65,7 @@ static int cmd_pack(int argc, char **argv)
}
if (repodir == NULL) {
fputs("missing argument: repository directory\n", stderr);
tell_read_help(argv[0]);
return EXIT_FAILURE;
repodir = REPODIR;
}
if (optind < argc)
@ -117,6 +115,7 @@ static command_t pack = {
" --file-list, -l <path> Specify a file containing a list of input files.\n"
" --repo-dir, -r <path> Specify the output repository path to store the\n"
" package in.\n"
" If not set, defaults to " REPODIR ".\n"
" --description, -d <path> Specify a file containing a description of the\n"
" package, including information such as package\n"
" dependencies, the actual package name, etc.\n"

View file

@ -25,6 +25,7 @@
#include "pkg/pkgformat.h"
#include "pkg/pkgwriter.h"
#include "command.h"
#include "config.h"
typedef struct dependency_t {
struct dependency_t *next;