Skip to content

Commit f36602b

Browse files
climblinnejgsogo
authored andcommitted
Example for SVN versioning (#887)
* Example for SVN versioning * Fix typos.
1 parent 33c272b commit f36602b

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

howtos/capture_version.rst

+36
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,42 @@ if it is not able to get the Git data. This is necessary when the recipe is alre
2929
Conan cache, and the Git repository may not be there,. A value of ``None`` makes Conan
3030
get the version from the metadata.
3131

32+
How to capture package version from SCM: svn
33+
============================================
34+
35+
The ``SVN()`` helper from tools, can be used to capture data from the subversion repo in which
36+
the *conanfile.py* recipe resides, and use it to define the version of the Conan package.
37+
38+
.. code-block:: python
39+
40+
from conans import ConanFile, tools
41+
42+
def get_svn_version(version):
43+
try:
44+
scm = tools.SVN()
45+
revision = scm.get_revision()
46+
branch = scm.get_branch() # Delivers e.g trunk, tags/v1.0.0, branches/my_branch
47+
branch = branch.replace("/","_")
48+
if scm.is_pristine():
49+
dirty = ""
50+
else:
51+
dirty = ".dirty"
52+
return "%s-%s+%s%s" % (version, revision, branch, dirty) # e.g. 1.2.0-1234+trunk.dirty
53+
except Exception:
54+
return None
55+
56+
class HelloLibrary(ConanFile):
57+
name = "Hello"
58+
version = get_svn_version("1.2.0")
59+
60+
def build(self):
61+
...
62+
63+
In this example, the package created with :command:`conan create` will be called
64+
``Hello/generated_version@user/channel``. Note that ``get_svn_version()`` returns ``None``
65+
if it is not able to get the subversion data. This is necessary when the recipe is already in the
66+
Conan cache, and the subversion repository may not be there. A value of ``None`` makes Conan
67+
get the version from the metadata.
3268

3369
How to capture package version from text or build files
3470
=======================================================

0 commit comments

Comments
 (0)