Skip to contentSkip to conversation

Track explicit module dependencies in Makefile.core.def

RFC PATCH Superseded Oliver Steffen 3 participants 3 messages Feb 22, 2024 – Feb 23, 2024

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 Track explicit module dependencies in Makefile.core.def

Add a new keyword, "depends", to the module definition syntax used in Makefile.core.def. This allows specifying explicit module dependencies together with the module definition.

Do not track the "extra_deps.lst" file in the repository anymore, it is now auto-generated.

Make use of this new keyword in the bli module definition.

---
 .gitignore                  | 1 -
 conf/Makefile.common        | 1 +
 gentpl.py                   | 7 +++++++
 grub-core/Makefile.am       | 7 +++++--
 grub-core/Makefile.core.def | 1 +
 grub-core/extra_deps.lst    | 1 -
 grub-core/genmoddep.awk     | 2 +-
 7 files changed, 15 insertions(+), 5 deletions(-)
 delete mode 100644 grub-core/extra_deps.lst
.gitignore +0 -1
index 4d0dfb700..11fcecf5c 100644
@@ -11,7 +11,6 @@
 *.img
 *.log
 *.lst
-!/grub-core/extra_deps.lst
 *.marker
 *.mod
 *.o
conf/Makefile.common +1 -0
index b8f216f6c..c60f55386 100644
@@ -111,6 +111,7 @@ MOD_FILES =
 MODULE_FILES =
 MARKER_FILES =
 KERNEL_HEADER_FILES =
+EXTRA_DEPS =
 
 bin_SCRIPTS =
 bin_PROGRAMS =
gentpl.py +7 -0
index bfab2113a..3b12eca6c 100644
@@ -631,6 +631,9 @@ def platform_values(defn, platform, suffix):
 def extra_dist(defn):
     return foreach_value(defn, "extra_dist", lambda value: value + " ")
 
+def extra_dep(defn):
+    return foreach_value(defn, "depends", lambda value: value + " ")
+
 def platform_sources(defn, p): return platform_values(defn, p, "")
 def platform_nodist_sources(defn, p): return platform_values(defn, p, "_nodist")
 
@@ -699,6 +702,10 @@ def module(defn, platform):
     gvar_add("MOD_FILES", name + ".mod")
     gvar_add("MARKER_FILES", name + ".marker")
     gvar_add("CLEANFILES", name + ".marker")
+
+    for dep in defn.find_all("depends"):
+        gvar_add("EXTRA_DEPS", "depends " + name + " " + dep + ":")
+
     output("""
 """ + name + """.marker: $(""" + cname(defn) + """_SOURCES) $(nodist_""" + cname(defn) + """_SOURCES)
 	$(TARGET_CPP) -DGRUB_LST_GENERATOR $(CPPFLAGS_MARKER) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(""" + cname(defn) + """_CPPFLAGS) $(CPPFLAGS) $^ > [email protected] || (rm -f $@; exit 1)
grub-core/Makefile.am +5 -2
index f18550c1c..5df36744e 100644
@@ -454,7 +454,10 @@ crypto.lst: $(srcdir)/lib/libgcrypt-grub/cipher/crypto.lst
 platform_DATA += crypto.lst
 CLEANFILES += crypto.lst
 
-syminfo.lst: gensyminfo.sh kernel_syms.lst $(top_srcdir)/grub-core/extra_deps.lst $(MODULE_FILES)
+extra_deps.lst:
+	@echo $(EXTRA_DEPS) | sed "s/\s*:\s*/\n/g" > $@
+
+syminfo.lst: gensyminfo.sh kernel_syms.lst extra_deps.lst $(MODULE_FILES)
 	cat kernel_syms.lst $(top_srcdir)/grub-core/extra_deps.lst > [email protected]
 	for m in $(MODULE_FILES); do \
 	  sh $< $$m >> [email protected] || exit 1; \
@@ -465,7 +468,7 @@ syminfo.lst: gensyminfo.sh kernel_syms.lst $(top_srcdir)/grub-core/extra_deps.ls
 moddep.lst: syminfo.lst genmoddep.awk video.lst
 	cat $< | sort | $(AWK) -f $(srcdir)/genmoddep.awk > $@ || (rm -f $@; exit 1)
 platform_DATA += moddep.lst
-CLEANFILES += config.log syminfo.lst moddep.lst
+CLEANFILES += config.log syminfo.lst moddep.lst extra_deps.lst
 
 $(MOD_FILES): %.mod : genmod.sh moddep.lst %.module$(EXEEXT) build-grub-module-verifier$(BUILD_EXEEXT)
 	TARGET_OBJ2ELF=@TARGET_OBJ2ELF@ sh $^ $@
grub-core/Makefile.core.def +1 -0
index 1571421d7..142faeff0 100644
@@ -2594,4 +2594,5 @@ module = {
   name = bli;
   efi = commands/bli.c;
   enable = efi;
+  depends = part_gpt;
 };
grub-core/extra_deps.lst deleted +0 -1
deleted file mode 100644
index f44ad6a0c..000000000
@@ -1 +0,0 @@
-depends bli part_gpt
grub-core/genmoddep.awk +1 -1
index cc987a53a..ab457cb2b 100644
@@ -35,7 +35,7 @@ BEGIN {
     for (i = 3; i <= NF; i++) {
       modtab[$2] = modtab[$2] " " $i;
     }
-  }
+  } else if ($1 == "") {} #Skip empty lines
   else {
     printf "error: %u: unrecognized input format\n", NR >"/dev/stderr";
     error++;
Signature · 7 lines
2.43.2


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Reviewed-by on v1 1/1
#1 lore raw

Adding Vladimir...

Quoted 10 lines · Oliver Steffen

Add a new keyword, "depends", to the module definition syntax used in Makefile.core.def. This allows specifying explicit module dependencies together with the module definition.

Do not track the "extra_deps.lst" file in the repository anymore, it is now auto-generated.

Make use of this new keyword in the bli module definition.

But I would want to hear Vladimir's opinion too...

Quoted 107 lines
---
 .gitignore                  | 1 -
 conf/Makefile.common        | 1 +
 gentpl.py                   | 7 +++++++
 grub-core/Makefile.am       | 7 +++++--
 grub-core/Makefile.core.def | 1 +
 grub-core/extra_deps.lst    | 1 -
 grub-core/genmoddep.awk     | 2 +-
 7 files changed, 15 insertions(+), 5 deletions(-)
 delete mode 100644 grub-core/extra_deps.lst
.gitignore +0 -1
index 4d0dfb700..11fcecf5c 100644
@@ -11,7 +11,6 @@
 *.img
 *.log
 *.lst
-!/grub-core/extra_deps.lst
 *.marker
 *.mod
 *.o
conf/Makefile.common +1 -0
index b8f216f6c..c60f55386 100644
@@ -111,6 +111,7 @@ MOD_FILES =
 MODULE_FILES =
 MARKER_FILES =
 KERNEL_HEADER_FILES =
+EXTRA_DEPS =
 
 bin_SCRIPTS =
 bin_PROGRAMS =
gentpl.py +7 -0
index bfab2113a..3b12eca6c 100644
@@ -631,6 +631,9 @@ def platform_values(defn, platform, suffix):
 def extra_dist(defn):
     return foreach_value(defn, "extra_dist", lambda value: value + " ")
 
+def extra_dep(defn):
+    return foreach_value(defn, "depends", lambda value: value + " ")
+
 def platform_sources(defn, p): return platform_values(defn, p, "")
 def platform_nodist_sources(defn, p): return platform_values(defn, p, "_nodist")
 
@@ -699,6 +702,10 @@ def module(defn, platform):
     gvar_add("MOD_FILES", name + ".mod")
     gvar_add("MARKER_FILES", name + ".marker")
     gvar_add("CLEANFILES", name + ".marker")
+
+    for dep in defn.find_all("depends"):
+        gvar_add("EXTRA_DEPS", "depends " + name + " " + dep + ":")
+
     output("""
 """ + name + """.marker: $(""" + cname(defn) + """_SOURCES) $(nodist_""" + cname(defn) + """_SOURCES)
 	$(TARGET_CPP) -DGRUB_LST_GENERATOR $(CPPFLAGS_MARKER) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(""" + cname(defn) + """_CPPFLAGS) $(CPPFLAGS) $^ > [email protected] || (rm -f $@; exit 1)
grub-core/Makefile.am +5 -2
index f18550c1c..5df36744e 100644
@@ -454,7 +454,10 @@ crypto.lst: $(srcdir)/lib/libgcrypt-grub/cipher/crypto.lst
 platform_DATA += crypto.lst
 CLEANFILES += crypto.lst
 
-syminfo.lst: gensyminfo.sh kernel_syms.lst $(top_srcdir)/grub-core/extra_deps.lst $(MODULE_FILES)
+extra_deps.lst:
+	@echo $(EXTRA_DEPS) | sed "s/\s*:\s*/\n/g" > $@
+
+syminfo.lst: gensyminfo.sh kernel_syms.lst extra_deps.lst $(MODULE_FILES)
 	cat kernel_syms.lst $(top_srcdir)/grub-core/extra_deps.lst > [email protected]
 	for m in $(MODULE_FILES); do \
 	  sh $< $$m >> [email protected] || exit 1; \
@@ -465,7 +468,7 @@ syminfo.lst: gensyminfo.sh kernel_syms.lst $(top_srcdir)/grub-core/extra_deps.ls
 moddep.lst: syminfo.lst genmoddep.awk video.lst
 	cat $< | sort | $(AWK) -f $(srcdir)/genmoddep.awk > $@ || (rm -f $@; exit 1)
 platform_DATA += moddep.lst
-CLEANFILES += config.log syminfo.lst moddep.lst
+CLEANFILES += config.log syminfo.lst moddep.lst extra_deps.lst
 
 $(MOD_FILES): %.mod : genmod.sh moddep.lst %.module$(EXEEXT) build-grub-module-verifier$(BUILD_EXEEXT)
 	TARGET_OBJ2ELF=@TARGET_OBJ2ELF@ sh $^ $@
grub-core/Makefile.core.def +1 -0
index 1571421d7..142faeff0 100644
@@ -2594,4 +2594,5 @@ module = {
   name = bli;
   efi = commands/bli.c;
   enable = efi;
+  depends = part_gpt;
 };
grub-core/extra_deps.lst deleted +0 -1
deleted file mode 100644
index f44ad6a0c..000000000
@@ -1 +0,0 @@
-depends bli part_gpt
grub-core/genmoddep.awk +0 -0
index cc987a53a..ab457cb2b 100644

grub-core/genmoddep.awk BEGIN { · line 41

Quoted 8 lines
grub-core/genmoddep.awk +1 -1
@@ -35,7 +35,7 @@ BEGIN {
     for (i = 3; i <= NF; i++) {
       modtab[$2] = modtab[$2] " " $i;
     }
-  }
+  } else if ($1 == "") {} #Skip empty lines
   else {
     printf "error: %u: unrecognized input format\n", NR >"/dev/stderr";
     error++;

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#2 lore raw
In reply to Oliver Steffen
Quoted 7 lines · Oliver Steffen

Add a new keyword, "depends", to the module definition syntax used in Makefile.core.def. This allows specifying explicit module dependencies together with the module definition.

Do not track the "extra_deps.lst" file in the repository anymore, it is now auto-generated.

Trying to build with this, it looks like it might be broken at the site where the extra_deps.lst is used:

1. Apply this patch in a fresh git tree
2. Revert "build: Include grub-core/extra_deps.lst in dist" (after all, no need to include it if it's auto generated, right?)
3. Create a dist tarball

    $ ./bootstrap
    $ mkdir compile
    $ cd compile
    $ ../configure
    $ make dist

4. Unpack tarball (eg, into /tmp)
5. Try to build from the tarball

    $ cd /tmp/grub
    $ mkdir compile
    $ cd compile
    $ ../configure --with-platform=efi
    $ make
    ...
    cat kernel_syms.lst ../../grub-core/extra_deps.lst > syminfo.lst.new
    cat: ../../grub-core/extra_deps.lst: No such file or directory
    make[3]: *** [Makefile:51281: syminfo.lst] Error 1
    make[3]: Leaving directory '/tmp/grub-2.13/compile/grub-core'
    make[2]: *** [Makefile:28866: all] Error 2
    make[2]: Leaving directory '/tmp/grub-2.13/compile/grub-core'
    make[1]: *** [Makefile:12131: all-recursive] Error 1
    make[1]: Leaving directory '/tmp/grub-2.13/compile'
    make: *** [Makefile:3958: all] Error 2

The file with the correct contents does get generated into grub-core/, but if I'm understanding the output correctly, it's trying to grab extra_deps.lst from outside the compile/ subdirectory.

- Oskari

Quoted 3 lines

Make use of this new keyword in the bli module definition.

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel