@@ -29,6 +29,42 @@ if it is not able to get the Git data. This is necessary when the recipe is alre
29
29
Conan cache, and the Git repository may not be there,. A value of ``None `` makes Conan
30
30
get the version from the metadata.
31
31
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.
32
68
33
69
How to capture package version from text or build files
34
70
=======================================================
0 commit comments