perf build: Check whether pkg-config is installed when libtraceevent is linked

Message ID 20240112034019.3558584-1-yangjihong1@huawei.com
State New
Headers
Series perf build: Check whether pkg-config is installed when libtraceevent is linked |

Commit Message

Yang Jihong Jan. 12, 2024, 3:40 a.m. UTC
  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 <yangjihong1@huawei.com>
---
 tools/perf/Makefile.config | 6 ++++++
 1 file changed, 6 insertions(+)
  

Comments

Namhyung Kim Jan. 16, 2024, 9:38 p.m. UTC | #1
Hello,

On Thu, Jan 11, 2024 at 7:44 PM Yang Jihong <yangjihong1@huawei.com> 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 <yangjihong1@huawei.com>

Acked-by: Namhyung Kim <namhyung@kernel.org>

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
>
  
Namhyung Kim Jan. 22, 2024, 8:36 p.m. UTC | #2
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
  

Patch

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)=