Skip to contentSkip to conversation

normal: Move common datetime functions out of the normal module

PATCH In review Javier Martinez Canillas 2 participants 2 messages Feb 14, 2020 – Feb 18, 2020 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 normal: Move common datetime functions out of the normal module

The common datetime helper functions are currently included in the normal module, but this makes any other module that calls these functions to have a dependency with the normal module only for this reason.

Since the normal module does a lot of stuff, it calls functions from other modules. But since other modules may depend on it for calling the datetime helpers, this could lead to circular dependencies between modules.

As an example, when platform == xen the grub_get_datetime() function from the datetime module calls to the grub_unixtime2datetime() helper function from the normal module. Which leads to the following module dependency:

    datetime -> normal

and send_dhcp_packet() from the net module calls the grub_get_datetime() function, which leads to the following module dependency:

    net -> datetime -> normal

but that means that the normal module is not allowed to depend on net or any other module that depends on it due the transitive dependency caused by datetime. A recent patch attempted to add support to fetch the config file over the network, which leads to the following circular dependency:

    normal -> net -> datetime -> normal

So having the datetime helpers in the normal module makes it quite fragile and easy to add circular dependencies like these, that break the build due the genmoddep.awk script catching the issues.

Fix this by taking the datetime helper functions out of the normal module and instead add them to the datetime module itself. Besides fixing these issues, it makes more sense to have these helper functions there anyways.

---
Hello Daniel,

I dig into the error you mentioned was happening when trying to build the "[PATCH v6 0/5] Search for specific config files using UUID, MAC and IP" patch-set.

This was caused by making the normal module to depend on the net module and this module in turn depending on normal through the datetime module.

The patch fixes the issue for me, after this I can successufully build the patch-set with the --with-platform=xen configure option.

Best regards,
Javier

 Makefile.util.def                    | 2 +-
 grub-core/Makefile.core.def          | 2 +-
 grub-core/{normal => lib}/datetime.c | 0
 3 files changed, 2 insertions(+), 2 deletions(-)
 rename grub-core/{normal => lib}/datetime.c (100%)
Makefile.util.def +1 -1
index 94336392b9e..174877c41b8 100644
@@ -141,7 +141,7 @@ library = {
   common = grub-core/lib/crc.c;
   common = grub-core/lib/adler32.c;
   common = grub-core/lib/crc64.c;
-  common = grub-core/normal/datetime.c;
+  common = grub-core/lib/datetime.c;
   common = grub-core/normal/misc.c;
   common = grub-core/partmap/acorn.c;
   common = grub-core/partmap/amiga.c;
grub-core/Makefile.core.def +1 -1
index a0507a1fa4c..91297e4ebfe 100644
@@ -1687,6 +1687,7 @@ module = {
 
 module = {
   name = datetime;
+  common = lib/datetime.c;
   cmos = lib/cmos_datetime.c;
   efi = lib/efi/datetime.c;
   uboot = lib/dummy/datetime.c;
@@ -1926,7 +1927,6 @@ module = {
   common = normal/autofs.c;
   common = normal/color.c;
   common = normal/completion.c;
-  common = normal/datetime.c;
   common = normal/menu.c;
   common = normal/menu_entry.c;
   common = normal/menu_text.c;
grub-core/lib/datetime.c renamed from grub-core/normal/datetime.c +0 -0
similarity index 100%
rename from grub-core/normal/datetime.c
rename to grub-core/lib/datetime.c
Signature · 1 line
2.24.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 30 lines · Javier Martinez Canillas

The common datetime helper functions are currently included in the normal module, but this makes any other module that calls these functions to have a dependency with the normal module only for this reason.

Since the normal module does a lot of stuff, it calls functions from other modules. But since other modules may depend on it for calling the datetime helpers, this could lead to circular dependencies between modules.

As an example, when platform == xen the grub_get_datetime() function from the datetime module calls to the grub_unixtime2datetime() helper function from the normal module. Which leads to the following module dependency:

    datetime -> normal

and send_dhcp_packet() from the net module calls the grub_get_datetime() function, which leads to the following module dependency:

    net -> datetime -> normal

but that means that the normal module is not allowed to depend on net or any other module that depends on it due the transitive dependency caused by datetime. A recent patch attempted to add support to fetch the config file over the network, which leads to the following circular dependency:

    normal -> net -> datetime -> normal

So having the datetime helpers in the normal module makes it quite fragile and easy to add circular dependencies like these, that break the build due the genmoddep.awk script catching the issues.

Quoted 6 lines

Fix this by taking the datetime helper functions out of the normal module and instead add them to the datetime module itself. Besides fixing these issues, it makes more sense to have these helper functions there anyways.

...and pushed with the rest of your patches...

Thank you for doing the work!

Daniel