Skip to contentSkip to conversation

scripts/bpf: Print an error when known types list needs updating

PATCH Superseded Jakub Sitnicki 2 participants 3 messages Oct 17, 2019 – Oct 18, 2019

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scripts/bpf: Print an error when known types list needs updating

Don't generate a broken bpf_helper_defs.h header if the helper script needs updating because it doesn't recognize a newly added type. Instead print an error that explains why the build is failing and stop.

Fixes 456a513bb5d4 ("scripts/bpf: Emit an #error directive known types list needs updating")
---
 scripts/bpf_helpers_doc.py | 4 ++--
 tools/lib/bpf/Makefile     | 3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)
scripts/bpf_helpers_doc.py +2 -2
index 08300bc024da..7548569e8076 100755
@@ -488,8 +488,8 @@ class PrinterHelpers(Printer):
             return t
         if t in self.mapped_types:
             return self.mapped_types[t]
-        print("")
-        print("#error \"Unrecognized type '%s', please add it to known types!\"" % t)
+        print("Unrecognized type '%s', please add it to known types!" % t,
+              file=sys.stderr)
         sys.exit(1)
 
     seen_helpers = set()
tools/lib/bpf/Makefile +2 -1
index 75b538577c17..26c202261c5f 100644
@@ -169,7 +169,8 @@ $(BPF_IN): force elfdep bpfdep bpf_helper_defs.h
 
 bpf_helper_defs.h: $(srctree)/include/uapi/linux/bpf.h
 	$(Q)$(srctree)/scripts/bpf_helpers_doc.py --header 		\
-		--file $(srctree)/include/uapi/linux/bpf.h > bpf_helper_defs.h
+		--file $(srctree)/include/uapi/linux/bpf.h > [email protected]
+	@mv [email protected] $@
 
 $(OUTPUT)libbpf.so: $(OUTPUT)libbpf.so.$(LIBBPF_VERSION)
 
Signature · 1 line
2.20.1
#1 lore raw
Quoted 17 lines · Jakub Sitnicki

Don't generate a broken bpf_helper_defs.h header if the helper script needs updating because it doesn't recognize a newly added type. Instead print an error that explains why the build is failing and stop.

Fixes 456a513bb5d4 ("scripts/bpf: Emit an #error directive known types list needs updating")
---
  scripts/bpf_helpers_doc.py | 4 ++--
  tools/lib/bpf/Makefile     | 3 ++-
  2 files changed, 4 insertions(+), 3 deletions(-)
scripts/bpf_helpers_doc.py +0 -0
index 08300bc024da..7548569e8076 100755

scripts/bpf_helpers_doc.py class PrinterHelpers(Printer): · line 492

Quoted 7 lines
scripts/bpf_helpers_doc.py +2 -2
@@ -488,8 +488,8 @@ class PrinterHelpers(Printer):
              return t
          if t in self.mapped_types:
              return self.mapped_types[t]
-        print("")
-        print("#error \"Unrecognized type '%s', please add it to known types!\"" % t)
+        print("Unrecognized type '%s', please add it to known types!" % t,
+              file=sys.stderr)

This looks good, thanks!

Quoted 8 lines
scripts/bpf_helpers_doc.py +0 -0
          sys.exit(1)
 
      seen_helpers = set()
tools/lib/bpf/Makefile +0 -0
index 75b538577c17..26c202261c5f 100644

tools/lib/bpf/Makefile $(BPF_IN): force elfdep bpfdep bpf_helper_defs.h · line 173

Quoted 6 lines
tools/lib/bpf/Makefile +2 -1
@@ -169,7 +169,8 @@ $(BPF_IN): force elfdep bpfdep bpf_helper_defs.h
 
  bpf_helper_defs.h: $(srctree)/include/uapi/linux/bpf.h
  	$(Q)$(srctree)/scripts/bpf_helpers_doc.py --header 		\
-		--file $(srctree)/include/uapi/linux/bpf.h > bpf_helper_defs.h
+		--file $(srctree)/include/uapi/linux/bpf.h > [email protected]
+	@mv [email protected] $@

This is unnecessary. Let's add ".DELETE_ON_ERROR:" at the end Makefile instead to trigger this auto-deletion of failed targets automatically.

Quoted 4 lines
tools/lib/bpf/Makefile +0 -0
  $(OUTPUT)libbpf.so: $(OUTPUT)libbpf.so.$(LIBBPF_VERSION)
 
 
#2 lore raw
Quoted 1 line · Andrii Nakryiko

On 10/17/19 2:44 AM, Jakub Sitnicki wrote:

[...]

Quoted 6 lines
Quoted 6 lines
tools/lib/bpf/Makefile +0 -0
index 75b538577c17..26c202261c5f 100644
@@ -169,7 +169,8 @@ $(BPF_IN): force elfdep bpfdep bpf_helper_defs.h
 
Quoted 8 lines

tools/lib/bpf/Makefile $(BPF_IN): force elfdep bpfdep bpf_helper_defs.h · line 173

Quoted 5 lines
tools/lib/bpf/Makefile +2 -1
  bpf_helper_defs.h: $(srctree)/include/uapi/linux/bpf.h
  	$(Q)$(srctree)/scripts/bpf_helpers_doc.py --header 		\
-		--file $(srctree)/include/uapi/linux/bpf.h > bpf_helper_defs.h
+		--file $(srctree)/include/uapi/linux/bpf.h > [email protected]
+	@mv [email protected] $@

This is unnecessary. Let's add ".DELETE_ON_ERROR:" at the end Makefile instead to trigger this auto-deletion of failed targets automatically.

Thanks for the hint. Will respin it.

-Jakub