perf tools: Stop depending on .git files for building PERF-VERSION-FILE

This essentially reverts commit c72e3f04b45fb2e5 ("tools/perf/build:
Speed up git-version test on re-make") and commit 4e666cdb06eede20
("perf tools: Fix dependency for version file creation")

In commit c72e3f04b45fb2e5 ("tools/perf/build: Speed up git-version test
on re-make"), a makefile dependency on .git/HEAD was added. The
background is that running PERF-VERSION-FILE is relatively slow, and
commands like "git describe" are particularly slow.

In commit 4e666cdb06eede20 ("perf tools: Fix dependency for version file
creation"), an additional dependency on .git/ORIG_HEAD was added, as
.git/HEAD may not change for "git reset --hard HEAD^" command. However,
depending on whether we're on a branch or not, a "git cherry-pick" may
not lead to the version being updated.

As discussed with the git community in [0], using git internal files for
dependencies is not reliable. Commit 4e666cdb06ee also breaks some build
scenarios [1].

As mentioned, c72e3f04b45fb2e5 ("tools/perf/build: Speed up git-version
test on re-make") was added to speed up the build. However in commit
7572733b84997d23 ("perf tools: Fix version kernel tag") we removed the
call to "git describe", so just revert Makefile.perf back to same as pre
c72e3f04b45fb2e5 ("tools/perf/build: Speed up git-version test on
re-make") and the build should not be so slow, as below:

Pre 7572733b8499:

$> time util/PERF-VERSION-GEN
PERF_VERSION = 5.17.rc8.g4e666cdb06ee

real 0m0.110s
user 0m0.091s
sys 0m0.019s

Post 7572733b8499:

$> time util/PERF-VERSION-GEN
PERF_VERSION = 5.17.rc8.g7572733b8499

real 0m0.039s
user 0m0.036s
sys 0m0.007s

[0] https://lore.kernel.org/git/87wngkpddp.fsf@igel.home/T/#m4a4dd6de52fdbe21179306cd57b3761eb07f45f8
[1] https://lore.kernel.org/linux-perf-users/20220329093120.4173283-1-matthieu.baerts@tessares.net/T/#u

Committer testing:

After a fresh rebuild using 'make -C tools/perf O=/tmp/build/perf install-bin':

$ perf -v
perf version 5.17.g162f9db407b6
$ git log --oneline -1
162f9db407b6a6e5 (HEAD -> perf/core) perf tools: Stop depending on .git files for building PERF-VERSION-FILE
$

Now using a detached tarball, i.e. outside the kernel source tree:

$ ls -la perf*tar
ls: cannot access 'perf*tar': No such file or directory
$ make perf-tar-src-pkg
TAR
PERF_VERSION = 5.17.g31d10b3ef133
$ ls -la perf*tar
-rw-r--r--. 1 acme acme 22241280 Mar 30 13:26 perf-5.17.0.tar
$ mv perf-5.17.0.tar /tmp
$ cd /tmp
$ tar xf perf-5.17.0.tar
$ cd perf-5.17.0/
$ make -C tools/perf |& tail
CC util/pmu.o
CC util/pmu-flex.o
CC util/expr-flex.o
CC util/expr.o
LD util/scripting-engines/perf-in.o
LD util/intel-pt-decoder/perf-in.o
LD util/perf-in.o
LD perf-in.o
LINK perf
make: Leaving directory '/tmp/perf-5.17.0/tools/perf'
$ tools/perf/perf -v
perf version 5.17.g31d10b3ef133
$ pwd
/tmp/perf-5.17.0
$ cat PERF-VERSION-FILE
#define PERF_VERSION "5.17.g31d10b3ef133"
$

Fixes: 4e666cdb06eede20 ("perf tools: Fix dependency for version file creation")
Reported-by: Matthieu Baerts <matthieu.baerts@tessares.net>
Signed-off-by: John Garry <john.garry@huawei.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Tested-by: Matthieu Baerts <matthieu.baerts@tessares.net>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.garry@huawei.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/1648635774-14581-1-git-send-email-john.garry@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by John Garry and committed by Arnaldo Carvalho de Melo d4ff9265 5ced8124

+2 -12
+2 -12
tools/perf/Makefile.perf
··· 691 691 $(SCRIPTS) : % : %.sh 692 692 $(QUIET_GEN)$(INSTALL) '$@.sh' '$(OUTPUT)$@' 693 693 694 - $(OUTPUT)PERF-VERSION-FILE: ../../.git/HEAD ../../.git/ORIG_HEAD 694 + $(OUTPUT)PERF-VERSION-FILE: .FORCE-PERF-VERSION-FILE 695 695 $(Q)$(SHELL_PATH) util/PERF-VERSION-GEN $(OUTPUT) 696 - $(Q)touch $(OUTPUT)PERF-VERSION-FILE 697 696 698 697 # These can record PERF_VERSION 699 698 perf.spec $(SCRIPTS) \ ··· 1138 1139 @echo "FEATURE-DUMP file available in $(OUTPUT)FEATURE-DUMP" 1139 1140 endif 1140 1141 1141 - # 1142 - # Trick: if ../../.git does not exist - we are building out of tree for example, 1143 - # then force version regeneration: 1144 - # 1145 - ifeq ($(wildcard ../../.git/HEAD),) 1146 - GIT-HEAD-PHONY = ../../.git/HEAD ../../.git/ORIG_HEAD 1147 - else 1148 - GIT-HEAD-PHONY = 1149 - endif 1150 1142 1151 1143 FORCE: 1152 1144 1153 1145 .PHONY: all install clean config-clean strip install-gtk 1154 1146 .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell 1155 - .PHONY: $(GIT-HEAD-PHONY) TAGS tags cscope FORCE prepare 1147 + .PHONY: .FORCE-PERF-VERSION-FILE TAGS tags cscope FORCE prepare 1156 1148 .PHONY: libtraceevent_plugins archheaders 1157 1149 1158 1150 endif # force_fixdep