|
1 |
| -.. spelling:: |
2 |
| - |
3 |
| - ing |
4 |
| - ver |
5 |
| - |
6 |
| -.. _conan_conanfile_methods: |
| 1 | +.. _reference_conanfile_methods: |
7 | 2 |
|
8 | 3 | Methods
|
9 | 4 | =======
|
10 | 5 |
|
11 | 6 |
|
12 |
| -requirements() |
13 |
| --------------- |
14 |
| - |
15 |
| -Requirement traits |
16 |
| -^^^^^^^^^^^^^^^^^^ |
17 |
| - |
18 |
| -Traits are properties of a requires clause. They determine how various parts of a |
19 |
| -dependency are treated and propagated by Conan. Values for traits are usually computed by |
20 |
| -Conan based on dependency's :ref:`reference_conanfile_attributes_package_type`, but can |
21 |
| -also be specified manually. |
22 |
| - |
23 |
| -A good introduction to traits is provided in the `Advanced Dependencies Model in Conan 2.0 |
24 |
| -<https://youtu.be/kKGglzm5ous>`_ presentation. |
25 |
| - |
26 |
| -In the example below ``headers`` and ``libs`` are traits. |
27 |
| - |
28 |
| -.. code-block:: python |
29 |
| -
|
30 |
| - self.requires("math/1.0", headers=True, libs=True) |
31 |
| -
|
32 |
| -
|
33 |
| -headers |
34 |
| -~~~~~~~ |
35 |
| - |
36 |
| -Indicates that there are headers that are going to be ``#included`` from this package at |
37 |
| -compile time. The dependency will be in the host context. |
38 |
| - |
39 |
| -libs |
40 |
| -~~~~ |
41 |
| - |
42 |
| -The dependency contains some library or artifact that will be used at link time of the |
43 |
| -consumer. This trait will typically be ``True`` for direct shared and static libraries, |
44 |
| -but could be false for indirect static libraries that are consumed via a shared library. |
45 |
| -The dependency will be in the host context. |
46 |
| - |
47 |
| -build |
48 |
| -~~~~~ |
49 |
| - |
50 |
| -This dependency is a build tool, an application or executable, like cmake, that is used |
51 |
| -exclusively at build time. It is not linked/embedded into binaries, and will be in the |
52 |
| -build context. |
53 |
| - |
54 |
| -run |
55 |
| -~~~ |
56 |
| - |
57 |
| -This dependency contains some executables, either apps or shared libraries that need to be |
58 |
| -available to execute (typically in the path, or other system env-vars). This trait can be |
59 |
| -``True`` for ``build=False``, in that case, the package will contain some executables that |
60 |
| -can run in the host system when installing it, typically like an end-user application. |
61 |
| -This trait can be ``True`` for ``build=True``, the package will contain executables that |
62 |
| -will run in the build context, typically while being used to build other packages. |
63 |
| - |
64 |
| -visible |
65 |
| -~~~~~~~ |
66 |
| - |
67 |
| -This ``require`` will be propagated downstream, even if it doesn't propagate ``headers``, |
68 |
| -``libs`` or ``run`` traits. Requirements that propagate downstream can cause version |
69 |
| -conflicts. This is typically ``True``, because in most cases, having 2 different versions of |
70 |
| -the same library in the same dependency graph is at least complicated, if not directly |
71 |
| -violating ODR or causing linking errors. It can be set to ``False`` in advanced scenarios, |
72 |
| -when we want to use different versions of the same package during the build. |
73 |
| - |
74 |
| -transitive_headers |
75 |
| -~~~~~~~~~~~~~~~~~~ |
76 |
| - |
77 |
| -If ``True`` the headers of the dependency will be visible downstream. |
78 |
| - |
79 |
| -transitive_libs |
80 |
| -~~~~~~~~~~~~~~~ |
81 |
| - |
82 |
| -If ``True`` the libraries to link with of the dependency will be visible downstream. |
83 |
| - |
84 |
| -test |
85 |
| -~~~~ |
86 |
| - |
87 |
| -This requirement is a test library or framework, like Catch2 or gtest. It is mostly a |
88 |
| -library that needs to be included and linked, but that will not be propagated downstream. |
89 |
| - |
90 |
| -package_id_mode |
91 |
| -~~~~~~~~~~~~~~~ |
92 |
| - |
93 |
| -If the recipe wants to specify how the dependency version affects the current package |
94 |
| -``package_id``, can be directly specified here. |
95 |
| - |
96 |
| -While it could be also done in the ``package_id()`` method, it seems simpler to be able to |
97 |
| -specify it in the ``requires`` while avoiding some ambiguities. |
98 |
| - |
99 |
| -.. code-block:: python |
100 |
| -
|
101 |
| - # We set the package_id_mode so it is part of the package_id |
102 |
| - self.tool_requires("tool/1.1.1", package_id_mode="minor_mode") |
103 |
| -
|
104 |
| -Which would be equivalent to: |
105 |
| - |
106 |
| -.. code-block:: python |
107 |
| -
|
108 |
| - def package_id(self): |
109 |
| - self.info.requires["tool"].minor_mode() |
110 |
| -
|
111 |
| -force |
112 |
| -~~~~~ |
113 |
| - |
114 |
| -This ``requires`` will force its version in the dependency graph upstream, overriding |
115 |
| -other existing versions even of transitive dependencies, and also solving potential |
116 |
| -existing conflicts. |
117 |
| - |
118 |
| -override |
119 |
| -~~~~~~~~ |
120 |
| - |
121 |
| -The same as the ``force`` trait, but not adding a ``direct`` dependency. If there is no |
122 |
| -transitive dependency to override, this ``require`` will be discarded. This trait only |
123 |
| -exists at the time of defining a ``requires``, but it will not exist as an actual |
124 |
| -``requires`` once the graph is fully evaluated |
125 |
| - |
126 |
| -direct |
127 |
| -~~~~~~ |
128 |
| - |
129 |
| -If the dependency is a direct one, that is, it has explicitly been declared by the current |
130 |
| -recipe, or if it is a transitive one. |
131 |
| - |
132 |
| - |
133 |
| -validate_build() |
134 |
| ----------------- |
135 |
| - |
136 |
| -The ``validate_build()`` method is used to verify if a configuration is valid for building a package. It is different |
137 |
| -from the ``validate()`` method that checks if the binary package is "impossible" or invalid for a given configuration. |
138 |
| - |
139 |
| -The ``validate_build()`` method has to use always the ``self.settings`` and ``self.options``: |
140 |
| - |
141 |
| -.. code-block:: python |
142 |
| -
|
143 |
| - from conan import ConanFile |
144 |
| - from conan.errors import ConanInvalidConfiguration |
145 |
| - class myConan(ConanFile): |
146 |
| - name = "foo" |
147 |
| - version = "1.0" |
148 |
| - settings = "os", "arch", "compiler" |
149 |
| - def package_id(self): |
150 |
| - # For this package, it doesn't matter the compiler used for the binary package |
151 |
| - del self.info.settings.compiler |
152 |
| - def validate_build(self): |
153 |
| - # But we know this cannot be build with "gcc" |
154 |
| - if self.settings.compiler == "gcc": |
155 |
| - raise ConanInvalidConfiguration("This doesn't build in GCC") |
| 7 | +.. toctree:: |
| 8 | + :maxdepth: 1 |
| 9 | + :hidden: |
| 10 | + |
| 11 | + methods/build |
| 12 | + methods/build_id |
| 13 | + methods/build_requirements |
| 14 | + methods/compatibility |
| 15 | + methods/configure |
| 16 | + methods/config_options |
| 17 | + methods/export |
| 18 | + methods/export_sources |
| 19 | + methods/generate |
| 20 | + methods/init |
| 21 | + methods/layout |
| 22 | + methods/package |
| 23 | + methods/package_id |
| 24 | + methods/package_info |
| 25 | + methods/requirements |
| 26 | + methods/set_name |
| 27 | + methods/set_version |
| 28 | + methods/source |
| 29 | + methods/system_requirements |
| 30 | + methods/test |
| 31 | + methods/validate |
| 32 | + methods/validate_build |
| 33 | + |
| 34 | + |
| 35 | +- :doc:`build() <methods/build>`: Contains the build instructions to build a package from source |
| 36 | +- :doc:`build_id() <methods/build_id>`: Allows reusing the same build to create different package binaries |
| 37 | +- :doc:`build_requirements() <methods/build_requirements>`: Defines ``tool_requires`` and ``test_requires`` |
| 38 | +- :doc:`compatibility() <methods/compatibility>`: Defines binary compatibility at the recipe level |
| 39 | +- :doc:`configure() <methods/configure>`: Allows configuring settings and options while computing dependencies |
| 40 | +- :doc:`config_options() <methods/config_options>`: Configure options while computing dependency graph |
| 41 | +- :doc:`export() <methods/export>`: Copies files that are part of the recipe |
| 42 | +- :doc:`export_sources() <methods/export_sources>`: Copies files that are part of the recipe sources |
| 43 | +- :doc:`generate() <methods/generate>`: Generates the files that are necessary for building the package |
| 44 | +- :doc:`init() <methods/init>`: Special initialization of recipe when extending from ``python_requires`` |
| 45 | +- :doc:`layout() <methods/layout>`: Defines the relative project layout, source folders, build folders, etc. |
| 46 | +- :doc:`package() <methods/package>`: Copies files from build folder to the package folder. |
| 47 | +- :doc:`package_id() <methods/package_id>`: Defines special logic for computing the binary ``package_id`` identifier |
| 48 | +- :doc:`package_info() <methods/package_info>`: Provide information for consumers of this package about libraries, folders, etc. |
| 49 | +- :doc:`requirements() <methods/requirements>`: Define the dependencies of the package |
| 50 | +- :doc:`set_name() <methods/set_name>`: Dynamically define the name of a package |
| 51 | +- :doc:`set_version() <methods/set_version>`: Dynamically define the version of a package. |
| 52 | +- :doc:`source() <methods/source>`: Define the dependencies of the package |
| 53 | +- :doc:`system_requirements() <methods/system_requirements>`: Call system package managers like Apt to install system packages |
| 54 | +- :doc:`test() <methods/test>`: Run some simple package test (exclusive of ``test_package``) |
| 55 | +- :doc:`validate() <methods/validate>`: Define if the current package is invalid (cannot work) with the current configuration. |
| 56 | +- :doc:`validate_build() <methods/validate_build>`: Define if the current package cannot be created with the current configuration. |
0 commit comments