mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.65k stars 1.64k forks source link

Wrap Entry Supersedes Presence of symlinked subproject #13746

Open WillAyd opened 1 month ago

WillAyd commented 1 month ago

Describe the bug When a project is symlinked into the subdirectory alongside a wrap file with the same name, Meson appears to ignore the symlinked subproject and proceed to using the wrap file entry

To Reproduce I've created an MRE at this location - https://github.com/WillAyd/meson-subproject-mre

The "main" project looks like:

project(
    'meson-subproject-mre',
    'c',
)

foo_lib = library('foo', 'foo.c')
foo_dep = declare_dependency(link_with: foo_lib)

In the "python" subdirectory, I've created a separate project that should refer to the "main" project:

project(
    'meson-subproject-mre',
    'c'
)

subproject = subproject('meson-subproject-mre')
foo_dep = subproject.get_variable('foo_dep')

Within the subprojects directory of the python directory, I have symlinked to the project root. However, I've additionally provided a meson-subproject-mre.wrap file in case that symlink does not work (ex: when installing from a Python sdist)

If you check out that project, then run:

cd python
meson setup builddir
meson compile -C builddir

You will see that meson downloads meson-subproject-mre from the wrap file, rather than resolving the project via the symlink

Expected behavior Calls to subproject('meson-subproject-mre') should resolve through the symlink, rather than through the wrap system

system parameters meson 1.5.2

QuLogic commented 1 month ago

I cannot reproduce with 1.4.1 or 1.5.2. Is this not on Linux?

Also, your symlink doesn't point to the top-level directory, but goes one above it and assumes the name of the top-level directory; could you perhaps have renamed it after making the symlink?

QuLogic commented 1 month ago

Oh, actually, you didn't provide a .wrap in the MRE, so it wouldn't have attempted it.

WillAyd commented 1 month ago

Ah sorry...missed pushing that. Should be there now

QuLogic commented 1 month ago

Ah, the problem is your wrap file says that the directory is meson-subproject-mre-$COMMIT_HASH, which isn't there, so Meson downloads it. I'm not sure if there's any documentation stating that the wrap file gets priority over a similarly named directory.

For now, you could get it to work by renaming the symlink a bit, and doing:

subproject = subproject('meson-subproject-mre-symlink', required: false)
if not subproject.found()
  subproject = subproject('meson-subproject-mre')  # Use wrap file.
endif
WillAyd commented 1 month ago

Ah, the problem is your wrap file says that the directory is meson-subproject-mre-$COMMIT_HASH, which isn't there, so Meson downloads it.

Oh OK - in this particular case I can just change that to remove the $COMMIT_HASH then too and it should work right? Seems to from a local test.

I was following that pattern since I've seen that in the wrapdb for many packages, assumedly to avoid a conflict of versions.

QuLogic commented 1 month ago

You could, but then you'd have to use a download URL from GitHub that doesn't include the commit hash in the resulting directory.