2024-01-12 03:45:07

by Yang Jihong

[permalink] [raw]
Subject: [PATCH] perf build: Check whether pkg-config is installed when libtraceevent is linked

If pkg-config is not installed when libtraceevent is linked, the build fails.

The error information is as follows:

$ make
<SNIP>
In file included from /home/yjh/projects_linux/perf-tool-next/linux/tools/perf/util/evsel.c:43:
/home/yjh/projects_linux/perf-tool-next/linux/tools/perf/util/trace-event.h:149:62: error: operator '&&' has no right operand
149 | #if defined(LIBTRACEEVENT_VERSION) && LIBTRACEEVENT_VERSION >= MAKE_LIBTRACEEVENT_VERSION(1, 5, 0)
| ^~
error: command '/usr/bin/gcc' failed with exit code 1
cp: cannot stat 'python_ext_build/lib/perf*.so': No such file or directory
make[2]: *** [Makefile.perf:668: python/perf.cpython-310-x86_64-linux-gnu.so] Error 1
make[2]: *** Waiting for unfinished jobs....

Because pkg-config is not installed, fail to get libtraceevent version in
Makefile.config file. As a result, LIBTRACEEVENT_VERSION is empty.
However, the preceding error information is not user-friendly.

Identify errors in advance by checking that pkg-config is installed at
compile time.

The build results of various scenarios are as follows:

1. build successful when libtraceevent is not linked and pkg-config is not installed

$ pkg-config --version
-bash: /usr/bin/pkg-config: No such file or directory
$ make clean >/dev/null
$ make NO_LIBTRACEEVENT=1 >/dev/null
Makefile.config:1133: No alternatives command found, you need to set JDIR= to point to the root of your Java directory
PERF_VERSION = 6.7.rc6.gd988c9f511af
$ echo $?
0

2. dummy pkg-config is missing when libtraceevent is linked

$ pkg-config --version
-bash: /usr/bin/pkg-config: No such file or directory
$ make clean >/dev/null
$ make >/dev/null
Makefile.config:221: *** Error: pkg-config needed by libtraceevent is missing on this system, please install it. Stop.
make[1]: *** [Makefile.perf:251: sub-make] Error 2
make: *** [Makefile:70: all] Error 2
$ echo $?
2

3. build successful when libtraceevent is linked and pkg-config is installed

$ pkg-config --version
0.29.2
$ make clean >/dev/null
$ make >/dev/null
Makefile.config:1133: No alternatives command found, you need to set JDIR= to point to the root of your Java directory
PERF_VERSION = 6.7.rc6.gd988c9f511af
$ echo $?
0

Signed-off-by: Yang Jihong <[email protected]>
---
tools/perf/Makefile.config | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index aa55850fbc21..70c33c935a98 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -216,6 +216,12 @@ ifeq ($(call get-executable,$(BISON)),)
dummy := $(error Error: $(BISON) is missing on this system, please install it)
endif

+ifneq ($(NO_LIBTRACEEVENT),1)
+ ifeq ($(call get-executable,$(PKG_CONFIG)),)
+ dummy := $(error Error: $(PKG_CONFIG) needed by libtraceevent is missing on this system, please install it)
+ endif
+endif
+
ifneq ($(OUTPUT),)
ifeq ($(shell expr $(shell $(BISON) --version | grep bison | sed -e 's/.\+ \([0-9]\+\).\([0-9]\+\).\([0-9]\+\)/\1\2\3/g') \>\= 371), 1)
BISON_FILE_PREFIX_MAP := --file-prefix-map=$(OUTPUT)=
--
2.34.1



2024-01-16 22:31:24

by Namhyung Kim

[permalink] [raw]
Subject: Re: [PATCH] perf build: Check whether pkg-config is installed when libtraceevent is linked

Hello,

On Thu, Jan 11, 2024 at 7:44 PM Yang Jihong <[email protected]> wrote:
>
> If pkg-config is not installed when libtraceevent is linked, the build fails.
>
> The error information is as follows:
>
> $ make
> <SNIP>
> In file included from /home/yjh/projects_linux/perf-tool-next/linux/tools/perf/util/evsel.c:43:
> /home/yjh/projects_linux/perf-tool-next/linux/tools/perf/util/trace-event.h:149:62: error: operator '&&' has no right operand
> 149 | #if defined(LIBTRACEEVENT_VERSION) && LIBTRACEEVENT_VERSION >= MAKE_LIBTRACEEVENT_VERSION(1, 5, 0)
> | ^~
> error: command '/usr/bin/gcc' failed with exit code 1
> cp: cannot stat 'python_ext_build/lib/perf*.so': No such file or directory
> make[2]: *** [Makefile.perf:668: python/perf.cpython-310-x86_64-linux-gnu.so] Error 1
> make[2]: *** Waiting for unfinished jobs....
>
> Because pkg-config is not installed, fail to get libtraceevent version in
> Makefile.config file. As a result, LIBTRACEEVENT_VERSION is empty.
> However, the preceding error information is not user-friendly.
>
> Identify errors in advance by checking that pkg-config is installed at
> compile time.

Thanks for working on this. I also think we can disable it when
pkg-config is not installed and continue to build. But I guess it's
usual to have pkg-config on a build environment so it'd be better
to stop the build and warn the user.

>
> The build results of various scenarios are as follows:
>
> 1. build successful when libtraceevent is not linked and pkg-config is not installed
>
> $ pkg-config --version
> -bash: /usr/bin/pkg-config: No such file or directory
> $ make clean >/dev/null
> $ make NO_LIBTRACEEVENT=1 >/dev/null
> Makefile.config:1133: No alternatives command found, you need to set JDIR= to point to the root of your Java directory
> PERF_VERSION = 6.7.rc6.gd988c9f511af
> $ echo $?
> 0
>
> 2. dummy pkg-config is missing when libtraceevent is linked
>
> $ pkg-config --version
> -bash: /usr/bin/pkg-config: No such file or directory
> $ make clean >/dev/null
> $ make >/dev/null
> Makefile.config:221: *** Error: pkg-config needed by libtraceevent is missing on this system, please install it. Stop.
> make[1]: *** [Makefile.perf:251: sub-make] Error 2
> make: *** [Makefile:70: all] Error 2
> $ echo $?
> 2
>
> 3. build successful when libtraceevent is linked and pkg-config is installed
>
> $ pkg-config --version
> 0.29.2
> $ make clean >/dev/null
> $ make >/dev/null
> Makefile.config:1133: No alternatives command found, you need to set JDIR= to point to the root of your Java directory
> PERF_VERSION = 6.7.rc6.gd988c9f511af
> $ echo $?
> 0
>
> Signed-off-by: Yang Jihong <[email protected]>

Acked-by: Namhyung Kim <[email protected]>

Thanks,
Namhyung


> ---
> tools/perf/Makefile.config | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
> index aa55850fbc21..70c33c935a98 100644
> --- a/tools/perf/Makefile.config
> +++ b/tools/perf/Makefile.config
> @@ -216,6 +216,12 @@ ifeq ($(call get-executable,$(BISON)),)
> dummy := $(error Error: $(BISON) is missing on this system, please install it)
> endif
>
> +ifneq ($(NO_LIBTRACEEVENT),1)
> + ifeq ($(call get-executable,$(PKG_CONFIG)),)
> + dummy := $(error Error: $(PKG_CONFIG) needed by libtraceevent is missing on this system, please install it)
> + endif
> +endif
> +
> ifneq ($(OUTPUT),)
> ifeq ($(shell expr $(shell $(BISON) --version | grep bison | sed -e 's/.\+ \([0-9]\+\).\([0-9]\+\).\([0-9]\+\)/\1\2\3/g') \>\= 371), 1)
> BISON_FILE_PREFIX_MAP := --file-prefix-map=$(OUTPUT)=
> --
> 2.34.1
>

2024-01-22 21:12:37

by Namhyung Kim

[permalink] [raw]
Subject: Re: [PATCH] perf build: Check whether pkg-config is installed when libtraceevent is linked

On Fri, 12 Jan 2024 03:40:19 +0000, Yang Jihong wrote:
> If pkg-config is not installed when libtraceevent is linked, the build fails.
>
> The error information is as follows:
>
> $ make
> <SNIP>
> In file included from /home/yjh/projects_linux/perf-tool-next/linux/tools/perf/util/evsel.c:43:
> /home/yjh/projects_linux/perf-tool-next/linux/tools/perf/util/trace-event.h:149:62: error: operator '&&' has no right operand
> 149 | #if defined(LIBTRACEEVENT_VERSION) && LIBTRACEEVENT_VERSION >= MAKE_LIBTRACEEVENT_VERSION(1, 5, 0)
> | ^~
> error: command '/usr/bin/gcc' failed with exit code 1
> cp: cannot stat 'python_ext_build/lib/perf*.so': No such file or directory
> make[2]: *** [Makefile.perf:668: python/perf.cpython-310-x86_64-linux-gnu.so] Error 1
> make[2]: *** Waiting for unfinished jobs....
>
> [...]

Applied to perf-tools-next, thanks!

Thanks,
Namhyung