meson.build is not always in the root of a repository
Expected behavior
Projectile should find the root of the GTK project when inside the x11 directory
Actual behavior
It considers the x11 directory as the root.
Steps to reproduce the problem
- Get a copy of GTK without a .git directory
- Open a file in the
x11directory - M-x projectile-project-info
Project dir: /home/bernat/src/gtk+3.0-3.24.31/gdk/x11/ ## Project VCS: none ## Project type: meson
Note that when we are in git, it works as expected.
Environment & Version information
Projectile version information
Projectile 2.5.0
Emacs version
Emacs 27.1
Operating system
Debian unstable
So, what's your suggestion? Just remove meson.build from project root markers? I'm not familiar with the tool, so I can't really suggest a course of action myself.
Maybe use the top-most one?
This will likely require a special function for it or splitting root markers into those that prefer the closest and the furthest. I think we have something like this for Makefiles already.
Meson has an extremely strict definition of what counts as the project root.
A meson.build file in which the first non-whitespace non-comment line is not the project() function, cannot be the project root, and must be a directory processed by another meson.build file using the subdir function.
A meson.build file in which the first non-whitespace non-comment line is the project() function, must be the project root.
So it is absolutely correct to use that file as the marker for a project root, but you could also do a quick heuristic parse of the first section of the file contents.
cmake can also have the same file at any level of the project tree, but my understanding is it's a lot looser about the contents. e.g. there is also a project() function in cmake, which "must" appear in the toplevel CMakeLists.txt but you can decline to do so and it will just generate a developer warning and continue with the default. You can also have it anywhere in the file -- or in any subdirectory you like.
Makefiles are unsolvable unless they come with a configure/configure.ac which actually does denote the toplevel.
So, do we need to do something about this or not?
Yes. As I suggested, there's a very simple file contents check you can do to determine with 100% accuracy if the current directory is a project root or a subdir.
The problem is this will require a custom function for the meson projects and will likely make their discovery a bit slower. Anyways, I'll mark this as an "enhancement" ticket and we'll see if someone's interested in tackling it. Should be pretty simple.
You can also check for meson_options.txt which, if it exists, only exists at the top level, but not all Meson projects are guaranteed to have one... if you do find one, then there's no need to open the other type of filename for reading, so that should help speed things up a bit.