Skip to content

Commit 6638127

Browse files
Complete ABC refactor
1 parent 7b51499 commit 6638127

1 file changed

Lines changed: 77 additions & 69 deletions

File tree

Tools/ssl/multissltests.py

Lines changed: 77 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -44,29 +44,6 @@
4444

4545
log = logging.getLogger("multissl")
4646

47-
OPENSSL_OLD_VERSIONS = [
48-
"1.1.1w",
49-
]
50-
51-
OPENSSL_RECENT_VERSIONS = [
52-
"3.0.16",
53-
"3.1.8",
54-
"3.2.4",
55-
"3.3.3",
56-
"3.4.1",
57-
# See make_ssl_data.py for notes on adding a new version.
58-
]
59-
60-
LIBRESSL_OLD_VERSIONS = [
61-
]
62-
63-
LIBRESSL_RECENT_VERSIONS = [
64-
]
65-
66-
AWSLC_RECENT_VERSIONS = [
67-
"1.55.0",
68-
]
69-
7047
# store files in ../multissl
7148
HERE = os.path.dirname(os.path.abspath(__file__))
7249
PYTHONROOT = os.path.abspath(os.path.join(HERE, '..', '..'))
@@ -155,32 +132,40 @@ class AbstractBuilder(object, metaclass=ABCMeta):
155132
jobs = os.process_cpu_count()
156133
else:
157134
jobs = os.cpu_count()
135+
module_files = (
136+
os.path.join(PYTHONROOT, "Modules/_ssl.c"),
137+
os.path.join(PYTHONROOT, "Modules/_hashopenssl.c"),
138+
)
139+
module_libs = ("_ssl", "_hashlib")
158140

159141
@property
160142
@abstractmethod
161-
def library(self):
143+
def library(self=None):
162144
pass
163145

164146
@property
165147
@abstractmethod
166-
def url_templates(self):
148+
def url_templates(self=None):
167149
pass
168150

169151
@property
170152
@abstractmethod
171-
def src_template(self):
153+
def src_template(self=None):
172154
pass
173155

174156
@property
175157
@abstractmethod
176-
def build_template(self):
158+
def build_template(self=None):
177159
pass
178160

179-
module_files = (
180-
os.path.join(PYTHONROOT, "Modules/_ssl.c"),
181-
os.path.join(PYTHONROOT, "Modules/_hashopenssl.c"),
182-
)
183-
module_libs = ("_ssl", "_hashlib")
161+
@property
162+
@abstractmethod
163+
def recent_versions():
164+
pass
165+
166+
@property
167+
def old_versions():
168+
return []
184169

185170
def __init__(self, version, args):
186171
self.version = version
@@ -420,25 +405,40 @@ class BuildOpenSSL(AbstractBuilder):
420405
depend_target = 'depend'
421406

422407
@property
423-
def library(self):
408+
def library(self=None):
424409
return "OpenSSL"
425410

426411
@property
427-
def url_templates(self):
412+
def url_templates(self=None):
428413
return (
429414
"https://github.com/openssl/openssl/releases/download/openssl-{v}/openssl-{v}.tar.gz",
430415
"https://www.openssl.org/source/openssl-{v}.tar.gz",
431416
"https://www.openssl.org/source/old/{s}/openssl-{v}.tar.gz",
432417
)
433418

434419
@property
435-
def src_template(self):
420+
def src_template(self=None):
436421
return "openssl-{}.tar.gz"
437422

438423
@property
439-
def build_template(self):
424+
def build_template(self=None):
440425
return "openssl-{}"
441426

427+
@property
428+
def recent_versions():
429+
return [
430+
"3.0.16",
431+
"3.1.8",
432+
"3.2.4",
433+
"3.3.3",
434+
"3.4.1",
435+
# See make_ssl_data.py for notes on adding a new version.
436+
]
437+
438+
@property
439+
def old_versions():
440+
return [ "1.1.1w" ]
441+
442442
def _post_install(self):
443443
if self.version.startswith("3."):
444444
self._post_install_3xx()
@@ -475,43 +475,53 @@ def short_version(self):
475475

476476
class BuildLibreSSL(AbstractBuilder):
477477
@property
478-
def library(self):
478+
def library(self=None):
479479
return "LibreSSL"
480480

481481
@property
482-
def url_templates(self):
482+
def url_templates(self=None):
483483
return (
484484
"https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-{v}.tar.gz",
485485
)
486486

487487
@property
488-
def src_template(self):
488+
def src_template(self=None):
489489
return "libressl-{}.tar.gz"
490490

491491
@property
492-
def build_template(self):
492+
def build_template(self=None):
493493
"libressl-{}"
494494

495+
@property
496+
def recent_versions():
497+
return []
498+
495499

496500
class BuildAWSLC(AbstractBuilder):
497501
@property
498-
def library(self):
502+
def library(self=None):
499503
return "AWS-LC"
500504

501505
@property
502-
def url_templates(self):
506+
def url_templates(self=None):
503507
return (
504508
"https://github.com/aws/aws-lc/archive/refs/tags/v{v}.tar.gz",
505509
)
506510

507511
@property
508-
def src_template(self):
512+
def src_template(self=None):
509513
return "aws-lc-{}.tar.gz"
510514

511515
@property
512-
def build_template(self):
516+
def build_template(self=None):
513517
return "aws-lc-{}"
514518

519+
@property
520+
def recent_versions():
521+
return [
522+
"1.55.0",
523+
]
524+
515525
def _build_src(self, config_args=()):
516526
cwd = self.build_dir
517527
log.info("Running build in {}".format(cwd))
@@ -566,33 +576,31 @@ def main():
566576
format="*** %(levelname)s %(message)s"
567577
)
568578

569-
ssl_libs = {
570-
"openssl": [
571-
BuildOpenSSL, OPENSSL_OLD_VERSIONS, OPENSSL_RECENT_VERSIONS, []
572-
],
573-
"libressl": [
574-
BuildLibreSSL, LIBRESSL_OLD_VERSIONS, LIBRESSL_RECENT_VERSIONS, []
575-
],
576-
"awslc": [BuildAWSLC, [], AWSLC_RECENT_VERSIONS, []],
577-
}
578-
if args.ssl and args.ssl_versions:
579-
ssl_libs[args.ssl][3] += args.ssl_versions
580-
elif args.ssl:
581-
ssl_libs[args.ssl][3] += ssl_libs[args.ssl][2]
579+
versions = []
580+
ssl_libs = AbstractBuilder.__subclasses__()
581+
if args.ssl:
582+
lib_name = lambda x: x.library.fget().lower().replace("-", "")
583+
libs = [l for l in ssl_libs if lib_name(l) == args.ssl]
584+
assert len(libs) == 1
585+
cls = libs.pop()
586+
if args.ssl_versions:
587+
versions += [(cls, v) for v in args.ssl_versions]
588+
else:
589+
versions += [(cls, v) for v in cls.recent_versions.fget()]
582590
else:
583-
ssl_libs["openssl"][3] += ssl_libs["openssl"][2]
584-
ssl_libs["libressl"][3] += ssl_libs["libressl"][2]
585-
ssl_libs["awslc"][3] += ssl_libs["awslc"][2]
586-
if not args.disable_ancient:
587-
ssl_libs["openssl"][3] += ssl_libs["openssl"][1]
588-
ssl_libs["libressl"][3] += ssl_libs["libressl"][1]
589-
# download and register builder
591+
if args.ssl_versions:
592+
print("ERROR: SSL versions specified without specifying library")
593+
exit(1)
594+
for cls in ssl_libs:
595+
versions += [(cls, v) for v in cls.recent_versions.fget()]
596+
if not args.disable_ancient:
597+
versions += [(cls, v) for v in cls.old_versions.fget()]
598+
590599
builds = []
591-
for build_class, _, _, versions in ssl_libs.values():
592-
for version in versions:
593-
build = build_class(version, args)
594-
build.install()
595-
builds.append(build)
600+
for build_class, version in versions:
601+
build = build_class(version, args)
602+
build.install()
603+
builds.append(build)
596604

597605
if args.steps in {'modules', 'tests'}:
598606
for build in builds:

0 commit comments

Comments
 (0)