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

AutotoolsDeps and environment access #2155

Merged
merged 3 commits into from
Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions reference/conanfile/tools/env/environment.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. _conan_tools_env_environment:

Environment
===========

Expand All @@ -20,8 +22,10 @@ It allows different operations like:
env.define("MYVAR1", "MyValue1") # Overwrite previously existing MYVAR1 with new value
env.append("MYVAR2", "MyValue2") # Append to existing MYVAR2 the new value
env.prepend("MYVAR3", "MyValue3") # Prepend to existing MYVAR3 the new value
env.remove("MYVAR3", "MyValue3") # Remove the MyValue3 from MYVAR3
env.unset("MYVAR4") # Remove MYVAR4 definition from environment


# And the equivalent with paths
env.define_path("MYPATH1", "path/one") # Overwrite previously existing MYPATH1 with new value
env.append_path("MYPATH2", "path/two") # Append to existing MYPATH2 the new value
Expand Down Expand Up @@ -78,6 +82,18 @@ Environments can be applied in the python environment:
...


You can iterate an Environment object:

.. code:: python

env1 = Environment()
env1.append("foo", "var")
env1.append("foo", "var2")
for name, value in env.items():
assert name == "foo":
assert value == "var var2"


There are some places where this ``Environment`` is used:

- In recipes ``package_info()`` method, in new ``self.buildenv_info`` and ``self.runenv_info``.
Expand Down
19 changes: 18 additions & 1 deletion reference/conanfile/tools/gnu/autotoolsdeps.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,21 @@ At this moment, only the ``requires`` information is generated, the ``build_requ
Attributes
++++++++++

At this moment, it is pending to expose attributes to let the user modify the behavior before calling ``generate()``
* **environment** : :ref:`Environment<conan_tools_env_environment>` object containing the computed variables. If you need
to modify some of the computed values you can access to the ``environment`` object.

.. code:: python

from conans import ConanFile
from conan.tools.gnu import AutotoolsDeps

class App(ConanFile):
settings = "os", "arch", "compiler", "build_type"

def generate(self):
tc = AutotoolsDeps(self)
tc.environment.remove("CPPFLAGS", "undesired_value")
tc.environment.append("CPPFLAGS", "var")
tc.environment.define("OTHER", "cat")
tc.environment.unset("LDFLAGS")
tc.generate()