Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add subproject.build_root() #10409

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tristan957
Copy link
Contributor

Imagine a C project with a subproject that is its Python bindings. The C
project makes use of the Python bindings to use a higher level language
for writing tests. In order to properly set PYTHONPATH in the tests'
environments, you need to know the subprojects build root, so that the
generated module is visibile when the test imports it. By exposing the
subproject's build root, the parent project can easily set the
PYTHONPATH to resolve the import.

Fixes #8302

Imagine a C project with a subproject that is its Python bindings. The C
project makes use of the Python bindings to use a higher level language
for writing tests. In order to properly set PYTHONPATH in the tests'
environments, you need to know the subprojects build root, so that the
generated module is visibile when the test imports it. By exposing the
subproject's build root, the parent project can easily set the
PYTHONPATH to resolve the import.
@tristan957
Copy link
Contributor Author

Assuming this gets accepted, I wouldn't mind also having a source_root()

@codecov
Copy link

codecov bot commented May 19, 2022

Codecov Report

Merging #10409 (6459a74) into master (cf86b2f) will decrease coverage by 0.48%.
The diff coverage is n/a.

❗ Current head 6459a74 differs from pull request most recent head 5e23403. Consider uploading reports for the commit 5e23403 to get more accurate results

@@            Coverage Diff             @@
##           master   #10409      +/-   ##
==========================================
- Coverage   68.73%   68.24%   -0.49%     
==========================================
  Files         406      203     -203     
  Lines       87650    43831   -43819     
  Branches    19486     9743    -9743     
==========================================
- Hits        60249    29914   -30335     
+ Misses      22862    11609   -11253     
+ Partials     4539     2308    -2231     
Impacted Files Coverage Δ
compilers/mixins/clang.py 56.09% <0.00%> (-14.64%) ⬇️
scripts/coverage.py 56.43% <0.00%> (-7.93%) ⬇️
compilers/mixins/gnu.py 81.10% <0.00%> (-0.47%) ⬇️
mtest.py 77.35% <0.00%> (-0.43%) ⬇️
interpreter/mesonmain.py 97.08% <0.00%> (-0.37%) ⬇️
backend/backends.py 86.73% <0.00%> (-0.25%) ⬇️
backend/ninjabackend.py 77.58% <0.00%> (-0.14%) ⬇️
mesonbuild/interpreter/interpreterobjects.py
mesonbuild/compilers/cython.py
mesonbuild/scripts/meson_exe.py
... and 201 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cf86b2f...5e23403. Read the comment docs.

@tristan957
Copy link
Contributor Author

I am going to advocate for this again. In some Go bindings for a C library that I have been working on, I need to set the CGO_CFLAGS so that header files are visible. In the case of the installed C library, I can use dep.get_variable('includedir'), but in the case of the subproject being used when the installed library isn't available, I cannot just add an includedir variable to the dep because I have some public headers being generated and others in the source tree, so I need to pass two paths to CGO_CFLAGS. I have worked around it by doing the following:

cgo_env.set('CGO_CFLAGS', '-I@0@ -I@1@'.format(hse_dep.get_variable('includedir'), meson.global_build_root() / 'subprojects/hse/include')

Obviously this is not ideal because subprojects/hse is an implementation detail.

cc @eli-schwartz

@eli-schwartz
Copy link
Member

eli-schwartz commented Jun 13, 2022

I thought I already commented on this but apparently not...

I don't really understand the rationale for this. It can inherently be done with subp.get_variable('build_root') instead, plus an accompanying variable assignment in the subproject.

And, in general this involves poking at subproject internals, which we would usually say means the subproject should collaborate with this use case by exporting whatever variables are necessary.

As for the specificity of this case exactly, this feels very much a solution to the wrong problem. The actual problem is that you want to get include_directories() attributes from a dep object and pass them as gcc-compatible flags to a custom target (or an env object applying to a custom target) in order to work around the fact that golang doesn't have built-in support.

So, hard NACK. If we are going to add API here, I'm strongly of the opinion that subp.get_variable() is wrong and you actually want idk, dep.cflags_as_string().

The backwards-compatible way to do this using existing API would be to have the subproject define

cgo_cflags = '-I@0@ -I@1@'.format(meson.project_source_root() /'include', meson.project_build_root() / 'include')

And either retrieve that via hse_dep.get_variable('cgo_cflags') or hse_subp.get_variable('cgo_cflags').

@eli-schwartz
Copy link
Member

Relevant: #5468

@tristan957
Copy link
Contributor Author

Makes sense. Essentially, I want access to the cflags and libflags for a dependency. I need them for both internal and pkgconfig dependency types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a subproject.build_root() function
2 participants