Comments (17)
Hi @Ed-CMI
Thanks for your question.
It is not very clear where and when you want to read this. If this is an environment variable set in the system, it would be a os.environ.get()
or os.getenv()
or similar.
But Conan does not set the env-vars in memory, but in script files like conanbuildenv.sh
and the like.
Also env-vars can be defined, appended, prepended from different places, like in a profile file [buildenv]
section, or in a recipe generate()
method, depending what generator is collecting the CPPFLAGS from where (like defined from dependencies with the PkgConfigDeps
generator? It is also possible to run commands without activating environment-variables by disabling the env
files in self.run()
.
from conan.
CPPFLAGS is created when running AutoToolsDeps. I wanted to read the CPPFLAGS in the generate method to gather the list of include directories that were collected based off requires used in recipe files so I can create an option file to be used during compilation. During our integration recipe file the CPPFLAGS is getting to large and when trying to invoking the makefile the following error is generated.
ConanException: Error 3221225477 while executing
from conan.
I see.
The AutotoolsDeps
can customize its environment as defined in the docs in https://docs.conan.io/2/reference/tools/gnu/autotoolsdeps.html#customization.
Basically the environment
attribute gives access to the environment definition, and allow manipulating it if desired.
from conan.
I have read thru this and will unset the variable but I need to read it first. How can I read CPPFLAG before I unset the variable? The Envvars class has a way to get environment variables but I did not see this in AutoToolsDeps.
from conan.
It is an Environment
object, first step is obtain the vars
as documented in https://docs.conan.io/2/reference/tools/env/environment.html#obtaining-environment-variables, something like envvars = env.vars(self, scope="build")
, then you can do a get()
over it (see https://docs.conan.io/2/reference/tools/env/envvars.html)
from conan.
I tried this logic before but the _include_paths kept indicating None. Am I doing something wrong?
env = Environment()
envvars = env.vars(self, scope="build")
_include_paths = envvars.get("CPPFLAGS", default=None, variable_reference=None)
print(f"Include Paths = {_include_paths}\n")
from conan.
You are instantiating a new Environnment
instead of using the one from AutotoolsDeps.environment
. Please check the above docs link: https://docs.conan.io/2/reference/tools/gnu/autotoolsdeps.html#customization
def generate(self):
tc = AutotoolsDeps(self)
tc.environment.remove("CPPFLAGS", "undesired_value")
it is the tc.environment
not a new (empty) Environment
object one, which is expected to return None
.
from conan.
Sorry Diego but I dont understand this response. My last comment ask why this code return None instead of the data currently stored in CPPFLAGS.
env = Environment()
envvars = env.vars(self, scope="build")
_include_paths = envvars.get("CPPFLAGS", default=None, variable_reference=None)
print(f"Include Paths = {_include_paths}\n")
from conan.
You are instantiating an empty env = Environment()
object. That object is empty, it doesn't contain any env-vars defined untill someone adds information to it, like env.define()
or one of the other methods. Having an empty Environment
object and calling env.get()
over it will always return None
, because that object is empty.
There is no "data currently in CPPFLAGS", the information is not stored in the global system environment variable. That information, if using AutotoolsDeps
comes from the AutotoolsDeps.environment
not over an empty Environment()
object not connected to the AutotoolsDeps
.
from conan.
Ok, Then we are back to my orginal question. How can I get the information stored in CPPFLAGS from AutoToolsDeps or is there another way to get all the includes from all the required recipe files included in the my integration recipe file?
from conan.
Ok, Then we are back to my orginal question. How can I get the information stored in CPPFLAGS from AutoToolsDeps or is there another way to get all the includes from all the required recipe files included in the my integration recipe file?
def generate(self):
tc = AutotoolsDeps(self)
env = tc.environment
myenvvar = env.get("MYENVVAR")
... # whatever you do with the env-var contents
# you can also call other ``env`` methods
tc.generate()
from conan.
I tried your suggestion and got the following error when using this code
tc = AutotoolsDeps(self)
env = tc.environment
_include_paths = env.get("CPPFLAGS")
ERROR: accellimrqstcoord/1.0.0.0: Error in generate() method, line 84
self.python_requires["csarbuildenvrequires"].module.csar_generate(self)
while calling 'csar_generate', line 108
_include_paths = env.get("CPPFLAGS")
AttributeError: 'Environment' object has no attribute 'get'
from conan.
Sorry, my bad, I forgot to use the EnvVars
described above:
def generate(self):
tc = AutotoolsDeps(self)
env = tc.environment
myenvvar = env.vars.get("MYENVVAR")
... # whatever you do with the env-var contents
# you can also call other ``env`` methods
tc.generate()
Please try that and let me know.
from conan.
Same issue when using myenvvar = env.vars.get("MYENVVAR")
accellimrqstcoord/1.0.0.0: Number of Processors = 24
ERROR: accellimrqstcoord/1.0.0.0: Error in generate() method, line 84
self.python_requires["csarbuildenvrequires"].module.csar_generate(self)
while calling 'csar_generate', line 108
_include_paths = env.vars.get("CPPFLAGS")
AttributeError: 'function' object has no attribute 'get'
from conan.
I am writing the code by heart, I am not checking it, the docs contain the exact interfaces to use.
This is more tested, it shouldn't fail:
def generate(self):
deps = AutotoolsDeps(self)
env = deps.environment
vars = env.vars(self)
cppflags = vars.get("CPPFLAGS")
...
deps.generate()
from conan.
This worked. Thanks. Can you provide a link to where this is documented. I tried to check version 2.2 documentation of Conan and can't find this reference.
from conan.
- https://docs.conan.io/2/reference/tools/gnu/autotoolsdeps.html#customization defines the usage of
deps.environment
and returns anEnvironment
object - The
Environment
has a link, follow it for https://docs.conan.io/2/reference/tools/env/environment.html#obtaining-environment-variables, for theenvvars = env.vars(self, scope="build")
environment variables object - Then you have the reference for
EnvVars
in https://docs.conan.io/2/reference/tools/env/envvars.html, including the.get()
method
Closing the ticket as solved, thanks for the feedback!
from conan.
Related Issues (20)
- [bug] unable to install openssl/3.2.1 recipe with conan version: 2.0.17 HOT 4
- [question] autotools with CFLAGS/LDFLAGS HOT 5
- [question] How to Conan download binaries and find binaries HOT 5
- Cache Gets wrong package[bug] HOT 8
- [question] Recommended way of calling conan from python program HOT 8
- [question] Problem deploying oneMKL prepackaged binaries in custom package HOT 21
- [bug] tools.build:compiler_executables won't work with Meson due to spaces in the compiler path HOT 5
- Cannot install qt 6.7.0 prebuilt binary on Windows HOT 5
- [question] How to use editable library with cmake's conan provider file HOT 2
- [bug] `qt` install broken since 2.3.0 HOT 2
- [question] How can I not export sources when creating a package and publishing it HOT 3
- [question] Compatibility Issues HOT 5
- Conan CLI: Add option to conan remove to just skip without error if package does not exist HOT 2
- [feature] expose CMakeToolchain conf to be able to set CMAKE_GENERATOR_INSTANCE HOT 1
- conan export-pkg command not passing --version to the recipe with Conan 2.2.3 HOT 10
- [question] Revision mismatch between OSes HOT 1
- [bug] detect_api.detect_clang_compiler provides the minor version of the compiler HOT 4
- SSLError: HTTPSConnectionPool HOT 2
- [question] "control" cmake include dir variable HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from conan.