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]) 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 ##### ##### search for dependencies #####
have_zlib="no" have_zlib="no"

View File

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

View File

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

View File

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

View File

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