projectile icon indicating copy to clipboard operation
projectile copied to clipboard

meson.build is not always in the root of a repository

Open vincentbernat opened this issue 3 years ago • 8 comments

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

  1. Get a copy of GTK without a .git directory
  2. Open a file in the x11 directory
  3. 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

vincentbernat avatar Jan 03 '22 19:01 vincentbernat

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.

bbatsov avatar Mar 16 '22 06:03 bbatsov

Maybe use the top-most one?

vincentbernat avatar Mar 16 '22 06:03 vincentbernat

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.

bbatsov avatar Mar 16 '22 06:03 bbatsov

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.

eli-schwartz avatar Mar 16 '22 18:03 eli-schwartz

So, do we need to do something about this or not?

bbatsov avatar Oct 30 '22 05:10 bbatsov

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.

eli-schwartz avatar Oct 30 '22 05:10 eli-schwartz

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.

bbatsov avatar Oct 30 '22 06:10 bbatsov

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.

eli-schwartz avatar Oct 30 '22 06:10 eli-schwartz