Skip to content

Commit e1bec6e

Browse files
danimtbmemsharded
authored andcommitted
Documents conan --test and should_test (conan-io#733)
1 parent 423afea commit e1bec6e

File tree

3 files changed

+79
-43
lines changed

3 files changed

+79
-43
lines changed

‎changelog.rst‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ Check https://github.com/conan-io/conan for issues and more details about develo
1414
1.6.0 ()
1515
----------------------
1616

17-
- Feature: Added new ``self.run(..., run_environment=True)`` argument, that applies automatically ``PATH``, ``LD_LIBRARY_PATH`` and ``DYLD_LIBRARY_PATH``
18-
environment variable, from the dependencies, to the execution of the current command.
17+
- Feature: Added new ``self.run(..., run_environment=True)`` argument, that applies automatically ``PATH``, ``LD_LIBRARY_PATH`` and
18+
``DYLD_LIBRARY_PATH`` environment variable, from the dependencies, to the execution of the current command.
1919
- Feature: Added new ``self.run(..., ignore_errors=True)`` argument, that inhibits launching an exception if the commands fails, user can
2020
capture the return code.
2121
- Feature: The ``json`` generator now outputs the settings and options
@@ -24,7 +24,10 @@ Check https://github.com/conan-io/conan for issues and more details about develo
2424
- Feature: Added ``filename`` parameter to ``tools.get()`` in case it cannot be deduced from URL.
2525
- Feature: Propagated ``keep_permissions`` and ``pattern`` parameters from ``tools.get()`` to ``tools.unzip()``.
2626
- Feature: Added XZ extensions to ``unzip()``. It will only work in Python 3 with lzma support enabled, producing an error otherwise.
27-
- Feature: Added `FRAMEWORK_SEARCH_PATHS` var to the xcode generator to support packaging Apple Frameworks. Read more :ref:`here<package_apple_framework>`.
27+
- Feature: Added `FRAMEWORK_SEARCH_PATHS` var to the xcode generator to support packaging Apple Frameworks. Read more
28+
:ref:`here<package_apple_framework>`.
29+
- Feature: Added :command:`conan build --test` and ``should_configure`` attribute to control test stage. Read more
30+
:ref:`here<attribute_build_stages>`.
2831

2932

3033
1.5.2 (5-July-2018)

‎reference/commands/development/build.rst‎

Lines changed: 24 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ conan build
66

77
.. code-block:: bash
88
9-
$ conan build [-h] [-b] [-bf BUILD_FOLDER] [-c] [-i] [-if INSTALL_FOLDER]
10-
[-pf PACKAGE_FOLDER] [-sf SOURCE_FOLDER]
9+
$ conan build [-h] [-b] [-bf BUILD_FOLDER] [-c] [-i] [-t]
10+
[-if INSTALL_FOLDER] [-pf PACKAGE_FOLDER]
11+
[-sf SOURCE_FOLDER]
1112
path
1213
1314
Calls your local conanfile.py 'build()' method. The recipe will be built in
@@ -24,18 +25,23 @@ folder will be configured as destination folder for the install step.
2425
optional arguments:
2526
-h, --help show this help message and exit
2627
-b, --build Execute the build step (variable should_build=True).
27-
When specified, configure/install won't run unless
28-
--configure/--install specified
28+
When specified, configure/install/test won't run
29+
unless --configure/--install/--test specified
2930
-bf BUILD_FOLDER, --build-folder BUILD_FOLDER
3031
Directory for the build process. Defaulted to the
3132
current directory. A relative path to current
3233
directory can also be specified
3334
-c, --configure Execute the configuration step (variable
34-
should_configure=True). When specified, build/install
35-
won't run unless --build/--install specified
35+
should_configure=True). When specified,
36+
build/install/test won't run unless
37+
--build/--install/--test specified
3638
-i, --install Execute the install step (variable
37-
should_install=True). When specified, configure/build
38-
won't run unless --configure/--build specified
39+
should_install=True). When specified,
40+
configure/build/test won't run unless
41+
--configure/--build/--test specified
42+
-t, --test Execute the test step (variable should_test=True).
43+
When specified, configure/build/install won't run
44+
unless --configure/--build/--install specified
3945
-if INSTALL_FOLDER, --install-folder INSTALL_FOLDER
4046
Directory containing the conaninfo.txt and
4147
conanbuildinfo.txt files (from previous 'conan
@@ -109,41 +115,20 @@ the files generators file. e.j ``conanbuildinfo.cmake``
109115

110116
**Example**: Control the build stages
111117

112-
Given a conanfile with this ``build()`` method:
113-
114-
.. code-block:: python
115-
116-
def build(self):
117-
cmake = CMake(self)
118-
cmake.configure()
119-
cmake.build()
120-
cmake.install()
121-
122-
If nothing is specified, all three methods will be called. But using command line arguments, this can be changed:
123-
118+
You can control the build stages using :command:`--configure`/:command:`--build`/:command:`--install`/:command:`--test` arguments. Here is
119+
an example using the CMake build helper:
124120

125121
.. code-block:: bash
126122
127-
$ conan build . -c # only run cmake.configure(). Other methods will do nothing
128-
$ conan build . -b # only run cmake.build(). Other methods will do nothing
129-
$ conan build . -i # only run cmake.install(). Other methods will do nothing
123+
$ conan build . --confiure # only run cmake.configure(). Other methods will do nothing
124+
$ conan build . --build # only run cmake.build(). Other methods will do nothing
125+
$ conan build . --install # only run cmake.install(). Other methods will do nothing
126+
$ conan build . --test # only run cmake.test(). Other methods will do nothing
130127
# They can be combined
131-
$ conan build . -c -b # run cmake.configure() + cmake.build(), but not cmake.install()
132-
133-
134-
Autotools and Meson helpers already implement the same functionality. For other build systems, you can use
135-
the following variables in the ``build()`` method:
136-
137-
.. code-block:: python
128+
$ conan build . -c -b # run cmake.configure() + cmake.build(), but not cmake.install() nor cmake.test
138129
139-
def build(self):
140-
if self.should_configure:
141-
# Run my configure stage
142-
if self.should_build:
143-
# Run my build stage
144-
if self.should_install: # If my build has install, otherwise use package()
145-
# Run my install stage
130+
If nothing is specified, all the methods will be called.
146131

132+
.. seealso::
147133

148-
Note these ``should_configure, should_build, should_install`` variables will always be ``True`` while
149-
building in the local cache. They can only be modified for the local flow with :command:`conan build`.
134+
Read more about :ref:`attribute_build_stages`.

‎reference/conanfile/attributes.rst‎

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,13 +483,61 @@ generated, but you can specify different generators and even use more than one.
483483
484484
Check the full :ref:`generators list<generators>`.
485485

486+
.. _attribute_build_stages:
487+
488+
should_configure, should_build, should_install, should_test
489+
-----------------------------------------------------------
490+
491+
Read only variables defaulted to ``True``.
492+
493+
This variables allow you control the build stages of a recipe during a :command:`conan build` command with the optional arguments
494+
:command:`--configure`/:command:`--build`/:command:`--install`/:command:`--test`. For example, given this ``build()`` method:
495+
496+
.. code-block:: python
497+
498+
def build(self):
499+
cmake = CMake(self)
500+
cmake.configure()
501+
cmake.build()
502+
cmake.install()
503+
cmake.test()
504+
505+
If nothing is specified, all four methods will be called. But using command line arguments, this can be changed:
506+
507+
.. code-block:: bash
508+
509+
$ conan build . --configure # only run cmake.configure(). Other methods will do nothing
510+
$ conan build . --build # only run cmake.build(). Other methods will do nothing
511+
$ conan build . --install # only run cmake.install(). Other methods will do nothing
512+
$ conan build . --test # only run cmake.test(). Other methods will do nothing
513+
# They can be combined
514+
$ conan build . -c -b # run cmake.configure() + cmake.build(), but not cmake.install() nor cmake.test()
515+
516+
Autotools and Meson helpers already implement the same functionality. For other build systems, you can use the these variables in the
517+
``build()`` method:
518+
519+
.. code-block:: python
520+
521+
def build(self):
522+
if self.should_configure:
523+
# Run my configure stage
524+
if self.should_build:
525+
# Run my build stage
526+
if self.should_install: # If my build has install, otherwise use package()
527+
# Run my install stage
528+
if self.should_test:
529+
# Run my test stage
530+
531+
Note these ``should_configure``, ``should_build``, ``should_install``, ``should_test`` variables will always be ``True`` while building in
532+
the cache and can be only modified for the local flow with :command:`conan build`.
533+
486534
build_policy
487535
------------
488536

489537
With the ``build_policy`` attribute the package creator can change the default conan's build behavior.
490538
The allowed ``build_policy`` values are:
491539

492-
- ``missing``: If no binary package is found, conan will build it without the need of invoke conan install with **--build missing** option.
540+
- ``missing``: If no binary package is found, Conan will build it without the need of invoke :command:`conan install --build missing` option.
493541
- ``always``: The package will be built always, **retrieving each time the source code** executing the "source" method.
494542

495543
.. code-block:: python

0 commit comments

Comments
 (0)