|
4 | 4 | # http://www.boost.org/LICENSE_1_0.txt)
|
5 | 5 | #
|
6 | 6 | # This script downloads either a tarball or zipfile of the latest version of the
|
7 |
| -# main repo. |
| 7 | +# main repo, unpacks it, runs bjam (including all unit tests) and creates a file |
| 8 | +# that contains all the information needed to evaluate any regression failures. |
| 9 | +# |
| 10 | +# 1. Create a directory where you want to run the test |
| 11 | +# 2. Download this script |
| 12 | +# 3. Run this script: python regression.py [options] |
| 13 | +# 4. E-mail the `cpp_netlib_regression.txt` file to the developers |
8 | 14 | #
|
9 | 15 |
|
10 | 16 |
|
|
17 | 23 | import subprocess
|
18 | 24 |
|
19 | 25 |
|
20 |
| -# |
21 |
| -# Some constants |
22 |
| -# |
23 |
| -repo_root = "http://github.com/mikhailberis/cpp-netlib/" |
24 |
| -branch = "0.6-devel" |
25 |
| -boost_minimum_version = "1_40" |
26 | 26 |
|
| 27 | +class RegressionTester: |
| 28 | + """ """ |
| 29 | + |
| 30 | + def __init__(self): |
| 31 | + """ """ |
27 | 32 |
|
28 |
| -def check_boost_installation(): |
29 |
| - """ Gets information about the user's boost environment. """ |
| 33 | + self._repo_root = "http://github.com/mikhailberis/cpp-netlib/" |
| 34 | + self._boost_minimum_version = "1_40" |
30 | 35 |
|
31 |
| - env = os.getenv("BOOST_ROOT") |
32 |
| - assert(env is not None) |
| 36 | + def check_boost_installation(self): |
| 37 | + """ Gets information about the user's boost environment. """ |
33 | 38 |
|
34 |
| - # get boost version from version.hpp |
35 |
| - version = None |
36 |
| - version_hpp = os.path.join(env, "boost", "version.hpp") |
37 |
| - f = open(version_hpp, "r") |
38 |
| - for line in f: |
39 |
| - if line.startswith("#define BOOST_LIB_VERSION"): |
40 |
| - begin = string.find(line, '"') |
41 |
| - end = string.rfind(line, '"') |
42 |
| - version = line[begin + 1:end] |
43 |
| - break |
| 39 | + env = os.getenv("BOOST_ROOT") |
| 40 | + assert(env is not None) |
44 | 41 |
|
45 |
| - class Params: pass |
46 |
| - params = Params() |
47 |
| - params.root = env |
48 |
| - params.version = version |
49 |
| - return params |
| 42 | + # get boost version from version.hpp |
| 43 | + version = None |
| 44 | + version_hpp = os.path.join(env, "boost", "version.hpp") |
| 45 | + f = open(version_hpp, "r") |
| 46 | + for line in f: |
| 47 | + if line.startswith("#define BOOST_LIB_VERSION"): |
| 48 | + begin = string.find(line, '"') |
| 49 | + end = string.rfind(line, '"') |
| 50 | + version = line[begin + 1:end] |
| 51 | + break |
50 | 52 |
|
| 53 | + class Params: pass |
| 54 | + params = Params() |
| 55 | + params.root = env |
| 56 | + params.version = version |
| 57 | + return params |
51 | 58 |
|
52 |
| -def build(bjam, user_config=None): |
53 |
| - """ """ |
| 59 | + def download(self, branch): |
| 60 | + """ """ |
54 | 61 |
|
55 |
| - if bjam is None: |
56 |
| - bjam = "bjam" |
| 62 | + raise NotImplementedError |
57 | 63 |
|
58 |
| - results = open("results.txt", "w+") |
59 |
| - rc = subprocess.call(bjam, stdout=results, stderr=results) |
| 64 | + def get_commit(self, filename): |
| 65 | + """ """ |
| 66 | + |
| 67 | + (root, ext) = os.path.splitext(filename) |
| 68 | + (root, ext) = os.path.splitext(root) |
| 69 | + return root.split("-")[-1] |
60 | 70 |
|
| 71 | + def unpack(self, filename): |
| 72 | + """ """ |
| 73 | + |
| 74 | + raise NotImplementedError |
61 | 75 |
|
62 |
| -def download_tarball(stage): |
63 |
| - """ Downloads the latest tarball from the mikhailberis fork. """ |
| 76 | + def build(self, results, bjam): |
| 77 | + """ """ |
| 78 | + |
| 79 | + rc = subprocess.call(bjam, stdout=results, stderr=results) |
| 80 | + |
| 81 | + def run(self, runner, branch, bjam=None, user_config=None): |
| 82 | + """ """ |
| 83 | + |
| 84 | + boost_params = self.check_boost_installation() |
| 85 | + assert(boost_params.version is not None) |
| 86 | + assert(boost_params.version > self._boost_minimum_version) |
| 87 | + |
| 88 | + results = "cpp_netlib_regression.txt" |
| 89 | + results_file = open(results, "w+") |
| 90 | + |
| 91 | + filename = self.download(branch) |
| 92 | + commit = self.get_commit(filename) |
| 93 | + |
| 94 | + self.unpack(filename) |
| 95 | + |
| 96 | + if bjam is None: |
| 97 | + bjam = "bjam" |
64 | 98 |
|
65 |
| - r = urllib2.urlopen(repo_root + "tarball/" + branch) |
66 |
| - filename = urlparse.urlparse(r.geturl()).path.split("/")[-1] |
67 |
| - path = os.path.join(stage, filename) |
68 |
| - f = open(path, "w+") |
69 |
| - f.write(r.read()) |
70 |
| - return filename |
71 |
| - |
72 |
| -def unpack_tarball(stage, filename): |
73 |
| - """ Unpacks the tarball into a stage directory. """ |
74 |
| - |
75 |
| - import tarfile |
76 |
| - import shutil |
77 |
| - |
78 |
| - (root, ext) = os.path.splitext(filename) |
79 |
| - (root, ext) = os.path.splitext(root) |
80 |
| - if os.path.exists(os.path.join(stage, root)): |
81 |
| - shutil.rmtree(os.path.join(stage, root)) |
82 |
| - |
83 |
| - os.chdir(stage) |
84 |
| - f = tarfile.open(os.path.join(stage, filename)) |
85 |
| - f.extractall() |
86 |
| - os.chdir(root) |
| 99 | + if user_config is not None: |
| 100 | + bjam = "%s --user-config=%s" % (bjam,u ser_config) |
| 101 | + |
| 102 | + self.build(results_file, bjam) |
| 103 | + |
| 104 | + results_file.write("\n\n") |
| 105 | + results_file.write("runner: %s\n" % runner) |
| 106 | + results_file.write("git_branch: %s\n" % branch) |
| 107 | + results_file.write("boost_root: %s\n" % boost_params.root) |
| 108 | + results_file.write("boost_version: %s\n" % boost_params.version) |
| 109 | + results_file.write("commit: %s\n" % commit) |
| 110 | + |
| 111 | + return results |
| 112 | + |
| 113 | + |
| 114 | +class RegressionTesterWithTar(RegressionTester): |
| 115 | + """ """ |
| 116 | + |
| 117 | + def __init__(self): |
| 118 | + RegressionTester.__init__(self) |
| 119 | + |
| 120 | + def download(self, branch): |
| 121 | + """ Downloads the latest tarball from the mikhailberis fork. """ |
87 | 122 |
|
| 123 | + r = urllib2.urlopen(self._repo_root + "tarball/" + branch) |
| 124 | + filename = urlparse.urlparse(r.geturl()).path.split("/")[-1] |
| 125 | + f = open(filename, "w+") |
| 126 | + f.write(r.read()) |
| 127 | + return filename |
| 128 | + |
| 129 | + def unpack(self, filename): |
| 130 | + """ Unpacks the tarball into a stage directory. """ |
| 131 | + |
| 132 | + import tarfile |
| 133 | + import shutil |
| 134 | + |
| 135 | + (root, ext) = os.path.splitext(filename) |
| 136 | + (root, ext) = os.path.splitext(root) |
| 137 | + if os.path.exists(root): |
| 138 | + shutil.rmtree(root) |
| 139 | + |
| 140 | + f = tarfile.open(filename) |
| 141 | + f.extractall() |
| 142 | + os.chdir(root) |
| 143 | + |
88 | 144 |
|
89 |
| -def download_zipball(stage): |
90 |
| - """ Downloads the latest zipfile from the mikhailberis fork. """ |
| 145 | +class RegressionTesterWithZip(RegressionTester): |
| 146 | + """ """ |
| 147 | + |
| 148 | + def __init__(self): |
| 149 | + RegressionTester.__init__(self) |
| 150 | + |
| 151 | + def download(self, branch): |
| 152 | + """ Downloads the latest zipfile from the mikhailberis fork. """ |
91 | 153 |
|
92 |
| - r = urllib2.urlopen(repo_root + "zipball/" + branch) |
93 |
| - filename = urlparse.urlparse(r.geturl()).path.split("/")[-1] |
94 |
| - path = os.path.join(stage, filename) |
95 |
| - f = open(path, "w+") |
96 |
| - f.write(r.read()) |
97 |
| - return filename |
| 154 | + r = urllib2.urlopen(self._repo_root + "zipball/" + branch) |
| 155 | + filename = urlparse.urlparse(r.geturl()).path.split("/")[-1] |
| 156 | + f = open(filename, "w+") |
| 157 | + f.write(r.read()) |
| 158 | + return filename |
98 | 159 |
|
99 |
| -def unpack_zipball(stage, filename): |
100 |
| - """ Unpacks the zip file into a stage directory. """ |
| 160 | + def unpack(self, filename): |
| 161 | + """ Unpacks the zip file into a stage directory. """ |
101 | 162 |
|
102 |
| - import zipfile |
103 |
| - import shutil |
| 163 | + import zipfile |
| 164 | + import shutil |
104 | 165 |
|
105 |
| - (root, ext) = os.path.splitext(filename) |
106 |
| - (root, ext) = os.path.splitext(root) |
107 |
| - if os.path.exists(os.path.join(stage, root)): |
108 |
| - shutil.rmtree(os.path.join(stage, root)) |
| 166 | + (root, ext) = os.path.splitext(filename) |
| 167 | + (root, ext) = os.path.splitext(root) |
| 168 | + if os.path.exists(root): |
| 169 | + shutil.rmtree(root) |
109 | 170 |
|
110 |
| - os.chdir(stage) |
111 |
| - f = zipfile.ZipFile(os.path.join(stage, filename)) |
112 |
| - f.extractall() |
113 |
| - os.chdir(root) |
| 171 | + f = zipfile.ZipFile(filename) |
| 172 | + f.extractall() |
| 173 | + os.chdir(root) |
114 | 174 |
|
115 | 175 |
|
116 | 176 | if __name__ == "__main__":
|
117 | 177 |
|
118 | 178 | opt = optparse.OptionParser(
|
119 | 179 | usage="%prog [options]")
|
120 |
| - |
121 |
| - opt.add_option("--zip", |
122 |
| - action="store_false", |
123 |
| - help="Downloads the zip file.") |
124 |
| - opt.add_option("--tar", |
125 |
| - action="store_false", |
126 |
| - help="Downloads the tar.gz file.") |
127 |
| - opt.add_option("--stage", |
128 |
| - metavar="DIR", |
129 |
| - help="the stage directory.") |
| 180 | + |
| 181 | + opt.add_option("--runner", |
| 182 | + metavar="RUNNER", |
| 183 | + help="A real name to identify the test runner.") |
| 184 | + opt.add_option("--package", |
| 185 | + metavar="ZIP/TAR", |
| 186 | + help="Specify 'zip' to download the zip file, or 'tar' to " |
| 187 | + "download the tarball.") |
130 | 188 | opt.add_option("--branch",
|
131 | 189 | help="the Git branch to check.")
|
132 | 190 | opt.add_option("--bjam",
|
133 |
| - help="The path to the bjam binary if it's not in the system path.") |
| 191 | + help="The path to the bjam binary if it's not in the system " |
| 192 | + "path.") |
134 | 193 | opt.add_option("--user-config",
|
135 | 194 | metavar="FILE",
|
136 | 195 | help="the user-config file to use.")
|
137 | 196 |
|
138 | 197 | (opts, args) = opt.parse_args()
|
139 | 198 |
|
140 |
| - if (opts.zip is None and opts.tar is None) or \ |
141 |
| - (opts.zip is not None and opts.tar is not None): |
142 |
| - print("Please specify either zip or tar") |
| 199 | + if opt.runner is None: |
| 200 | + opt.print_help() |
143 | 201 | sys.exit(-1)
|
144 | 202 |
|
145 |
| - if opts.stage is None: |
146 |
| - opts.stage = "/tmp" |
147 |
| - print("stage: %s" % opts.stage) |
| 203 | + if opts.branch is None: |
| 204 | + opt.print_help() |
| 205 | + sys.exit(-1) |
148 | 206 |
|
149 |
| - boost_params = check_boost_installation() |
150 |
| - assert(boost_params.version is not None) |
151 |
| - assert(boost_params.version > boost_minimum_version) |
152 |
| - print("boost_root: %s" % boost_params.root) |
153 |
| - print("boost_version: %s" % boost_params.version) |
| 207 | + if opts.package not in ["zip", "tar"]: |
| 208 | + opt.print_help() |
| 209 | + sys.exit(-1) |
| 210 | + |
| 211 | + if opts.package == "zip": |
| 212 | + tester = RegressionTesterWithZip() |
| 213 | + elif opts.package == "tar": |
| 214 | + tester = RegressionTesterWithTar() |
154 | 215 |
|
155 | 216 | try:
|
156 |
| - if opts.zip is not None: |
157 |
| - filename = download_zipball(opts.stage) |
158 |
| - unpack_zipball(opts.stage, filename) |
159 |
| - elif opts.tar is not None: |
160 |
| - filename = download_tarball(opts.stage) |
161 |
| - unpack_tarball(opts.stage, filename) |
162 |
| - |
163 |
| - build(opts.bjam, opts.user_config) |
164 |
| - |
| 217 | + results = tester.run(opts.runner, |
| 218 | + opts.branch, |
| 219 | + bjam=opts.bjam, |
| 220 | + user_config=opts.user_config) |
| 221 | + print("The regression results are found in `%s`." % results) |
| 222 | + print( "Please e-mail this to the project administrators at `[email protected]`") |
165 | 223 | except Exception, e:
|
166 | 224 | print(e)
|
0 commit comments