Skip to content

duneproject does not check whether a module exists correctly

When listing dependent dune modules in duneproject, the script does not check correctly whether these modules exist. So non-existing module names are accepted. As far as I understand the code, this is not supposed to be the correct behavior.

The problem is in the modulesexist() function, that performs a pkg-config test where the error code is interpreted in the wrong way:

      if [ "$found" = "0" ]; then
          # Module not found in list, try pkg-config
          pkg-config $module &> /dev/null
          found=$?
      fi

But, pkg-conofig returns 0 in case that the module was found. While the return value variable allfound in modulesexist should be 0 in case that all modules are found, the local variable found should be 1 if the current module is found. This is a bit irritating. A solution could be to revert the meaning of found (and maybe rename the variable to notfound), or by changing the pkg-config test to something similar to

      if [ "$found" = "0" ]; then
          # Module not found in list, try pkg-config
          set +e
          pkg-config $module &> /dev/null
          if [ "$?" = 0 ]; then
            found=1
          fi
          set -e
      fi