Optional dependency on bluez-libs generates circular dependency

Hello, I am currently using OpenWRT master (f6e9f23771) and according to [1], I have created a package with optional dependency on bluez-libs. It however leads to a circular dependency injected by OpenWRT build system with the following error:

Collecting package info: done
tmp/.config-package.in:131096:error: recursive dependency detected!
For a resolution refer to Documentation/kbuild/kconfig-language.txt
subsection "Kconfig recursive dependency limitations"
tmp/.config-package.in:131096:	symbol PACKAGE_test depends on TEST_OPTION
For a resolution refer to Documentation/kbuild/kconfig-language.txt
subsection "Kconfig recursive dependency limitations"
tmp/.config-package.in:131113:	symbol TEST_OPTION depends on PACKAGE_test

If I do the same with a different package (e.g. glib2 instead of bluez-libs) then there is no such circular dependency generated. Can you please help me to do it right or explain me, what or why I am doing wrong?

[1] https://openwrt.org/docs/guide-developer/packages#adding_configuration_options

Here follows a minimal package (into packages/utils/test/Makefile) for reproducing. I assume to install the feed feeds/packages that contains bluez-libs package.

include $(TOPDIR)/rules.mk

PKG_NAME:=test
PKG_VERSION:=1
PKG_RELEASE:=1

include $(INCLUDE_DIR)/host-build.mk
include $(INCLUDE_DIR)/package.mk
 
define Package/test
  SECTION:=utils
  CATEGORY:=Utilities
  DEPENDS:=+TEST_OPTION:bluez-libs
  TITLE:=Test
endef

define Package/test/config
config TEST_OPTION
 	depends on PACKAGE_test
	bool "option"
endef

$(eval $(call BuildPackage,test))

After my investigations when looking into tmp/.config-package.in:

config PACKAGE_test
	tristate "test................................................................ Test"
	default y if DEFAULT_test
	default m if ALL
	depends on !(TEST_OPTION) || USB_SUPPORT
	select PACKAGE_bluez-libs if TEST_OPTION
	select PACKAGE_librt if USE_GLIBC
	depends on !(TEST_OPTION && LINUX_4_14) || !LINUX_3_18
	select PACKAGE_libc
	depends on !(TEST_OPTION && USE_RFKILL) || USE_RFKILL
	select PACKAGE_libpthread if USE_GLIBC
	select PACKAGE_libssp if GCC_LIBSSP
	help
	 Test

I found out that OpenWRT is generating some dependency logic, see:

depends on !(TEST_OPTION && LINUX_4_14) || !LINUX_3_18
depends on !(TEST_OPTION && USE_RFKILL) || USE_RFKILL

that is probably important but it conflicts with my "depends on PACKAGE_test" from Package/test/config. The problem is that this is automatical and I cannot influence it in any way (or?). I believe that these two lines should be part the TEST_OPTION and not of the whole package.

If I omit my "depends on..." from the TEST_OPTION then the option is confusingly shown even when the package is deselected. However, this "depends..." is also shown in the example in section "Adding configuration options" [1]. So, is it wrong or how should I understand it?

Single config items indeed shouldn't depend on their package to avoid this kind of circular dependencies. Note that your linked example uses kconfig menu sections and adds the dependencies to them instead. Maybe you could try the same and see if it helps.

Did you mean this?

menu "Configuration"
	depends on PACKAGE_test

	config TEST_OPTION
		bool "option"
endmenu

No, this does not prevent the circular dependency because the particular config entries implicitly depend on their menus. Nor adding "MENU:=1" to the package definition does change anything.