diff options
Diffstat (limited to 'BuildTools/SCons')
| -rw-r--r-- | BuildTools/SCons/Tools/textfile.py | 2 | ||||
| -rw-r--r-- | BuildTools/SCons/Version.py | 191 |
2 files changed, 163 insertions, 30 deletions
diff --git a/BuildTools/SCons/Tools/textfile.py b/BuildTools/SCons/Tools/textfile.py index 02fc54a..73105ad 100644 --- a/BuildTools/SCons/Tools/textfile.py +++ b/BuildTools/SCons/Tools/textfile.py | |||
| @@ -63,7 +63,7 @@ def _do_subst(node, subs): | |||
| 63 | then all instances of %VERSION% in the file will be replaced with | 63 | then all instances of %VERSION% in the file will be replaced with |
| 64 | 1.2345 and so forth. | 64 | 1.2345 and so forth. |
| 65 | """ | 65 | """ |
| 66 | contents = node.get_text_contents() | 66 | contents = node.get_contents().decode('utf-8') |
| 67 | if not subs: return contents | 67 | if not subs: return contents |
| 68 | for (k,v) in subs: | 68 | for (k,v) in subs: |
| 69 | contents = re.sub(k, v, contents) | 69 | contents = re.sub(k, v, contents) |
diff --git a/BuildTools/SCons/Version.py b/BuildTools/SCons/Version.py index b69cdca..001374a 100644 --- a/BuildTools/SCons/Version.py +++ b/BuildTools/SCons/Version.py | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | import subprocess, os, datetime, re, os.path | 1 | import subprocess, os, datetime, re, os.path, sys, unittest |
| 2 | 2 | ||
| 3 | def getGitBuildVersion(root, project) : | 3 | def getGitBuildVersion(root, project) : |
| 4 | tag = git("describe --tags --exact --match \"" + project + "-*\"", root) | 4 | tag = git("describe --tags --exact --match \"" + project + "-*\"", root) |
| @@ -6,7 +6,7 @@ def getGitBuildVersion(root, project) : | |||
| 6 | return tag.rstrip()[len(project)+1:] | 6 | return tag.rstrip()[len(project)+1:] |
| 7 | tag = git("describe --tags --match \"" + project + "-*\"", root) | 7 | tag = git("describe --tags --match \"" + project + "-*\"", root) |
| 8 | if tag : | 8 | if tag : |
| 9 | m = re.match(project + "-(.*)-(.*)-(.*)", tag.decode('utf-8')) | 9 | m = re.match(project + "-(.*)-(.*)-(.*)", tag) |
| 10 | if m : | 10 | if m : |
| 11 | return m.group(1) + "-dev" + m.group(2) | 11 | return m.group(1) + "-dev" + m.group(2) |
| 12 | return None | 12 | return None |
| @@ -37,32 +37,165 @@ def getBuildVersion(root, project) : | |||
| 37 | 37 | ||
| 38 | return datetime.date.today().strftime("%Y%m%d") | 38 | return datetime.date.today().strftime("%Y%m%d") |
| 39 | 39 | ||
| 40 | def convertToWindowsVersion(version) : | 40 | # The following conversion allows us to use version tags the format: |
| 41 | version_match = re.match("(\d+)\.(\d+)(.*)", version.decode('utf-8')) | 41 | # major.0 |
| 42 | major = version_match and int(version_match.group(1)) or 0 | 42 | # major.0.(0 to 9) |
| 43 | minor = version_match and int(version_match.group(2)) or 0 | 43 | # |
| 44 | if version_match and len(version_match.group(3)) == 0 : | 44 | # Either from above followed by: |
| 45 | patch = 60000 | 45 | # alpha(0 to 4) |
| 46 | else : | 46 | # beta(0 to 6) |
| 47 | match = re.match("^beta(\d+)(.*)", version_match.group(3)) | 47 | # rc(1 to 11) |
| 48 | build_string = "" | 48 | # |
| 49 | if match : | 49 | # Followed by an optional -dev(1-65535) for off tag builds. |
| 50 | patch = 1000*int(match.group(1)) | 50 | def convertToWindowsVersion(version): |
| 51 | build_string = match.group(2) | 51 | match = re.match(r"(?P<major>\d+)\.(?P<minor>\d+)\.?(?P<patch>\d+)?(?:(?P<stage>rc|beta|alpha)(?P<stage_number>\d+)?)?(?:-dev(?P<dev>\d+))?", version) |
| 52 | else : | 52 | assert(match) |
| 53 | rc_match = re.match("^rc(\d+)(.*)", version_match.group(3)) | 53 | major, minor, patch = (0, 0, 0) |
| 54 | if rc_match : | ||
| 55 | patch = 10000*int(rc_match.group(1)) | ||
| 56 | build_string = rc_match.group(2) | ||
| 57 | else : | ||
| 58 | patch = 0 | ||
| 59 | alpha_match = re.match("^alpha(.*)", version_match.group(3)) | ||
| 60 | if alpha_match : | ||
| 61 | build_string = alpha_match.group(1) | ||
| 62 | |||
| 63 | if len(build_string) > 0 : | ||
| 64 | build_match = re.match("^-dev(\d+)", build_string) | ||
| 65 | if build_match : | ||
| 66 | patch += int(build_match.group(1)) | ||
| 67 | 54 | ||
| 55 | groups = match.groupdict() | ||
| 56 | assert(groups['major']) | ||
| 57 | major = int(groups['major']) | ||
| 58 | |||
| 59 | if groups['minor']: | ||
| 60 | assert(int(groups['minor']) == 0) | ||
| 61 | |||
| 62 | if groups['patch']: | ||
| 63 | assert(0 <= int(groups['patch']) <= 9) | ||
| 64 | minor = int(groups['patch']) * 25 | ||
| 65 | |||
| 66 | stage = groups["stage"] | ||
| 67 | if stage: | ||
| 68 | stageNumber = groups['stage_number'] | ||
| 69 | if not stageNumber or stageNumber == "": | ||
| 70 | stageNumber = 0 | ||
| 71 | else: | ||
| 72 | stageNumber = int(stageNumber) | ||
| 73 | |||
| 74 | if stage == "alpha": | ||
| 75 | assert(0 <= stageNumber <= 4) | ||
| 76 | minor = 1 + stageNumber | ||
| 77 | elif stage == "beta": | ||
| 78 | assert(0 <= stageNumber <= 6) | ||
| 79 | minor = 6 + stageNumber | ||
| 80 | elif stage == "rc": | ||
| 81 | assert(1 <= stageNumber <= 11) | ||
| 82 | minor = 12 + stageNumber | ||
| 83 | else: | ||
| 84 | assert(False) | ||
| 85 | else: | ||
| 86 | minor = minor + 24 | ||
| 87 | |||
| 88 | if groups['dev']: | ||
| 89 | patch = 1 + int(groups['dev']) | ||
| 90 | |||
| 91 | # The following constraints are set by Windows Installer framework | ||
| 92 | assert(0 <= major <= 255) | ||
| 93 | assert(0 <= minor <= 255) | ||
| 94 | assert(0 <= patch <= 65535) | ||
| 68 | return (major, minor, patch) | 95 | return (major, minor, patch) |
| 96 | |||
| 97 | # Test Windows version mapping scheme | ||
| 98 | class convertToWindowsVersionTest(unittest.TestCase): | ||
| 99 | def testWindowsVersionsAreDescending(self): | ||
| 100 | versionStringsWithOldVersions = [ | ||
| 101 | ("5.0rc11", None), | ||
| 102 | ("5.0rc1", None), | ||
| 103 | ("5.0beta6", None), | ||
| 104 | ("5.0alpha4", None), | ||
| 105 | ("5.0alpha2", None), | ||
| 106 | ("5.0alpha", None), | ||
| 107 | ("4.0.9", None), | ||
| 108 | ("4.0.1", None), | ||
| 109 | ("4.0", (4, 0, 60000)), | ||
| 110 | ("4.0rc6", (4, 0, 60000)), | ||
| 111 | ("4.0rc5", (4, 0, 50000)), | ||
| 112 | ("4.0rc4", (4, 0, 40000)), | ||
| 113 | ("4.0rc3", (4, 0, 30000)), | ||
| 114 | ('4.0rc2-dev34', (4, 0, 20034)), | ||
| 115 | ('4.0rc2-dev33', (4, 0, 20033)), | ||
| 116 | ('4.0rc2-dev31', (4, 0, 20031)), | ||
| 117 | ('4.0rc2-dev30', (4, 0, 20030)), | ||
| 118 | ('4.0rc2-dev29', (4, 0, 20029)), | ||
| 119 | ('4.0rc2-dev27', (4, 0, 20027)), | ||
| 120 | ('4.0rc2-dev39', (4, 0, 20039)), | ||
| 121 | ('4.0rc2', (4, 0, 20000)), | ||
| 122 | ('4.0rc1', (4, 0, 10000)), | ||
| 123 | ('4.0beta2-dev203', (4, 0, 2203)), | ||
| 124 | ('4.0beta2-dev195', (4, 0, 2195)), | ||
| 125 | ('4.0beta2-dev177', (4, 0, 2177)), | ||
| 126 | ('4.0beta2-dev171', (4, 0, 2171)), | ||
| 127 | ('4.0beta2-dev154', (4, 0, 2154)), | ||
| 128 | ('4.0beta2-dev150', (4, 0, 2150)), | ||
| 129 | ('4.0beta2-dev142', (4, 0, 2142)), | ||
| 130 | ('4.0beta2-dev140', (4, 0, 2140)), | ||
| 131 | ('4.0beta2-dev133', (4, 0, 2133)), | ||
| 132 | ('4.0beta2-dev118', (4, 0, 2118)), | ||
| 133 | ('4.0beta2-dev112', (4, 0, 2112)), | ||
| 134 | ('4.0beta2-dev93', (4, 0, 2093)), | ||
| 135 | ('4.0beta2-dev80', (4, 0, 2080)), | ||
| 136 | ('4.0beta2-dev72', (4, 0, 2072)), | ||
| 137 | ('4.0beta2-dev57', (4, 0, 2057)), | ||
| 138 | ('4.0beta2-dev44', (4, 0, 2044)), | ||
| 139 | ('4.0beta2-dev38', (4, 0, 2038)), | ||
| 140 | ('4.0beta2-dev29', (4, 0, 2029)), | ||
| 141 | ('4.0beta2-dev15', (4, 0, 2015)), | ||
| 142 | ('4.0beta2', (4, 0, 2000)), | ||
| 143 | ('4.0beta1', (4, 0, 1000)), | ||
| 144 | ('4.0alpha-dev80', (4, 0, 80)), | ||
| 145 | ('4.0alpha-dev50', (4, 0, 50)), | ||
| 146 | ('4.0alpha-dev43', (4, 0, 43)), | ||
| 147 | ('4.0alpha-dev21', (4, 0, 21)), | ||
| 148 | ('3.0', (3, 0, 60000)), | ||
| 149 | ('3.0rc3', (3, 0, 30000)), | ||
| 150 | ('3.0rc2', (3, 0, 20000)), | ||
| 151 | ('3.0rc1', (3, 0, 10000)), | ||
| 152 | ('3.0beta2-dev124', (3, 0, 2124)), | ||
| 153 | ('3.0beta2-dev81', (3, 0, 2081)), | ||
| 154 | ('3.0beta2-dev50', (3, 0, 2050)), | ||
| 155 | ('3.0beta2-dev44', (3, 0, 2044)), | ||
| 156 | ('3.0beta2-dev40', (3, 0, 2040)), | ||
| 157 | ('3.0beta2-dev26', (3, 0, 2026)), | ||
| 158 | ('3.0beta2', (3, 0, 2000)), | ||
| 159 | ('3.0beta1', (3, 0, 1000)), | ||
| 160 | ('3.0alpha-dev529', (3, 0, 529)), | ||
| 161 | ('3.0alpha-dev528', (3, 0, 528)), | ||
| 162 | ('3.0alpha-dev526', (3, 0, 526)), | ||
| 163 | ('3.0alpha-dev524', (3, 0, 524)), | ||
| 164 | ('3.0alpha-dev515', (3, 0, 515)), | ||
| 165 | ] | ||
| 166 | windowsVersionMapping = list(map(lambda (x,y): (x, convertToWindowsVersion(x)), versionStringsWithOldVersions)) | ||
| 167 | |||
| 168 | def testThatBetaIsHigherThanAlpha(self): | ||
| 169 | self.assertTrue(convertToWindowsVersion("3.0beta0") > convertToWindowsVersion("3.0alpha0")) | ||
| 170 | self.assertTrue(convertToWindowsVersion("3.0beta6") > convertToWindowsVersion("3.0alpha1")) | ||
| 171 | self.assertTrue(convertToWindowsVersion("3.0beta6") > convertToWindowsVersion("3.0alpha4")) | ||
| 172 | |||
| 173 | def testThatRcIsHigherThanAlphaAndBeta(self): | ||
| 174 | self.assertTrue(convertToWindowsVersion("3.0rc11") > convertToWindowsVersion("3.0alpha0")) | ||
| 175 | self.assertTrue(convertToWindowsVersion("3.0rc11") > convertToWindowsVersion("3.0alpha4")) | ||
| 176 | self.assertTrue(convertToWindowsVersion("3.0rc1") > convertToWindowsVersion("3.0alpha0")) | ||
| 177 | self.assertTrue(convertToWindowsVersion("3.0rc1") > convertToWindowsVersion("3.0alpha4")) | ||
| 178 | self.assertTrue(convertToWindowsVersion("3.0rc11") > convertToWindowsVersion("3.0beta0")) | ||
| 179 | self.assertTrue(convertToWindowsVersion("3.0rc11") > convertToWindowsVersion("3.0beta6")) | ||
| 180 | self.assertTrue(convertToWindowsVersion("3.0rc1") > convertToWindowsVersion("3.0beta0")) | ||
| 181 | self.assertTrue(convertToWindowsVersion("3.0rc1") > convertToWindowsVersion("3.0beta6")) | ||
| 182 | |||
| 183 | def testThatStableIsHigherThanAlphaAndBetaAndRc(self): | ||
| 184 | self.assertTrue(convertToWindowsVersion("3.0") > convertToWindowsVersion("3.0alpha0")) | ||
| 185 | self.assertTrue(convertToWindowsVersion("3.0") > convertToWindowsVersion("3.0alpha4")) | ||
| 186 | self.assertTrue(convertToWindowsVersion("3.0") > convertToWindowsVersion("3.0alpha0")) | ||
| 187 | self.assertTrue(convertToWindowsVersion("3.0") > convertToWindowsVersion("3.0alpha4")) | ||
| 188 | self.assertTrue(convertToWindowsVersion("3.0") > convertToWindowsVersion("3.0beta0")) | ||
| 189 | self.assertTrue(convertToWindowsVersion("3.0") > convertToWindowsVersion("3.0beta6")) | ||
| 190 | self.assertTrue(convertToWindowsVersion("3.0") > convertToWindowsVersion("3.0rc1")) | ||
| 191 | self.assertTrue(convertToWindowsVersion("3.0") > convertToWindowsVersion("3.0rc11")) | ||
| 192 | |||
| 193 | if __name__ == '__main__': | ||
| 194 | if len(sys.argv) == 1: | ||
| 195 | unittest.main() | ||
| 196 | elif len(sys.argv) == 2: | ||
| 197 | print convertToWindowsVersion(sys.argv[1]) | ||
| 198 | sys.exit(0) | ||
| 199 | else: | ||
| 200 | print "Error: Simply run the script without arguments or pass a single argument." | ||
| 201 | sys.exit(-1) | ||
Swift