|
27 | 27 | import contextlib
|
28 | 28 | import datetime
|
29 | 29 | import glob
|
| 30 | +import itertools |
30 | 31 | import json
|
31 | 32 | import os
|
32 | 33 | import platform
|
@@ -232,6 +233,66 @@ def retag_unittests(args):
|
232 | 233 | mx.run(['scp', filename, parsed_args.upload_results_to.rstrip('/') + '/'])
|
233 | 234 |
|
234 | 235 |
|
| 236 | +def _read_tags(path='.'): |
| 237 | + tags = set() |
| 238 | + tagfiles = glob.glob(os.path.join(path, 'graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/*.txt')) |
| 239 | + for tagfile in tagfiles: |
| 240 | + with open(tagfile) as f: |
| 241 | + tags |= {(os.path.basename(tagfile), line.strip()) for line in f if line.strip()} |
| 242 | + return tags |
| 243 | + |
| 244 | + |
| 245 | +def _write_tags(tags, path='.'): |
| 246 | + tagdir = os.path.join(path, 'graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/') |
| 247 | + tagfiles = glob.glob(os.path.join(path, 'graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/*.txt')) |
| 248 | + for file in tagfiles: |
| 249 | + os.unlink(file) |
| 250 | + for file, tags in itertools.groupby(sorted(tags), key=lambda x: x[0]): |
| 251 | + with open(os.path.join(tagdir, file), 'w') as f: |
| 252 | + for tag in tags: |
| 253 | + f.write(tag[1] + '\n') |
| 254 | + |
| 255 | + |
| 256 | +def _fetch_tags_for_platform(parsed_args, platform): |
| 257 | + oldpwd = os.getcwd() |
| 258 | + with tempfile.TemporaryDirectory(prefix='graalpython-update-tags-') as d: |
| 259 | + os.chdir(d) |
| 260 | + try: |
| 261 | + tarfile = 'unittest-tags-{}.tar.bz2'.format(platform) |
| 262 | + mx.run(['curl', '-O', '{}/{}'.format(parsed_args.tags_directory_url.rstrip('/'), tarfile)]) |
| 263 | + os.mkdir(platform) |
| 264 | + mx.run(['tar', 'xf', tarfile, '-C', platform]) |
| 265 | + return _read_tags(platform) |
| 266 | + finally: |
| 267 | + os.chdir(oldpwd) |
| 268 | + |
| 269 | + |
| 270 | +def update_unittest_tags(args): |
| 271 | + parser = ArgumentParser('mx python-update-unittest-tags') |
| 272 | + parser.add_argument('tags_directory_url') |
| 273 | + parsed_args = parser.parse_args(args) |
| 274 | + |
| 275 | + current_tags = _read_tags() |
| 276 | + linux_tags = _fetch_tags_for_platform(parsed_args, 'linux') |
| 277 | + darwin_tags = _fetch_tags_for_platform(parsed_args, 'darwin') |
| 278 | + |
| 279 | + # msimacek TODO: this is overly conservative as it wouldn't include tests that are skipped on the other platform |
| 280 | + result_tags = linux_tags & darwin_tags |
| 281 | + _write_tags(result_tags) |
| 282 | + |
| 283 | + diff = linux_tags - darwin_tags |
| 284 | + if diff: |
| 285 | + mx.warn("The following tests work only on Linux:\n" + '\n'.join(x[1] for x in diff)) |
| 286 | + |
| 287 | + diff = darwin_tags - linux_tags |
| 288 | + if diff: |
| 289 | + mx.warn("The following tests work only on Darwin:\n" + '\n'.join(x[1] for x in diff)) |
| 290 | + |
| 291 | + diff = current_tags - result_tags |
| 292 | + if diff: |
| 293 | + mx.warn("Potential regressions:\n" + '\n'.join(x[1] for x in diff)) |
| 294 | + |
| 295 | + |
235 | 296 | AOT_INCOMPATIBLE_TESTS = ["test_interop.py"]
|
236 | 297 |
|
237 | 298 | class GraalPythonTags(object):
|
@@ -1623,6 +1684,7 @@ def checkout_find_version_for_graalvm(args):
|
1623 | 1684 | 'python-gvm': [python_gvm, ''],
|
1624 | 1685 | 'python-unittests': [python3_unittests, ''],
|
1625 | 1686 | 'python-retag-unittests': [retag_unittests, ''],
|
| 1687 | + 'python-update-unittest-tags': [update_unittest_tags, ''], |
1626 | 1688 | 'python-import-for-graal': [checkout_find_version_for_graalvm, ''],
|
1627 | 1689 | 'nativebuild': [nativebuild, ''],
|
1628 | 1690 | 'nativeclean': [nativeclean, ''],
|
|
0 commit comments