mesonbuild / meson

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

Subproject option doesn't yield to the parent, but to the root project #12488

Open intractabilis opened 7 months ago

intractabilis commented 7 months ago

Suppose you want to use GStreamer as a subproject. You create the following meson.build

project('gstproj', ['c', 'cpp'])

gst_dep = dependency(
    'gstreamer-1.0'
  , version: '>= 1.23'
  , default_options: ['gpl=enabled']
  )

You also create the following subprojects/gstreamer-full.wrap

[wrap-git]
directory = gstreamer
url = https://gitlab.freedesktop.org/gstreamer/gstreamer.git
revision = main
depth = 1

[provide]
dependency_names = gstreamer-1.0, gstreamer-app-1.0, gstreamer-audio-1.0, gstreamer-base-1.0, gstreamer-gl-1.0, gstreamer-gl-egl-1.0, gstreamer-gl-x11-1.0, gstreamer-net-1.0, gstreamer-pbutils-1.0, gstreamer-rtp-1.0, gstreamer-rtsp-1.0, gstreamer-rtsp-server-1.0, gstreamer-sdp-1.0, gstreamer-video-1.0

Then you run meson setup build.

GStreamer has a subproject gst-plugins-bad, which also has an option gpl that yields

option('gpl', type: 'feature', value: 'disabled', yield: true,
  description: 'Allow build plugins that have (A)GPL-licensed dependencies')

You assume that since you set gpl to enabled in the parent project, gst-plugins-bad will yield enabled. To your utter surprise, it stays disabled.

It seems like it's because of this line in interpreter.py

if opt.yielding and key.subproject and key.as_root() in self.coredata.options:

as_root makes it search gpl in your project, instead of the parent.

This behavior is counterintuitive on multiple levels. Let's assume I create an option gpl in my project and assign it enabled. It will behave strangely because gpl in GStreamer itself doesn't yield. Therefore, I will have gstreamer-full:gpl=whatever you set in default_options, gst-plugins-bad:gpl=enabled. Even more curious case would be if you have another subproject also with an option gpl that yields, but with a different type.

xclaesse commented 7 months ago

For better or worse, that's the expected behaviour. Meson subprojects are not a tree (that would be a graph), but a flat hierarchy. They are all subprojects of the main project. That means you need to add the gpl option into your project, or you can add in main project: project(..., default_options: ['gst-plugins-base:gpl=enabled', 'gst-plugins-good:gpl=enabled', ...]).

xclaesse commented 7 months ago

Diverging: Hopefully GStreamer will one day accept to give up on core/base/good/bad/ugly split non-sense and make a single project.

intractabilis commented 7 months ago

What happens if I have another subproject, TumboYumbo, which has a subproject TumboBumbo, where gpl is a Boolean? Can I have in my main project two options gpl with different types?