3 class samba_version(object):
4 def __init__(self
, version_dict
, have_git
=False):
5 '''Determine the version number of samba
7 See VERSION for the format. Entries on that file are
8 also accepted as dictionary entries here
16 self
.ALPHA_RELEASE
=None
19 self
.IS_GIT_SNAPSHOT
=True
20 self
.RELEASE_NICKNAME
=None
21 self
.VENDOR_SUFFIX
=None
22 self
.VENDOR_PATCH
=None
24 for a
, b
in version_dict
.iteritems():
25 if a
.startswith("SAMBA_VERSION_"):
26 setattr(self
, a
[14:], b
)
30 if self
.IS_GIT_SNAPSHOT
== "yes":
31 self
.IS_GIT_SNAPSHOT
=True
32 elif self
.IS_GIT_SNAPSHOT
== "no":
33 self
.IS_GIT_SNAPSHOT
=False
36 ## start with "3.0.22"
38 self
.MAJOR
=int(self
.MAJOR
)
39 self
.MINOR
=int(self
.MINOR
)
40 self
.RELEASE
=int(self
.RELEASE
)
42 SAMBA_VERSION_STRING
= ("%u.%u.%u" % (self
.MAJOR
, self
.MINOR
, self
.RELEASE
))
45 ## maybe add "3.0.22a" or "4.0.0tp11" or "4.0.0alpha1" or "3.0.22pre1" or "3.0.22rc1"
46 ## We do not do pre or rc version on patch/letter releases
48 if self
.REVISION
is not None:
49 SAMBA_VERSION_STRING
+= self
.REVISION
50 if self
.TP_RELEASE
is not None:
51 self
.TP_RELEASE
= int(self
.TP_RELEASE
)
52 SAMBA_VERSION_STRING
+= ("tp%u" % self
.TP_RELEASE
)
53 if self
.ALPHA_RELEASE
is not None:
54 self
.ALPHA_RELEASE
= int(self
.ALPHA_RELEASE
)
55 SAMBA_VERSION_STRING
+= ("alpha%u" % self
.ALPHA_RELEASE
)
56 if self
.PRE_RELEASE
is not None:
57 self
.PRE_RELEASE
= int(self
.PRE_RELEASE
)
58 SAMBA_VERSION_STRING
+= ("pre%u" % self
.PRE_RELEASE
)
59 if self
.RC_RELEASE
is not None:
60 self
.RC_RELEASE
= int(self
.RC_RELEASE
)
61 SAMBA_VERSION_STRING
+= ("rc%u" % self
.RC_RELEASE
)
63 if self
.IS_GIT_SNAPSHOT
:
66 git
= Utils
.cmd_output('git show --pretty=format:"%h%n%ct%n%H%n%cd" --stat HEAD', silent
=True)
71 SAMBA_VERSION_STRING
+= "-GIT-UNKNOWN"
73 lines
= git
.splitlines();
74 self
.GIT_COMMIT_ABBREV
= lines
[0]
75 self
.GIT_COMMIT_TIME
= lines
[1]
76 self
.GIT_COMMIT_FULLREV
= lines
[2]
77 self
.GIT_COMMIT_DATE
= lines
[3]
79 SAMBA_VERSION_STRING
+= ("-GIT-" + self
.GIT_COMMIT_ABBREV
)
81 clean
= Utils
.cmd_output('git diff HEAD | wc -l', silent
=True)
83 self
.GIT_COMMIT_IS_CLEAN
= True
85 self
.GIT_COMMIT_IS_CLEAN
= False
86 SAMBA_VERSION_STRING
+= "+"
88 self
.OFFICIAL_STRING
=SAMBA_VERSION_STRING
90 if self
.VENDOR_SUFFIX
is not None:
91 SAMBA_VERSION_STRING
+= ("-" + self
.VENDOR_SUFFIX
)
92 self
.VENDOR_SUFFIX
= self
.VENDOR_SUFFIX
94 if self
.VENDOR_PATCH
is not None:
95 SAMBA_VERSION_STRING
+= ("-" + self
.VENDOR_PATCH
)
96 self
.VENDOR_PATCH
= self
.VENDOR_PATCH
98 self
.STRING
= SAMBA_VERSION_STRING
100 if self
.RELEASE_NICKNAME
is not None:
101 self
.STRING_WITH_NICKNAME
+= (" (" + self
.RELEASE_NICKNAME
+ ")")
102 self
.RELEASE_NICKNAME
= self
.RELEASE_NICKNAME
104 self
.STRING_WITH_NICKNAME
= self
.STRING
107 string
="/* Autogenerated by waf */\n"
108 string
+="#define SAMBA_VERSION_MAJOR %u\n" % self
.MAJOR
109 string
+="#define SAMBA_VERSION_MINOR %u\n" % self
.MINOR
110 string
+="#define SAMBA_VERSION_RELEASE %u\n" % self
.RELEASE
111 if self
.REVISION
is not None:
112 string
+="#define SAMBA_VERSION_REVISION %u\n" % self
.REVISION
114 if self
.TP_RELEASE
is not None:
115 string
+="#define SAMBA_VERSION_TP_RELEASE %u\n" % self
.TP_RELEASE
117 if self
.ALPHA_RELEASE
is not None:
118 string
+="#define SAMBA_VERSION_ALPHA_RELEASE %u\n" % self
.ALPHA_RELEASE
120 if self
.PRE_RELEASE
is not None:
121 string
+="#define SAMBA_VERSION_PRE_RELEASE %u\n" % self
.PRE_RELEASE
123 if self
.RC_RELEASE
is not None:
124 string
+="#define SAMBA_VERSION_RC_RELEASE %u\n" % self
.RC_RELEASE
127 string
+="#define SAMBA_VERSION_GIT_COMMIT_ABBREV \"" + self
.GIT_COMMIT_ABBREV
+ "\"\n"
128 string
+="#define SAMBA_VERSION_GIT_COMMIT_FULLREV \"" + self
.GIT_COMMIT_FULLREV
+ "\"\n"
129 string
+="#define SAMBA_VERSION_GIT_COMMIT_DATE \"" + self
.GIT_COMMIT_DATE
+ "\"\n"
130 string
+="#define SAMBA_VERSION_GIT_COMMIT_TIME " + self
.GIT_COMMIT_TIME
+ "\n"
131 if self
.GIT_COMMIT_IS_CLEAN
:
132 string
+="#define SAMBA_VERSION_GIT_COMMIT_IS_CLEAN 1\n"
133 except AttributeError:
136 string
+="#define SAMBA_VERSION_OFFICIAL_STRING \"" + self
.OFFICIAL_STRING
+ "\"\n"
138 if self
.VENDOR_SUFFIX
is not None:
139 string
+="#define SAMBA_VERSION_VENDOR_SUFFIX " + self
.VENDOR_SUFFIX
+ "\n"
140 if self
.VENDOR_PATCH
is not None:
141 string
+="#define SAMBA_VERSION_VENDOR_PATCH " + self
.VENDOR_PATCH
+ "\n"
143 if self
.RELEASE_NICKNAME
is not None:
144 string
+="#define SAMBA_VERSION_RELEASE_NICKNAME " + self
.RELEASE_NICKNAME
+ "\n"
146 # We need to put this #ifdef in to the headers so that vendors can override the version with a function
148 #ifdef SAMBA_VERSION_VENDOR_FUNCTION
149 # define SAMBA_VERSION_STRING SAMBA_VERSION_VENDOR_FUNCTION
150 #else /* SAMBA_VERSION_VENDOR_FUNCTION */
151 # define SAMBA_VERSION_STRING "''' + self
.STRING_WITH_NICKNAME
+ '''"
154 string
+="/* Version for mkrelease.sh: \nSAMBA_VERSION_STRING=" + self
.STRING_WITH_NICKNAME
+ "\n */\n"
159 class samba_version_file(samba_version
):
160 def __init__(self
, version_file
, have_git
=False):
161 '''Parse the version information from a VERSION file'''
162 f
= open(version_file
, 'r')
169 if line
.startswith("#"):
171 split_line
=line
.split("=")
172 if split_line
[1] != "":
173 value
= split_line
[1].strip('"')
174 version_dict
[split_line
[0]] = value
176 print("Failed to parse line %s from %s" % (line
, version_file
))
179 super(samba_version_file
, self
).__init
__(version_dict
, have_git
=have_git
)