Subject: 29.0.50; build problem git worktree linked to main worktree (repo)

From: Gregor Zattler <[email-masked]>
Date: Sun, 06 Nov 2022 00:11:09 +0100

Dear Emacs developers,

building Emacs from sources in a detached linked worktree[1]
linked to a main worktree[1] fails, because necessary
-by.el, -wy.el files are not generated as described in
admin/grammars/Makefile for targets `bovine` and `wisent`.
Instead while these files are generated error messages "Args
out of range: "master", 0, 7" are shown and the respective
files are not generated.

Why this is the case, I have no clue.  The respective code
for generating these files is way above my skills.

But I found out that building instead from sources in a
linked worktree linked to a bare repository[1] works as
expected.

This is what I will do from now on, therefore the
aforementioned failure is no problem for me any more.

If there is a bug in the Emacs build system regarding linked
worktrees linked to main worktrees, though, is up to you.

In order to rule out any misconfiguration on my side, I
installed Emacs build dependencies on a minimal installation
of Debian/bullseye, cloned the emacs git repo with a freshly
created and otherwise unconfigured user.  To trigger the
build process this user then issued only "make V=1 -j 1" to
get the most default build process.  All tests were made
with freshly cloned repos respectively freshly generated git
worktrees created from those pristine git repos.

The difference between a linked worktree and its main
worktree is in the .git directory only, as this diff shows:
$ diff -aNurx.git/* emacs2 emacs2-worktree
File emacs2/.git is a directory while file emacs2-worktree/.git is a regular file

While investigating, I learned that the build process embeds
the repository revision into the Emacs binary.  This is the
case if Emacs is build in a linked worktree linked to a bare
repository, as the template from emacs-report-bug shows.

In case of the linked worktree linked to the main worktree
the build process does *not* fail if one removes the .git
file before.  This destroy the link to the repo, though and
the repository version is not embedded in the
resulting binary accordingly.

Why the existence of the .git file disturbs the production
of the grammar files, I have no clue.

If you have further specific questions, I'm happy to help as
far as my very limited knowledge allows.

Thanks for your attention, Gregor

P.S.: This started with a message on help-gnu-emacs:
https://lists.gnu.org/archive/html/help-gnu-emacs/2022-10/msg00860.html
and helpful answers by Eli:
https://lists.gnu.org/archive/html/help-gnu-emacs/2022-11/msg00002.html
and following messages.

[1] In git parlance a
    - "linked worktree" has no .git directory, but a .git
      *file* which's contents points to either a
      - "main worktree" which contains the .git directory,
        (is a git repo with a checked out worktree of its
        own), or a
      - bare repository, which basically is a directory
        containing the contents of a .git dir but without a
        checked out worktree.