Commit 6503b9ff76a90cebb6c1c86996793a1dd4c449fe
1 parent
a14056db
Correctly set libtool version
Showing
1 changed file
with
112 additions
and
22 deletions
dev/set_version.py
| @@ -57,6 +57,42 @@ def get_current(): | @@ -57,6 +57,42 @@ def get_current(): | ||
| 57 | return version | 57 | return version |
| 58 | 58 | ||
| 59 | 59 | ||
| 60 | +# ========================== # | ||
| 61 | +# Get libtool version number # | ||
| 62 | +# ========================== # | ||
| 63 | +def get_libtool(): | ||
| 64 | + """ | ||
| 65 | + Get libtools version number | ||
| 66 | + | ||
| 67 | + Returns | ||
| 68 | + ------- | ||
| 69 | + version : str | ||
| 70 | + Version number | ||
| 71 | + """ | ||
| 72 | + # Initialse version number of empty string | ||
| 73 | + version = '' | ||
| 74 | + | ||
| 75 | + # Open configure.ac file | ||
| 76 | + f = open('configure.ac', 'r') | ||
| 77 | + | ||
| 78 | + # Read all lines | ||
| 79 | + for line in f: | ||
| 80 | + | ||
| 81 | + # Search for pattern | ||
| 82 | + if line.startswith('CTOOLS_LT_VERSION='): | ||
| 83 | + | ||
| 84 | + # Extract version number | ||
| 85 | + start = line.find('"')+1 | ||
| 86 | + stop = line.find('"', start) | ||
| 87 | + version = line[start:stop].strip() | ||
| 88 | + | ||
| 89 | + # Close file | ||
| 90 | + f.close() | ||
| 91 | + | ||
| 92 | + # Return version | ||
| 93 | + return version | ||
| 94 | + | ||
| 95 | + | ||
| 60 | # ============================== # | 96 | # ============================== # |
| 61 | # Set version number in one file # | 97 | # Set version number in one file # |
| 62 | # ============================== # | 98 | # ============================== # |
| @@ -84,7 +120,6 @@ def set_version(filename, version, current): | @@ -84,7 +120,6 @@ def set_version(filename, version, current): | ||
| 84 | 120 | ||
| 85 | # Replace version number | 121 | # Replace version number |
| 86 | new_content = content.replace(current, version) | 122 | new_content = content.replace(current, version) |
| 87 | - #print(new_content) | ||
| 88 | 123 | ||
| 89 | # Open file in write mode | 124 | # Open file in write mode |
| 90 | f = open(filename, 'w') | 125 | f = open(filename, 'w') |
| @@ -130,29 +165,58 @@ def set_versions(version, current): | @@ -130,29 +165,58 @@ def set_versions(version, current): | ||
| 130 | 165 | ||
| 131 | 166 | ||
| 132 | # =============================================== # | 167 | # =============================================== # |
| 133 | -# Set special version number in configure.ac file # | 168 | +# Set libtool version number in configure.ac file # |
| 134 | # =============================================== # | 169 | # =============================================== # |
| 135 | -def set_special_configure(version, current): | 170 | +def set_libtool_version(library=False, added=False, removed=False, changed=False): |
| 136 | """ | 171 | """ |
| 137 | Set special version numbers in configure.ac file | 172 | Set special version numbers in configure.ac file |
| 138 | 173 | ||
| 139 | Parameters | 174 | Parameters |
| 140 | ---------- | 175 | ---------- |
| 141 | - version : str | ||
| 142 | - Version number | ||
| 143 | - current : str | ||
| 144 | - Current version number | 176 | + library : bool, optional |
| 177 | + Library source code changed | ||
| 178 | + added : bool, optional | ||
| 179 | + Interfaces added | ||
| 180 | + removed : bool, optional | ||
| 181 | + Interfaces removed | ||
| 182 | + changed : bool, optional | ||
| 183 | + Interfaces changed | ||
| 145 | """ | 184 | """ |
| 146 | - # Generate current version number | ||
| 147 | - split = current.split('.') | ||
| 148 | - cur = '%s:%s:%s' % (split[0], split[1], split[2]) | ||
| 149 | - | ||
| 150 | - # Generate new version number | ||
| 151 | - split = version.split('.') | ||
| 152 | - ver = '%s:%s:%s' % (split[0], split[1], split[2]) | ||
| 153 | - | ||
| 154 | - # Set version number | ||
| 155 | - set_version('configure.ac', ver, cur) | 185 | + # Get libtool version number |
| 186 | + old = get_libtool() | ||
| 187 | + split = old.split(':') | ||
| 188 | + | ||
| 189 | + # Decompose libtool version number | ||
| 190 | + current = int(split[0]) | ||
| 191 | + revision = int(split[1]) | ||
| 192 | + age = int(split[2]) | ||
| 193 | + | ||
| 194 | + # If the library source code has changed at all since the last update, then | ||
| 195 | + # increment revision | ||
| 196 | + if library: | ||
| 197 | + revision += 1 | ||
| 198 | + | ||
| 199 | + # If any interfaces have been added, removed, or changed since the last | ||
| 200 | + # update, increment current, and set revision to 0 | ||
| 201 | + if added or removed or changed: | ||
| 202 | + current += 1 | ||
| 203 | + revision = 0 | ||
| 204 | + | ||
| 205 | + # If any interfaces have been added since the last public release, then | ||
| 206 | + # increment age | ||
| 207 | + if added: | ||
| 208 | + age += 1 | ||
| 209 | + | ||
| 210 | + # If any interfaces have been removed or changed since the last public | ||
| 211 | + # release, then set age to 0 | ||
| 212 | + if removed or changed: | ||
| 213 | + age = 0 | ||
| 214 | + | ||
| 215 | + # Build new libtool version number | ||
| 216 | + version = '%d:%d:%d' % (current, revision, age) | ||
| 217 | + | ||
| 218 | + # Set libtool version number | ||
| 219 | + set_version('configure.ac', version, old) | ||
| 156 | 220 | ||
| 157 | # Return | 221 | # Return |
| 158 | return | 222 | return |
| @@ -193,19 +257,45 @@ def set_special_conf(version, current): | @@ -193,19 +257,45 @@ def set_special_conf(version, current): | ||
| 193 | if __name__ == '__main__': | 257 | if __name__ == '__main__': |
| 194 | 258 | ||
| 195 | # Check for version number | 259 | # Check for version number |
| 196 | - if len(sys.argv) < 2: | ||
| 197 | - sys.exit('Usage: set_version.py version') | 260 | + if len(sys.argv) < 3: |
| 261 | + print('Usage: set_version.py version [larc]') | ||
| 262 | + print(' l : source code changed') | ||
| 263 | + print(' a : interface(s) added') | ||
| 264 | + print(' r : interface(s) removed') | ||
| 265 | + print(' c : interface(s) changed') | ||
| 266 | + sys.exit() | ||
| 198 | 267 | ||
| 199 | # Extract version number | 268 | # Extract version number |
| 200 | version = sys.argv[1] | 269 | version = sys.argv[1] |
| 201 | 270 | ||
| 271 | + # Extract code change flags | ||
| 272 | + if len(sys.argv) == 3: | ||
| 273 | + flags = sys.argv[2] | ||
| 274 | + | ||
| 275 | + # Set change flags | ||
| 276 | + library = False | ||
| 277 | + added = False | ||
| 278 | + removed = False | ||
| 279 | + changed = False | ||
| 280 | + if flags.find('l') != -1: | ||
| 281 | + library = True | ||
| 282 | + if flags.find('a') != -1: | ||
| 283 | + added = True | ||
| 284 | + if flags.find('r') != -1: | ||
| 285 | + removed = True | ||
| 286 | + if flags.find('c') != -1: | ||
| 287 | + changed = True | ||
| 288 | + | ||
| 202 | # Get the current version | 289 | # Get the current version |
| 203 | current = get_current() | 290 | current = get_current() |
| 204 | 291 | ||
| 205 | # Set versions | 292 | # Set versions |
| 206 | set_versions(version, current) | 293 | set_versions(version, current) |
| 207 | 294 | ||
| 208 | - # Set special version number: | ||
| 209 | - set_special_configure(version, current) # CTOOLS_LT_VERSION="x:y:z" | ||
| 210 | - set_special_conf(version, current) # version = 'x.y' | 295 | + # Set libtool version |
| 296 | + set_libtool_version(library=library, added=added, removed=removed, | ||
| 297 | + changed=changed) | ||
| 298 | + | ||
| 299 | + # Set special version number in doc/source/conf.py file | ||
| 300 | + set_special_conf(version, current) | ||
| 211 | 301 |