Git Product home page Git Product logo

Comments (17)

memsharded avatar memsharded commented on July 18, 2024

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.

Ed-CMI avatar Ed-CMI commented on July 18, 2024

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.

memsharded avatar memsharded commented on July 18, 2024

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.

Ed-CMI avatar Ed-CMI commented on July 18, 2024

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.

memsharded avatar memsharded commented on July 18, 2024

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.

Ed-CMI avatar Ed-CMI commented on July 18, 2024

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.

memsharded avatar memsharded commented on July 18, 2024

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.

Ed-CMI avatar Ed-CMI commented on July 18, 2024

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.

memsharded avatar memsharded commented on July 18, 2024

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.

Ed-CMI avatar Ed-CMI commented on July 18, 2024

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.

memsharded avatar memsharded commented on July 18, 2024

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.

Ed-CMI avatar Ed-CMI commented on July 18, 2024

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.

memsharded avatar memsharded commented on July 18, 2024

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.

Ed-CMI avatar Ed-CMI commented on July 18, 2024

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.

memsharded avatar memsharded commented on July 18, 2024

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.

Ed-CMI avatar Ed-CMI commented on July 18, 2024

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.

memsharded avatar memsharded commented on July 18, 2024

Closing the ticket as solved, thanks for the feedback!

from conan.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.