Repository: mesonbuild/meson

Issue:
"include_directories sandbox violation" being misleading
**Describe the bug**
when hard-coding include directory of a subproject in meson.build of the parent project a warning is issued.

```
                        The project is trying to access the directory {a} which belongs to a different
                        subproject. This is a problem as it hardcodes the relative paths of these two projeccts.
                        This makes it impossible to compile the project in any other directory layout and also
                        prevents the subproject from changing its own directory layout.
                        Instead of poking directly at the internals the subproject should be executed and
                        it should set a variable that the caller can then use. Something like:
                        # In subproject
                        some_dep = declare_dependency(include_directories: include_directories('include'))
                        # In parent project
                        some_dep = dependency('some')
                        executable(..., dependencies: [some_dep])
                        This warning will become a hard error in a future Meson release.
```

This is totally understandable behavior but the solution is sort of misleading. From what I understand defining dependency in this manner of `some_dep = dependency('some')` makes meson search for dependency only systemwide rather than in subprojects, which is probably not what someone, who would hardcode dependency (or include directory) of a subproject in a parent_directory meson.build file, would want. In fact if the subproject is not installed system-wide, like in example below should fail to resolve.

**To Reproduce**
create some parent project with meson.build as simple as
```
project('main', 'cpp')

sub1=subproject('sub1')
executable('helloworld', 'helloworld.cpp', include_directories: include_directories('subprojects/sub1/includes'))
```
with subprojects/sub1/meson.build whose content is something like

```
project('sub1', 'cpp')
sub1_dep = declare_dependency(include_directories:include_directories('includes'))
```

This triggers error stated above.
Following instruction given in the error and modifying the file like below

```
project('main', 'cpp')

sub1=subproject('sub1')
sub1_dep = dependency('sub1')

executable('exe1','emptyfile', dependencies: [sub1_dep])
```

This gives another error given that sub1 is not defined in package-config or cmake

```
WARNING: Subproject 'sub1' did not override 'sub1' dependency and no variable name specified
Dependency sub1 from subproject subprojects/sub1 found: NO

meson.build:4:0: ERROR: Dependency 'sub1' is required but not found.
```

**Expected behavior**
if the meson.build of the project is modified like below, meson is able to fallback to locating dependency in subprojects

```
sub1=subproject('sub1')
sub1_dep = dependency('sub1', fallback: ['sub1', 'sub1_dep'])
```

or even this

```
sub1=subproject('sub1')
sub1_dep=sub1.get_variable('sub1_dep')
```

It might be more desirable if meson told users to do these instead?

**system parameters**
* Is this a [cross build](https://mesonbuild.com/Cross-compilation.html) or just a plain native build (for the same computer)?
* what operating system (e.g. MacOS Catalina, Windows 10, CentOS 8.0, Ubuntu 18.04, etc.)
* what Python version are you using e.g. 3.8.0
* what `meson --version`
* what `ninja --version` if it's a Ninja build



Discussion:

Resolving patch:
diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py
--- a/mesonbuild/interpreter/interpreter.py
+++ b/mesonbuild/interpreter/interpreter.py
@@ -2215,6 +2215,10 @@ def build_incdir_object(self, incdir_strings: T.List[str], is_system: bool = Fal
                         # In subproject
                         some_dep = declare_dependency(include_directories: include_directories('include'))
 
+                        # In subproject wrap file
+                        [provide]
+                        some = some_dep
+
                         # In parent project
                         some_dep = dependency('some')
                         executable(..., dependencies: [some_dep])


Test patch: