Hi Dmitry,

> > 1. At line 4260, what's the place where $modules variable gets assigned?
> 
> Indeed the comments for function func_emit_autoconf_snippets are misleading:
> This functions receives two module lists:
>   $modules (implicit),
>   $1 (explicit: first argument).
> 
> Where does $modules come from?
>   - For the invocation in func_import, line 5640 and 5659
>     it is set at line 5298. But I'm not sure this was intended this way, maybe
>     another list should be used instead of "$main_modules"?
>   - For the invocation in func_create_testdir, line 6288 and 6290 and 6402 
> and 6404 and 6417
>     it does not appear to be set in a consistent and correct way.
>     (It is set differently if $single_configure and ! $single_configure.)
>     This is probably a bug.
> The set of modules that _ought_ to be used here is the set of modules
> being used for the current configure file. That's my current understanding.
> But I'd really need to look at a couple of test cases in order to
> firmly answer the question.

I've understood it now: the code in func_create_testdir was not really a bug,
because --conditional-dependencies was not allowed in this case anyway.

Here's the patch that implements --conditional-dependencies also with
--with-tests.

Bruno
>From 589e96475f8f2d21a83405ab0672ce95091b80e5 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Fri, 29 Dec 2017 00:29:23 +0100
Subject: [PATCH] gnulib-tool: Make --conditional-dependencies work better.

Reported by Dmitry Selyutin <ghostman...@gmail.com>.

* gnulib-tool (Options): Don't reject the combination of
--conditional-dependencies with --with-tests.
(func_emit_autoconf_snippets): Add argument referenceable_modules.
Don't reference $modules.
(func_import, func_create_testdir): Pass it.
---
 ChangeLog   | 10 ++++++++++
 gnulib-tool | 37 ++++++++++++++++++++-----------------
 2 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 7d7b10a..1e2e0fb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2017-12-28  Bruno Haible  <br...@clisp.org>
+
+	gnulib-tool: Make --conditional-dependencies work better.
+	Reported by Dmitry Selyutin <ghostman...@gmail.com>.
+	* gnulib-tool (Options): Don't reject the combination of
+	--conditional-dependencies with --with-tests.
+	(func_emit_autoconf_snippets): Add argument referenceable_modules.
+	Don't reference $modules.
+	(func_import, func_create_testdir): Pass it.
+
 2017-12-19  Paul Eggert  <egg...@cs.ucla.edu>
 
 	regex: use re_malloc etc. consistently
diff --git a/gnulib-tool b/gnulib-tool
index 22817c9..5f640e3 100755
--- a/gnulib-tool
+++ b/gnulib-tool
@@ -1505,10 +1505,6 @@ func_determine_path_separator
   esac
   # Now the only possible values of "$inctests" are true and false
   # (or blank but then it is irrelevant).
-  if test "$cond_dependencies" = true && test "$inctests" = true; then
-    echo "gnulib-tool: option --conditional-dependencies is not supported with --with-tests" 1>&2
-    func_exit 1
-  fi
 
   # Determine the minimum supported autoconf version from the project's
   # configure.ac.
@@ -4231,7 +4227,7 @@ func_emit_autoconf_snippet ()
   fi
 }
 
-# func_emit_autoconf_snippets modules verifier toplevel disable_libtool disable_gettext
+# func_emit_autoconf_snippets modules referenceable_modules verifier toplevel disable_libtool disable_gettext
 # collects and emit the autoconf snippets of a set of modules.
 # Input:
 # - local_gnulib_path  from --local-dir
@@ -4240,6 +4236,7 @@ func_emit_autoconf_snippet ()
 # - sed_replace_include_guard_prefix
 #                     sed expression for resolving ${gl_include_guard_prefix}
 # - modules           the list of modules.
+# - referenceable_modules  the list of modules which may be referenced as dependencies.
 # - verifier          one of func_verify_module, func_verify_nontests_module,
 #                     func_verify_tests_module. It selects the subset of
 #                     $modules to consider.
@@ -4252,12 +4249,13 @@ func_emit_autoconf_snippet ()
 #                     invocations.
 func_emit_autoconf_snippets ()
 {
-  verifier="$2"
-  toplevel="$3"
-  disable_libtool="$4"
-  disable_gettext="$5"
+  referenceable_modules="$2"
+  verifier="$3"
+  toplevel="$4"
+  disable_libtool="$5"
+  disable_gettext="$6"
   if test "$cond_dependencies" = true; then
-    for m in $modules; do echo $m; done | LC_ALL=C sort -u > "$tmp"/modules
+    for m in $referenceable_modules; do echo $m; done | LC_ALL=C sort -u > "$tmp"/modules
     # Emit the autoconf code for the unconditional modules.
     for module in $1; do
       eval $verifier
@@ -5637,7 +5635,7 @@ s,//*$,/,'
     if test -n "$witness_c_macro"; then
       echo "  m4_pushdef([gl_MODULE_INDICATOR_CONDITION], [$witness_c_macro])"
     fi
-    func_emit_autoconf_snippets "$main_modules" func_verify_module true false true
+    func_emit_autoconf_snippets "$main_modules" "$main_modules" func_verify_module true false true
     if test -n "$witness_c_macro"; then
       echo "  m4_popdef([gl_MODULE_INDICATOR_CONDITION])"
     fi
@@ -5656,7 +5654,7 @@ s,//*$,/,'
     echo "  AC_SUBST([${macro_prefix}tests_WITNESS])"
     echo "  gl_module_indicator_condition=\$${macro_prefix}tests_WITNESS"
     echo "  m4_pushdef([gl_MODULE_INDICATOR_CONDITION], [\$gl_module_indicator_condition])"
-    func_emit_autoconf_snippets "$testsrelated_modules" func_verify_module true true true
+    func_emit_autoconf_snippets "$testsrelated_modules" "$main_modules $testsrelated_modules" func_verify_module true true true
     echo "  m4_popdef([gl_MODULE_INDICATOR_CONDITION])"
     func_emit_initmacro_end ${macro_prefix}tests
     # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
@@ -6081,6 +6079,11 @@ func_create_testdir ()
     func_modules_add_dummy
   fi
 
+  # Note:
+  # If $single_configure, we use the module lists $main_modules and
+  # $testsrelated_modules; $modules is merely a temporary variable.
+  # Whereas if ! $configure, the module list is $modules.
+
   # Show banner notice of every module.
   if $single_configure; then
     modules="$main_modules"
@@ -6285,9 +6288,9 @@ func_create_testdir ()
        # autoconf snippets. It's cleanest to put those of the library before
        # those of the tests.
        echo "gl_source_base='../$sourcebase'"
-       func_emit_autoconf_snippets "$modules" func_verify_nontests_module false false false
+       func_emit_autoconf_snippets "$modules" "$modules" func_verify_nontests_module false false false
        echo "gl_source_base='.'"
-       func_emit_autoconf_snippets "$modules" func_verify_tests_module false false false
+       func_emit_autoconf_snippets "$modules" "$modules" func_verify_tests_module false false false
        func_emit_initmacro_end $macro_prefix
        # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
        # created using libtool, because libtool already handles the dependencies.
@@ -6399,9 +6402,9 @@ func_create_testdir ()
    func_emit_initmacro_start $macro_prefix
    echo "gl_source_base='$sourcebase'"
    if $single_configure; then
-     func_emit_autoconf_snippets "$main_modules" func_verify_module true false false
+     func_emit_autoconf_snippets "$main_modules" "$main_modules" func_verify_module true false false
    else
-     func_emit_autoconf_snippets "$modules" func_verify_nontests_module true false false
+     func_emit_autoconf_snippets "$modules" "$modules" func_verify_nontests_module true false false
    fi
    func_emit_initmacro_end $macro_prefix
    if $single_configure; then
@@ -6414,7 +6417,7 @@ func_create_testdir ()
      echo "  AC_SUBST([${macro_prefix}tests_WITNESS])"
      echo "  gl_module_indicator_condition=\$${macro_prefix}tests_WITNESS"
      echo "  m4_pushdef([gl_MODULE_INDICATOR_CONDITION], [\$gl_module_indicator_condition])"
-     func_emit_autoconf_snippets "$testsrelated_modules" func_verify_module true false false
+     func_emit_autoconf_snippets "$testsrelated_modules" "$main_modules $testsrelated_modules" func_verify_module true false false
      echo "  m4_popdef([gl_MODULE_INDICATOR_CONDITION])"
      func_emit_initmacro_end ${macro_prefix}tests
    fi
-- 
2.7.4

Reply via email to