diff mbox series

[bpf-next] scripts/bpf: Print an error when known types list needs updating

Message ID 20191017094416.7688-1-jakub@cloudflare.com
State Changes Requested
Delegated to: BPF Maintainers
Headers show
Series [bpf-next] scripts/bpf: Print an error when known types list needs updating | expand

Commit Message

Jakub Sitnicki Oct. 17, 2019, 9:44 a.m. UTC
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")
Suggested-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>
---
 scripts/bpf_helpers_doc.py | 4 ++--
 tools/lib/bpf/Makefile     | 3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)

Comments

Andrii Nakryiko Oct. 17, 2019, 5:11 p.m. UTC | #1
On 10/17/19 2:44 AM, Jakub Sitnicki wrote:
> 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")
> Suggested-by: Andrii Nakryiko <andriin@fb.com>
> Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>
> ---
>   scripts/bpf_helpers_doc.py | 4 ++--
>   tools/lib/bpf/Makefile     | 3 ++-
>   2 files changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/scripts/bpf_helpers_doc.py b/scripts/bpf_helpers_doc.py
> index 08300bc024da..7548569e8076 100755
> --- a/scripts/bpf_helpers_doc.py
> +++ b/scripts/bpf_helpers_doc.py
> @@ -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!

>           sys.exit(1)
>   
>       seen_helpers = set()
> diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile
> index 75b538577c17..26c202261c5f 100644
> --- a/tools/lib/bpf/Makefile
> +++ b/tools/lib/bpf/Makefile
> @@ -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 > $@.tmp
> +	@mv $@.tmp $@

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

>   
>   $(OUTPUT)libbpf.so: $(OUTPUT)libbpf.so.$(LIBBPF_VERSION)
>   
>
Jakub Sitnicki Oct. 18, 2019, 9:07 a.m. UTC | #2
On Thu, Oct 17, 2019 at 07:11 PM CEST, Andrii Nakryiko wrote:
> On 10/17/19 2:44 AM, Jakub Sitnicki wrote:

[...]

>> diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile
>> index 75b538577c17..26c202261c5f 100644
>> --- a/tools/lib/bpf/Makefile
>> +++ b/tools/lib/bpf/Makefile
>> @@ -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 > $@.tmp
>> +	@mv $@.tmp $@
>
> 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
diff mbox series

Patch

diff --git a/scripts/bpf_helpers_doc.py b/scripts/bpf_helpers_doc.py
index 08300bc024da..7548569e8076 100755
--- a/scripts/bpf_helpers_doc.py
+++ b/scripts/bpf_helpers_doc.py
@@ -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()
diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile
index 75b538577c17..26c202261c5f 100644
--- a/tools/lib/bpf/Makefile
+++ b/tools/lib/bpf/Makefile
@@ -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 > $@.tmp
+	@mv $@.tmp $@
 
 $(OUTPUT)libbpf.so: $(OUTPUT)libbpf.so.$(LIBBPF_VERSION)