Path: blob/main/contrib/jemalloc/scripts/gen_travis.py
39507 views
#!/usr/bin/env python312from itertools import combinations, chain3from enum import Enum, auto456LINUX = 'linux'7OSX = 'osx'8WINDOWS = 'windows'9FREEBSD = 'freebsd'101112AMD64 = 'amd64'13ARM64 = 'arm64'14PPC64LE = 'ppc64le'151617TRAVIS_TEMPLATE = """\18# This config file is generated by ./scripts/gen_travis.py.19# Do not edit by hand.2021# We use 'minimal', because 'generic' makes Windows VMs hang at startup. Also22# the software provided by 'generic' is simply not needed for our tests.23# Differences are explained here:24# https://docs.travis-ci.com/user/languages/minimal-and-generic/25language: minimal26dist: focal2728jobs:29include:30{jobs}3132before_install:33- |-34if test -f "./scripts/$TRAVIS_OS_NAME/before_install.sh"; then35source ./scripts/$TRAVIS_OS_NAME/before_install.sh36fi3738before_script:39- |-40if test -f "./scripts/$TRAVIS_OS_NAME/before_script.sh"; then41source ./scripts/$TRAVIS_OS_NAME/before_script.sh42else43scripts/gen_travis.py > travis_script && diff .travis.yml travis_script44autoconf45# If COMPILER_FLAGS are not empty, add them to CC and CXX46./configure ${{COMPILER_FLAGS:+ CC="$CC $COMPILER_FLAGS" \47CXX="$CXX $COMPILER_FLAGS"}} $CONFIGURE_FLAGS48make -j349make -j3 tests50fi5152script:53- |-54if test -f "./scripts/$TRAVIS_OS_NAME/script.sh"; then55source ./scripts/$TRAVIS_OS_NAME/script.sh56else57make check58fi59"""606162class Option(object):63class Type:64COMPILER = auto()65COMPILER_FLAG = auto()66CONFIGURE_FLAG = auto()67MALLOC_CONF = auto()68FEATURE = auto()6970def __init__(self, type, value):71self.type = type72self.value = value7374@staticmethod75def as_compiler(value):76return Option(Option.Type.COMPILER, value)7778@staticmethod79def as_compiler_flag(value):80return Option(Option.Type.COMPILER_FLAG, value)8182@staticmethod83def as_configure_flag(value):84return Option(Option.Type.CONFIGURE_FLAG, value)8586@staticmethod87def as_malloc_conf(value):88return Option(Option.Type.MALLOC_CONF, value)8990@staticmethod91def as_feature(value):92return Option(Option.Type.FEATURE, value)9394def __eq__(self, obj):95return (isinstance(obj, Option) and obj.type == self.type96and obj.value == self.value)979899# The 'default' configuration is gcc, on linux, with no compiler or configure100# flags. We also test with clang, -m32, --enable-debug, --enable-prof,101# --disable-stats, and --with-malloc-conf=tcache:false. To avoid abusing102# travis though, we don't test all 2**7 = 128 possible combinations of these;103# instead, we only test combinations of up to 2 'unusual' settings, under the104# hope that bugs involving interactions of such settings are rare.105MAX_UNUSUAL_OPTIONS = 2106107108GCC = Option.as_compiler('CC=gcc CXX=g++')109CLANG = Option.as_compiler('CC=clang CXX=clang++')110CL = Option.as_compiler('CC=cl.exe CXX=cl.exe')111112113compilers_unusual = [CLANG,]114115116CROSS_COMPILE_32BIT = Option.as_feature('CROSS_COMPILE_32BIT')117feature_unusuals = [CROSS_COMPILE_32BIT]118119120configure_flag_unusuals = [Option.as_configure_flag(opt) for opt in (121'--enable-debug',122'--enable-prof',123'--disable-stats',124'--disable-libdl',125'--enable-opt-safety-checks',126'--with-lg-page=16',127)]128129130malloc_conf_unusuals = [Option.as_malloc_conf(opt) for opt in (131'tcache:false',132'dss:primary',133'percpu_arena:percpu',134'background_thread:true',135)]136137138all_unusuals = (compilers_unusual + feature_unusuals139+ configure_flag_unusuals + malloc_conf_unusuals)140141142def get_extra_cflags(os, compiler):143if os == FREEBSD:144return []145146if os == WINDOWS:147# For non-CL compilers under Windows (for now it's only MinGW-GCC),148# -fcommon needs to be specified to correctly handle multiple149# 'malloc_conf' symbols and such, which are declared weak under Linux.150# Weak symbols don't work with MinGW-GCC.151if compiler != CL.value:152return ['-fcommon']153else:154return []155156# We get some spurious errors when -Warray-bounds is enabled.157extra_cflags = ['-Werror', '-Wno-array-bounds']158if compiler == CLANG.value or os == OSX:159extra_cflags += [160'-Wno-unknown-warning-option',161'-Wno-ignored-attributes'162]163if os == OSX:164extra_cflags += [165'-Wno-deprecated-declarations',166]167return extra_cflags168169170# Formats a job from a combination of flags171def format_job(os, arch, combination):172compilers = [x.value for x in combination if x.type == Option.Type.COMPILER]173assert(len(compilers) <= 1)174compiler_flags = [x.value for x in combination if x.type == Option.Type.COMPILER_FLAG]175configure_flags = [x.value for x in combination if x.type == Option.Type.CONFIGURE_FLAG]176malloc_conf = [x.value for x in combination if x.type == Option.Type.MALLOC_CONF]177features = [x.value for x in combination if x.type == Option.Type.FEATURE]178179if len(malloc_conf) > 0:180configure_flags.append('--with-malloc-conf=' + ','.join(malloc_conf))181182if not compilers:183compiler = GCC.value184else:185compiler = compilers[0]186187extra_environment_vars = ''188cross_compile = CROSS_COMPILE_32BIT.value in features189if os == LINUX and cross_compile:190compiler_flags.append('-m32')191192features_str = ' '.join([' {}=yes'.format(feature) for feature in features])193194stringify = lambda arr, name: ' {}="{}"'.format(name, ' '.join(arr)) if arr else ''195env_string = '{}{}{}{}{}{}'.format(196compiler,197features_str,198stringify(compiler_flags, 'COMPILER_FLAGS'),199stringify(configure_flags, 'CONFIGURE_FLAGS'),200stringify(get_extra_cflags(os, compiler), 'EXTRA_CFLAGS'),201extra_environment_vars)202203job = ' - os: {}\n'.format(os)204job += ' arch: {}\n'.format(arch)205job += ' env: {}'.format(env_string)206return job207208209def generate_unusual_combinations(unusuals, max_unusual_opts):210"""211Generates different combinations of non-standard compilers, compiler flags,212configure flags and malloc_conf settings.213214@param max_unusual_opts: Limit of unusual options per combination.215"""216return chain.from_iterable(217[combinations(unusuals, i) for i in range(max_unusual_opts + 1)])218219220def included(combination, exclude):221"""222Checks if the combination of options should be included in the Travis223testing matrix.224225@param exclude: A list of options to be avoided.226"""227return not any(excluded in combination for excluded in exclude)228229230def generate_jobs(os, arch, exclude, max_unusual_opts, unusuals=all_unusuals):231jobs = []232for combination in generate_unusual_combinations(unusuals, max_unusual_opts):233if included(combination, exclude):234jobs.append(format_job(os, arch, combination))235return '\n'.join(jobs)236237238def generate_linux(arch):239os = LINUX240241# Only generate 2 unusual options for AMD64 to reduce matrix size242max_unusual_opts = MAX_UNUSUAL_OPTIONS if arch == AMD64 else 1243244exclude = []245if arch == PPC64LE:246# Avoid 32 bit builds and clang on PowerPC247exclude = (CROSS_COMPILE_32BIT, CLANG,)248249return generate_jobs(os, arch, exclude, max_unusual_opts)250251252def generate_macos(arch):253os = OSX254255max_unusual_opts = 1256257exclude = ([Option.as_malloc_conf(opt) for opt in (258'dss:primary',259'percpu_arena:percpu',260'background_thread:true')] +261[Option.as_configure_flag('--enable-prof')] +262[CLANG,])263264return generate_jobs(os, arch, exclude, max_unusual_opts)265266267def generate_windows(arch):268os = WINDOWS269270max_unusual_opts = 3271unusuals = (272Option.as_configure_flag('--enable-debug'),273CL,274CROSS_COMPILE_32BIT,275)276return generate_jobs(os, arch, (), max_unusual_opts, unusuals)277278279def generate_freebsd(arch):280os = FREEBSD281282max_unusual_opts = 4283unusuals = (284Option.as_configure_flag('--enable-debug'),285Option.as_configure_flag('--enable-prof --enable-prof-libunwind'),286Option.as_configure_flag('--with-lg-page=16 --with-malloc-conf=tcache:false'),287CROSS_COMPILE_32BIT,288)289return generate_jobs(os, arch, (), max_unusual_opts, unusuals)290291292293def get_manual_jobs():294return """\295# Development build296- os: linux297env: CC=gcc CXX=g++ CONFIGURE_FLAGS="--enable-debug \298--disable-cache-oblivious --enable-stats --enable-log --enable-prof" \299EXTRA_CFLAGS="-Werror -Wno-array-bounds"300# --enable-expermental-smallocx:301- os: linux302env: CC=gcc CXX=g++ CONFIGURE_FLAGS="--enable-debug \303--enable-experimental-smallocx --enable-stats --enable-prof" \304EXTRA_CFLAGS="-Werror -Wno-array-bounds"305"""306307308def main():309jobs = '\n'.join((310generate_windows(AMD64),311312generate_freebsd(AMD64),313314generate_linux(AMD64),315generate_linux(PPC64LE),316317generate_macos(AMD64),318319get_manual_jobs(),320))321322print(TRAVIS_TEMPLATE.format(jobs=jobs))323324325if __name__ == '__main__':326main()327328329