mirror of
https://gitlab.freedesktop.org/pkg-config/pkg-config.git
synced 2026-05-05 06:27:59 +02:00
Enforce exclusive output options
Currently, any output option (e.g., --version or --libs) will be set as valid and what's output is at the mercy of the order of the output handling code in main(). However, most combinations of output would make no sense to be used together. For example, mixing --modversion and --print-provides provides no way to differentiate between the output from the options. Further, mixing --variable and --cflags currently causes an error because there's no space separating the option outputs. Instead, keep track of when an output option has been set and ignore subsequent output options. There are currently two exceptions: 1. Any combination of --cflags* and --libs* are allowed. 2. Both --print-requires and --print-requires-private can be used together as the user may just not care which is private. Freedesktop #54391 (https://bugs.freedesktop.org/show_bug.cgi?id=54391)
This commit is contained in:
parent
469a3d6366
commit
d1b7dd42d1
2 changed files with 46 additions and 0 deletions
|
|
@ -37,3 +37,18 @@ run_test --print-requires-private requires-test
|
|||
RESULT="sub1 Subdirectory package 1 - Test package 1 for subdirectory
|
||||
sub2 Subdirectory package 2 - Test package 2 for subdirectory"
|
||||
PKG_CONFIG_LIBDIR="$srcdir/sub" run_test --list-all
|
||||
|
||||
# Check handling when multiple incompatible options are set
|
||||
RESULT="Ignoring incompatible output option \"--modversion\"
|
||||
$PACKAGE_VERSION"
|
||||
run_test --version --modversion simple
|
||||
|
||||
RESULT="Ignoring incompatible output option \"--version\"
|
||||
1.0.0"
|
||||
run_test --modversion --version simple
|
||||
|
||||
# --print-requires/--print-requires-private allowed together
|
||||
RESULT="public-dep >= 1
|
||||
private-dep >= 1"
|
||||
run_test --print-requires --print-requires-private requires-test
|
||||
run_test --print-requires-private --print-requires requires-test
|
||||
|
|
|
|||
31
main.c
31
main.c
|
|
@ -59,6 +59,7 @@ static gboolean want_variable_list = FALSE;
|
|||
static gboolean want_debug_spew = FALSE;
|
||||
static gboolean want_verbose_errors = FALSE;
|
||||
static gboolean want_stdout_errors = FALSE;
|
||||
static gboolean output_opt_set = FALSE;
|
||||
|
||||
void
|
||||
debug_spew (const char *format, ...)
|
||||
|
|
@ -155,6 +156,35 @@ static gboolean
|
|||
output_opt_cb (const char *opt, const char *arg, gpointer data,
|
||||
GError **error)
|
||||
{
|
||||
/* only allow one output mode, with a few exceptions */
|
||||
if (output_opt_set)
|
||||
{
|
||||
gboolean bad_opt = TRUE;
|
||||
|
||||
/* multiple flag options (--cflags --libs-only-l) allowed */
|
||||
if (pkg_flags != 0 &&
|
||||
(strcmp (opt, "--libs") == 0 ||
|
||||
strcmp (opt, "--libs-only-l") == 0 ||
|
||||
strcmp (opt, "--libs-only-other") == 0 ||
|
||||
strcmp (opt, "--libs-only-L") == 0 ||
|
||||
strcmp (opt, "--cflags") == 0 ||
|
||||
strcmp (opt, "--cflags-only-I") == 0 ||
|
||||
strcmp (opt, "--cflags-only-other") == 0))
|
||||
bad_opt = FALSE;
|
||||
|
||||
/* --print-requires and --print-requires-private allowed */
|
||||
if ((want_requires && strcmp (opt, "--print-requires-private") == 0) ||
|
||||
(want_requires_private && strcmp (opt, "--print-requires") == 0))
|
||||
bad_opt = FALSE;
|
||||
|
||||
if (bad_opt)
|
||||
{
|
||||
fprintf (stderr, "Ignoring incompatible output option \"%s\"\n",
|
||||
opt);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp (opt, "--version") == 0)
|
||||
want_my_version = TRUE;
|
||||
else if (strcmp (opt, "--modversion") == 0)
|
||||
|
|
@ -192,6 +222,7 @@ output_opt_cb (const char *opt, const char *arg, gpointer data,
|
|||
else
|
||||
return FALSE;
|
||||
|
||||
output_opt_set = TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue