diff mbox series

[bpf-next,2/3] bpftool: Add libbpf's version number to "bpftool version" output

Message ID 20220131211136.71010-3-quentin@isovalent.com (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series bpftool: Switch to independent versioning scheme | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 6 maintainers not CCed: kpsingh@kernel.org sdf@google.com john.fastabend@gmail.com kafai@fb.com songliubraving@fb.com yhs@fb.com
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 38 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next success VM_Test

Commit Message

Quentin Monnet Jan. 31, 2022, 9:11 p.m. UTC
To help users check what version of libbpf has been used to compile
bpftool, embed the version number and print it along with bpftool's own
version number.

Signed-off-by: Quentin Monnet <quentin@isovalent.com>
---
 tools/bpf/bpftool/Documentation/common_options.rst | 3 ++-
 tools/bpf/bpftool/Makefile                         | 2 ++
 tools/bpf/bpftool/main.c                           | 3 +++
 3 files changed, 7 insertions(+), 1 deletion(-)

Comments

Andrii Nakryiko Feb. 2, 2022, 6:59 a.m. UTC | #1
On Mon, Jan 31, 2022 at 1:11 PM Quentin Monnet <quentin@isovalent.com> wrote:
>
> To help users check what version of libbpf has been used to compile
> bpftool, embed the version number and print it along with bpftool's own
> version number.
>
> Signed-off-by: Quentin Monnet <quentin@isovalent.com>
> ---
>  tools/bpf/bpftool/Documentation/common_options.rst | 3 ++-
>  tools/bpf/bpftool/Makefile                         | 2 ++
>  tools/bpf/bpftool/main.c                           | 3 +++
>  3 files changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/tools/bpf/bpftool/Documentation/common_options.rst b/tools/bpf/bpftool/Documentation/common_options.rst
> index 908487b9c2ad..24166733d3ae 100644
> --- a/tools/bpf/bpftool/Documentation/common_options.rst
> +++ b/tools/bpf/bpftool/Documentation/common_options.rst
> @@ -4,7 +4,8 @@
>           Print short help message (similar to **bpftool help**).
>
>  -V, --version
> -         Print version number (similar to **bpftool version**), and optional
> +         Print bpftool's version number (similar to **bpftool version**), the
> +         version of libbpf that was used to compile the binary, and optional
>           features that were included when bpftool was compiled. Optional
>           features include linking against libbfd to provide the disassembler
>           for JIT-ted programs (**bpftool prog dump jited**) and usage of BPF
> diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
> index 83369f55df61..bd5a8cafac49 100644
> --- a/tools/bpf/bpftool/Makefile
> +++ b/tools/bpf/bpftool/Makefile
> @@ -42,6 +42,7 @@ LIBBPF_BOOTSTRAP_INTERNAL_HDRS := $(addprefix $(LIBBPF_BOOTSTRAP_HDRS_DIR)/,hash
>  ifeq ($(BPFTOOL_VERSION),)
>  BPFTOOL_VERSION := $(shell make -rR --no-print-directory -sC ../../.. kernelversion)
>  endif
> +LIBBPF_VERSION := $(shell make -r --no-print-directory -sC $(BPF_DIR) libbpfversion)
>

why can't you use libbpf_version_string() API instead?



>  $(LIBBPF_OUTPUT) $(BOOTSTRAP_OUTPUT) $(LIBBPF_BOOTSTRAP_OUTPUT) $(LIBBPF_HDRS_DIR) $(LIBBPF_BOOTSTRAP_HDRS_DIR):
>         $(QUIET_MKDIR)mkdir -p $@
> @@ -84,6 +85,7 @@ CFLAGS += -DPACKAGE='"bpftool"' -D__EXPORTED_HEADERS__ \
>         -I$(srctree)/tools/include \
>         -I$(srctree)/tools/include/uapi
>  CFLAGS += -DBPFTOOL_VERSION='"$(BPFTOOL_VERSION)"'
> +CFLAGS += -DLIBBPF_VERSION='"$(LIBBPF_VERSION)"'
>  ifneq ($(EXTRA_CFLAGS),)
>  CFLAGS += $(EXTRA_CFLAGS)
>  endif
> diff --git a/tools/bpf/bpftool/main.c b/tools/bpf/bpftool/main.c
> index 9d01fa9de033..4bda73057980 100644
> --- a/tools/bpf/bpftool/main.c
> +++ b/tools/bpf/bpftool/main.c
> @@ -89,6 +89,8 @@ static int do_version(int argc, char **argv)
>
>                 jsonw_name(json_wtr, "version");
>                 jsonw_printf(json_wtr, "\"%s\"", BPFTOOL_VERSION);
> +               jsonw_name(json_wtr, "libbpf_version");
> +               jsonw_printf(json_wtr, "\"%s\"", LIBBPF_VERSION);
>
>                 jsonw_name(json_wtr, "features");
>                 jsonw_start_object(json_wtr);   /* features */
> @@ -102,6 +104,7 @@ static int do_version(int argc, char **argv)
>                 unsigned int nb_features = 0;
>
>                 printf("%s v%s\n", bin_name, BPFTOOL_VERSION);
> +               printf("using libbpf v%s\n", LIBBPF_VERSION);
>                 printf("features:");
>                 if (has_libbfd) {
>                         printf(" libbfd");
> --
> 2.32.0
>
Quentin Monnet Feb. 2, 2022, 6:58 p.m. UTC | #2
2022-02-01 22:59 UTC-0800 ~ Andrii Nakryiko <andrii.nakryiko@gmail.com>
> On Mon, Jan 31, 2022 at 1:11 PM Quentin Monnet <quentin@isovalent.com> wrote:
>>
>> To help users check what version of libbpf has been used to compile
>> bpftool, embed the version number and print it along with bpftool's own
>> version number.
>>
>> Signed-off-by: Quentin Monnet <quentin@isovalent.com>
>> ---
>>  tools/bpf/bpftool/Documentation/common_options.rst | 3 ++-
>>  tools/bpf/bpftool/Makefile                         | 2 ++
>>  tools/bpf/bpftool/main.c                           | 3 +++
>>  3 files changed, 7 insertions(+), 1 deletion(-)
>>
>> diff --git a/tools/bpf/bpftool/Documentation/common_options.rst b/tools/bpf/bpftool/Documentation/common_options.rst
>> index 908487b9c2ad..24166733d3ae 100644
>> --- a/tools/bpf/bpftool/Documentation/common_options.rst
>> +++ b/tools/bpf/bpftool/Documentation/common_options.rst
>> @@ -4,7 +4,8 @@
>>           Print short help message (similar to **bpftool help**).
>>
>>  -V, --version
>> -         Print version number (similar to **bpftool version**), and optional
>> +         Print bpftool's version number (similar to **bpftool version**), the
>> +         version of libbpf that was used to compile the binary, and optional
>>           features that were included when bpftool was compiled. Optional
>>           features include linking against libbfd to provide the disassembler
>>           for JIT-ted programs (**bpftool prog dump jited**) and usage of BPF
>> diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
>> index 83369f55df61..bd5a8cafac49 100644
>> --- a/tools/bpf/bpftool/Makefile
>> +++ b/tools/bpf/bpftool/Makefile
>> @@ -42,6 +42,7 @@ LIBBPF_BOOTSTRAP_INTERNAL_HDRS := $(addprefix $(LIBBPF_BOOTSTRAP_HDRS_DIR)/,hash
>>  ifeq ($(BPFTOOL_VERSION),)
>>  BPFTOOL_VERSION := $(shell make -rR --no-print-directory -sC ../../.. kernelversion)
>>  endif
>> +LIBBPF_VERSION := $(shell make -r --no-print-directory -sC $(BPF_DIR) libbpfversion)
>>
> 
> why can't you use libbpf_version_string() API instead?

I missed it somehow, thanks for the pointer. It seems to be a recent
addition to libbpf, and it was probably not present last time I checked
for such an API. I'll use it.
diff mbox series

Patch

diff --git a/tools/bpf/bpftool/Documentation/common_options.rst b/tools/bpf/bpftool/Documentation/common_options.rst
index 908487b9c2ad..24166733d3ae 100644
--- a/tools/bpf/bpftool/Documentation/common_options.rst
+++ b/tools/bpf/bpftool/Documentation/common_options.rst
@@ -4,7 +4,8 @@ 
 	  Print short help message (similar to **bpftool help**).
 
 -V, --version
-	  Print version number (similar to **bpftool version**), and optional
+	  Print bpftool's version number (similar to **bpftool version**), the
+	  version of libbpf that was used to compile the binary, and optional
 	  features that were included when bpftool was compiled. Optional
 	  features include linking against libbfd to provide the disassembler
 	  for JIT-ted programs (**bpftool prog dump jited**) and usage of BPF
diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
index 83369f55df61..bd5a8cafac49 100644
--- a/tools/bpf/bpftool/Makefile
+++ b/tools/bpf/bpftool/Makefile
@@ -42,6 +42,7 @@  LIBBPF_BOOTSTRAP_INTERNAL_HDRS := $(addprefix $(LIBBPF_BOOTSTRAP_HDRS_DIR)/,hash
 ifeq ($(BPFTOOL_VERSION),)
 BPFTOOL_VERSION := $(shell make -rR --no-print-directory -sC ../../.. kernelversion)
 endif
+LIBBPF_VERSION := $(shell make -r --no-print-directory -sC $(BPF_DIR) libbpfversion)
 
 $(LIBBPF_OUTPUT) $(BOOTSTRAP_OUTPUT) $(LIBBPF_BOOTSTRAP_OUTPUT) $(LIBBPF_HDRS_DIR) $(LIBBPF_BOOTSTRAP_HDRS_DIR):
 	$(QUIET_MKDIR)mkdir -p $@
@@ -84,6 +85,7 @@  CFLAGS += -DPACKAGE='"bpftool"' -D__EXPORTED_HEADERS__ \
 	-I$(srctree)/tools/include \
 	-I$(srctree)/tools/include/uapi
 CFLAGS += -DBPFTOOL_VERSION='"$(BPFTOOL_VERSION)"'
+CFLAGS += -DLIBBPF_VERSION='"$(LIBBPF_VERSION)"'
 ifneq ($(EXTRA_CFLAGS),)
 CFLAGS += $(EXTRA_CFLAGS)
 endif
diff --git a/tools/bpf/bpftool/main.c b/tools/bpf/bpftool/main.c
index 9d01fa9de033..4bda73057980 100644
--- a/tools/bpf/bpftool/main.c
+++ b/tools/bpf/bpftool/main.c
@@ -89,6 +89,8 @@  static int do_version(int argc, char **argv)
 
 		jsonw_name(json_wtr, "version");
 		jsonw_printf(json_wtr, "\"%s\"", BPFTOOL_VERSION);
+		jsonw_name(json_wtr, "libbpf_version");
+		jsonw_printf(json_wtr, "\"%s\"", LIBBPF_VERSION);
 
 		jsonw_name(json_wtr, "features");
 		jsonw_start_object(json_wtr);	/* features */
@@ -102,6 +104,7 @@  static int do_version(int argc, char **argv)
 		unsigned int nb_features = 0;
 
 		printf("%s v%s\n", bin_name, BPFTOOL_VERSION);
+		printf("using libbpf v%s\n", LIBBPF_VERSION);
 		printf("features:");
 		if (has_libbfd) {
 			printf(" libbfd");