@@ -24,11 +24,9 @@ the right environment variable set, so they will be able to locate the (A) share
2424Similarly if you use the :ref: `virtualenv generator<virtual_environment_generator> ` and you
2525activate it, you will get the paths needed to locate the shared libraries in your terminal.
2626
27-
2827Example
2928-------
3029
31-
3230We are packaging a tool called ``toolA `` with a library and an executable that, for example, compress data.
3331
3432The package offers two flavors, shared library or static library (embedded in the executable of the tool and
@@ -49,7 +47,6 @@ you will need to have the shared library available.
4947 options = {" shared" : [True , False ]}
5048 default_options = " shared=False"
5149
52-
5350 def build (self ):
5451 # build your shared library
5552
@@ -65,40 +62,28 @@ you will need to have the shared library available.
6562 else :
6663 ...
6764
68-
69- def package_info (self ):
70- self .env_info.PATH .append(os.path.join(self .package_folder, " bin" ))
71- if self .options.shared:
72- self .env_info.LD_LIBRARY_PATH .append(os.path.join(self .package_folder, " lib" ))
73- self .env_info.DYLD_LIBRARY_PATH .append(os.path.join(self .package_folder, " lib" ))
74-
75-
76-
7765 Using the tool from a different package
7866---------------------------------------
7967
8068If we are creating now a package that uses the ``ToolA `` executable to compress some data. You can
81- call directly to the ``toolA.exe ``, the required environment variables to locate both the executable
82- and the shared libraries are automatically available:
69+ execute directly ``toolA `` using RunEnvironment build helper to set the environment variables accordingly:
8370
8471.. code-block :: python
8572
8673 import os
8774 from conans import tools, ConanFile
8875
8976 class PackageB (ConanFile ):
90- ... .
9177 name = " packageB"
9278 version = " 1.0"
9379 requires = " toolA/1.0@myuser/stable"
9480
95-
9681 def build (self ):
97- ...
98- # we can call directly the ``toolA`` executable. the shared library will be located too
9982 exe_name = " toolA.exe" if self .settings.os == " Windows" else " toolA"
100- self .run(" %s --someparams" % exe_name)
101- ...
83+ env_build = RunEnvironment(self )
84+ with tools.environment_append(env_build.vars):
85+ self .run(" %s --someparams" % exe_name)
86+ ...
10287
10388 Building an application using the shared library from ``toolA ``
10489---------------------------------------------------------------
@@ -107,9 +92,8 @@ As we are building a final application, probably we will want to distribute it t
10792shared library from the ``toolA ``, so we can use the :ref: `Imports<imports_txt> ` to import the required
10893shared libraries to our user space.
10994
110- **conanfile.txt **
111-
11295.. code-block :: python
96+ :caption: * conanfile.txt*
11397
11498 [requires]
11599 toolA/ 1.0 @ myuser/ stable
@@ -125,8 +109,7 @@ shared libraries to our user space.
125109 lib, * .dylib* -> ./ bin # Copies all dylib files from packages lib folder to my "bin" folder
126110 lib, * .so* -> ./ bin # Copies all dylib files from packages lib folder to my "bin" folder
127111
128-
129- **In the terminal window and build the project: **
112+ Now you can build the project:
130113
131114.. code-block :: bash
132115
@@ -146,67 +129,35 @@ In Linux you still need to set the ``LD_LIBRARY_PATH``, or in OSX, the ``DYLD_LI
146129
147130 $ cd bin && LD_LIBRARY_PATH=$( pwd) && ./mytool
148131
149-
150132 Using shared libraries from dependencies
151- ------------------------------------------
133+ ----------------------------------------
152134
153135If you are executing something that depends on shared libraries belonging to your dependencies, such shared libraries have to be found at
154136runtime. In Windows, it is enough if the package added its binary folder to the system ``PATH ``. In Linux and OSX, it is necessary that the
155137``LD_LIBRARY_PATH `` and ``DYLD_LIBRARY_PATH `` environment variables are used.
156138
157139Security restrictions might apply in OSX
158140(`read this thread <https://stackoverflow.com/questions/35568122/why-isnt-dyld-library-path-being-propagated-here >`_), so the
159- ``DYLD_LIBRARY_PATH `` environment variable is not directly transferred to the child process. In that case, you have to use it explicitely in
160- your conanfile.py:
141+ ``DYLD_LIBRARY_PATH `` environment variable is not directly transferred to the child process. In that case, you have to use it explicitly in
142+ your * conanfile.py * :
161143
162144.. code-block :: python
163145
164146 def test (self ):
165147 # self.run('./myexe") # won't work, even if 'DYLD_LIBRARY_PATH' is in the env
166- self .run(' DYLD_LIBRARY_PATH=%s ./myexe" % o s.environ[' DYLD_LIBRARY_PATH ' ])
167-
168-
169-
170- Using the ** virtualenv** generator
171- ----------------------------------
172-
173- We could also use a :ref:`virtualenv generator< virtual_environment_generator> ` to get the
174- `` toolA`` executable available:
175-
176- ** conanfile.txt**
148+ with tools.environment_append({" DYLD_LIBRARY_PATH" : [self .deps_cpp_info[" toolA" ].lib_paths]}):
149+ self .run(' DYLD_LIBRARY_PATH=%s ./myexe" % o s.environ[' DYLD_LIBRARY_PATH ' ])
177150
178- .. code- block:: python
179-
180- [requires]
181- toolA/ 1.0 @ myuser/ stable
182-
183- [options]
184- toolA:shared = True
151+ Or you could use `` RunEnvironment`` helper described above.
185152
186- [generators]
187- virtualenv
153+ Using `` virtualrunenv `` generator
154+ -------------------------------- -
188155
189-
190- ** In the terminal window:**
191-
192- .. code- block:: bash
193-
194- conan install .
195- source activate
196- toolA -- someparams
197-
198-
199- Using the ** virtualrunenv** generator
200- ------------------------------------ -
201-
202- Even if `` toolA`` doesn' t declare the variables in the ``package_info`` method, you can use
203- the :ref:`virtualrunenv generator< virtual_run_environment_generator> ` . It will set automatically
204- the environment variables poiting to the " lib" and " bin" folders.
205-
206-
207- ** conanfile.txt**
156+ :ref:`virtualrunenv generator< virtual_run_environment_generator> ` will set the environment variables `` PATH `` , `` LD_LIBRARY_PATH `` ,
157+ `` DYLD_LIBRARY_PATH `` pointing to * lib* and * bin * folders automatically.
208158
209159.. code- block:: python
160+ :caption: * conanfile.txt*
210161
211162 [requires]
212163 toolA/ 1.0 @ myuser/ stable
@@ -215,14 +166,14 @@ the environment variables poiting to the "lib" and "bin" folders.
215166 toolA:shared = True
216167
217168 [generators]
218- virtualenv
169+ virtualrunenv
219170
220-
221- ** In the terminal window:**
171+ In the terminal window:
222172
223173.. code- block:: bash
224174
225- conan install .
226- source activate
227- toolA -- someparams
228-
175+ $ conan install .
176+ $ source activate_run
177+ $ toolA -- someparams
178+ # Only For Mac OS users to avoid restrictions:
179+ $ DYLD_LIBRARY_PATH = $ DYLD_LIBRARY_PATH toolA -- someparams
0 commit comments