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
is "yes":
31 self
.IS_GIT_SNAPSHOT
=True
32 elif self
.IS_GIT_SNAPSHOT
is "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 self
.OFFICIAL_STRING
=SAMBA_VERSION_STRING
83 if self
.VENDOR_SUFFIX
is not None:
84 SAMBA_VERSION_STRING
+= ("-" + self
.VENDOR_SUFFIX
)
85 self
.VENDOR_SUFFIX
= self
.VENDOR_SUFFIX
87 if self
.VENDOR_PATCH
is not None:
88 SAMBA_VERSION_STRING
+= ("-" + self
.VENDOR_PATCH
)
89 self
.VENDOR_PATCH
= self
.VENDOR_PATCH
91 self
.STRING
= SAMBA_VERSION_STRING
93 if self
.RELEASE_NICKNAME
is not None:
94 self
.STRING_WITH_NICKNAME
+= (" (" + self
.RELEASE_NICKNAME
+ ")")
95 self
.RELEASE_NICKNAME
= self
.RELEASE_NICKNAME
97 self
.STRING_WITH_NICKNAME
= self
.STRING
100 string
="/* Autogenerated by waf */\n"
101 string
+="#define SAMBA_VERSION_MAJOR %u\n" % self
.MAJOR
102 string
+="#define SAMBA_VERSION_MINOR %u\n" % self
.MINOR
103 string
+="#define SAMBA_VERSION_RELEASE %u\n" % self
.RELEASE
104 if self
.REVISION
is not None:
105 string
+="#define SAMBA_VERSION_REVISION %u\n" % self
.REVISION
107 if self
.TP_RELEASE
is not None:
108 string
+="#define SAMBA_VERSION_TP_RELEASE %u\n" % self
.TP_RELEASE
110 if self
.ALPHA_RELEASE
is not None:
111 string
+="#define SAMBA_VERSION_ALPHA_RELEASE %u\n" % self
.ALPHA_RELEASE
113 if self
.PRE_RELEASE
is not None:
114 string
+="#define SAMBA_VERSION_PRE_RELEASE %u\n" % self
.PRE_RELEASE
116 if self
.RC_RELEASE
is not None:
117 string
+="#define SAMBA_VERSION_RC_RELEASE %u\n" % self
.RC_RELEASE
120 string
+="#define SAMBA_VERSION_GIT_COMMIT_ABBREV " + self
.GIT_COMMIT_ABBREV
+ "\n"
121 string
+="#define SAMBA_VERSION_GIT_COMMIT_TIME " + self
.GIT_COMMIT_TIME
+ "\n"
122 string
+="#define SAMBA_VERSION_GIT_COMMIT_FULLREV " + self
.GIT_COMMIT_TIME
+ "\n"
123 string
+="#define SAMBA_VERSION_GIT_COMMIT_DATE " + self
.GIT_COMMIT_DATA
+ "\n"
124 except AttributeError:
127 string
+="#define SAMBA_VERSION_OFFICIAL_STRING \"" + self
.OFFICIAL_STRING
+ "\"\n"
129 if self
.VENDOR_SUFFIX
is not None:
130 string
+="#define SAMBA_VERSION_VENDOR_SUFFIX " + self
.VENDOR_SUFFIX
+ "\n"
131 if self
.VENDOR_PATCH
is not None:
132 string
+="#define SAMBA_VERSION_VENDOR_PATCH " + self
.VENDOR_PATCH
+ "\n"
134 if self
.RELEASE_NICKNAME
is not None:
135 string
+="#define SAMBA_VERSION_RELEASE_NICKNAME " + self
.RELEASE_NICKNAME
+ "\n"
137 # We need to put this #ifdef in to the headers so that vendors can override the version with a function
139 #ifdef SAMBA_VERSION_VENDOR_FUNCTION
140 # define SAMBA_VERSION_STRING SAMBA_VERSION_VENDOR_FUNCTION
141 #else /* SAMBA_VERSION_VENDOR_FUNCTION */
142 # define SAMBA_VERSION_STRING "''' + self
.STRING_WITH_NICKNAME
+ '''"
145 string
+="/* Version for mkrelease.sh: \nSAMBA_VERSION_STRING=" + self
.STRING_WITH_NICKNAME
+ "\n */\n"
150 class samba_version_file(samba_version
):
151 def __init__(self
, version_file
, have_git
=False):
152 '''Parse the version information from a VERSION file'''
153 f
= open(version_file
, 'r')
160 if line
.startswith("#"):
162 split_line
=line
.split("=")
163 if split_line
[1] != "":
164 value
= split_line
[1].strip('"')
165 version_dict
[split_line
[0]] = value
167 print "Failed to parse line %s from %s" % (line
, version_file
)
170 super(samba_version_file
, self
).__init
__(version_dict
, have_git
=have_git
)