docs
docs copied to clipboard
Improve documentation regarding custom `scope` in `EnvVars` and `env` argument of `self.run`
In https://docs.conan.io/en/1.51/reference/conanfile/tools/env/envvars.html#creating-environment-files, it is explained how to aggregate calls of scripts in conanbuild script with scope="build", or in conanrun script with scope="run".
Actually in https://github.com/conan-io/conan-center-index/pull/12598, I wanted to inject some variables in a specific scope without polluting build or run scopes, then refer to it in self.run. And the documentation is not very clear, I had to make some extrapolations based on documentation, and finally get a working solution.
-
Please explain that you can use any custom
scopename, aggregating the calls of one or several scripts in a scriptconan<scopename>. And then you can refer to it inenvargument ofself.runwithconan<scopename>. Currently documentation is too focused on the built-inbuild&runscopes (except one sentence in https://docs.conan.io/en/1.51/reference/conanfile/tools/env/environment.html#obtaining-environment-variables), which can be misleading. -
Also it would be nice to explain how to create a custom
scopeaggregating custom scripts and script ofVirtualBuildEnv(again to not pollutebuildscope), while still having the script ofVirtualBuildEnvinbuildscope. So basically is it possible to pass an array of values toscopeargument so that a script can be wrapped in severalscope? Something like this maybe:def generate(self): env1 = VirtualBuildEnv(self) env1.generate(scope=["build", "custom"]) env2 = Environment() env2.define("FOO", "bar") env2vars = env2.vars(self, scope="custom") env2vars.save_script("custom_env_file") def build(self): self.run("...") # I need build scope here (implicit), but I do not want FOO self.run("...", env="conancustom") # I need my custom scope which contains my FOO variable & variables from VirtualBuildEnv -
https://docs.conan.io/en/1.51/reference/conanfile/tools/env/environment.html#variable-declaration should say that you can also give a python array of paths to
define_path,append_pathandprepend_path, and that it's properly translated to corresponding syntax depending on build OS. -
It is not clear whether
buildenv_infooftool_requires(andrunenv_infoof theirrequires) coming from a host profile are automatically injected inbuildscope (regardless of recipe generators since obviously a recipe should be agnostic to these profile details) or not. -
Could you clarify whether
buildenv_infoof "internal"tool_requiresof a recipe (I mean not coming from a host profile, but hardcoded in the recipe) are automatically injected tobuildscope or if it requires an explicitVirtualBuildEnvin generators? If explicitVirtualBuildEnvis required, maybe add a big rule of thumb stating that as soon as a recipe has at least onetool_requires, it should haveVirtualBuildEnvin its generators? -
The documentation doesn't explain in which methods of conan v2 build helpers (
conan.tools.cmake.CMake,conan.tools.meson.Mesonetc)conanbuildis automatically called. -
The documentation doesn't say whether variables from
VirtualRunEnvare automatically injected inconfigure()method ofAutotoolshelper when there isAutotoolsDepsand in case of native build, so thatconfigurecan succeed in case of shared dependencies (if native build, autotools configuration runs test executables to check working compiler, and ifLIBShas been populated with shared libs, it fails if this test executable can't find these shared libs at runtime). If it's not automatically handled, it would be a very good idea to explain that recipes authors must injectVirtualRunEnvinbuildscope if: autotools will call configure AND there are dependencies ANDAutotoolsDepsis in generators AND not cross-building. -
Finally, some code examples are incorrect.
Environment(self)is invalid, it'sEnvironment()(at least in conan 1.51.3).
(by the way I've also tried scope=None, and it raised an error:
ERROR: emsdk/3.1.18: Error in generate() method, line 73
envvars = env.vars(self, scope=None)
AttributeError: 'NoneType' object has no attribute 'startswith'
)