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

I want to get the path of a generator-processed file #10836

Open
ouillie opened this issue Sep 21, 2022 · 2 comments
Open

I want to get the path of a generator-processed file #10836

ouillie opened this issue Sep 21, 2022 · 2 comments

Comments

@ouillie
Copy link

ouillie commented Sep 21, 2022

Describe the bug

This is more of a feature request, and I'd be willing to try implementing it if there's currently no good way to accomplish it and there's an appetite for it. Thought I'd file the bug first to make sure it's not a non-starter.

custom_target lets you pass variables in the command like @BUILD_ROOT@ etc. I want to use these variables in the env as well.

To Reproduce
Something like this:

custom_target('target',
              env: {'FOO': '@BUILD_ROOT@'},
              command: ['bash', '-c', 'echo FOO=${FOO}'],
              capture: true,
              output: 'target')

If you run meson compile -C builddir target && cat build/target you'll see FOO=@BUILD_ROOT@ (no substitution occurred).

Expected behavior
Should show FOO=/absolute/path/to/build/root or whatever.

system parameters

  • Is this a cross build or just a plain native build (for the same computer)?
    • Native
  • what operating system (e.g. MacOS Catalina, Windows 10, CentOS 8.0, Ubuntu 18.04, etc.)
    • Posix
  • what Python version are you using e.g. 3.8.0
    • 3.10.6
  • what meson --version
    • 0.63.2
  • what ninja --version if it's a Ninja build
    • 1.11.1
@eli-schwartz
Copy link
Member

In this specific example, you could probably just use env: {'FOO': meson.global_build_root()}.

Or, POSIX specific, you could use command: ['env', 'FOO=@BUILD_ROOT@', 'bash', '-c', 'echo FOO=${FOO}']

...

I'm not sure what to think about making this a supported general feature.

@ouillie
Copy link
Author

ouillie commented Sep 22, 2022

Ok my b I misunderstood @BUILD_ROOT@. What I actually want is only loosely related :/

I'd like to get the path of a file that was generated by a generator. Processing with a generator results in a generated_list, which is specifically documented as an "opaque object".

In this case, I'm passing preserve_path_from: meson.current_source_dir() to the generator's process() method, so the generated file ends up have a path that looks like @BUILD_ROOT@/<target>.p/same/path/structure/as/source (at least on Linux). For my own purposes, I could reconstruct that path using meson.global_build_root(), join_paths() and str.join(), but it's unclear to me if that would be portable, so it seems that a preferable solution would be to somehow inspect the generated_list and get paths by index.

@ouillie ouillie changed the title I want to pass @BUILD_ROOT@ in an environment variable for custom_target I want to get the path of a generator-processed file Sep 22, 2022
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

No branches or pull requests

2 participants