Skip to content

Commit

Permalink
Merge pull request #3997 from randombit/jack/binary-options-helper
Browse files Browse the repository at this point in the history
Add helper for defining binary option pairs
  • Loading branch information
randombit authored Apr 10, 2024
2 parents 4cfd407 + f2ebabb commit d9edacb
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 80 deletions.
120 changes: 46 additions & 74 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,30 @@ def process_command_line(args):
available before logging is setup.
"""

def define_option_pair(group, verb, nverb, what, default, msg=optparse.SUPPRESS_HELP):
dest = '%s_%s' % (verb, what.replace('-', '_'))

# always show the help for the option that switches away from the default
with_help = msg if not default else optparse.SUPPRESS_HELP
without_help = msg if default else optparse.SUPPRESS_HELP

group.add_option('--%s-%s' % (verb, what),
dest=dest,
action='store_true',
default=default,
help=with_help)

group.add_option('--%s-%s' % (nverb, what),
dest=dest,
action='store_false',
help=without_help)

def add_with_without_pair(group, what, default, msg=optparse.SUPPRESS_HELP):
define_option_pair(group, 'with', 'without', what, default, msg)

def add_enable_disable_pair(group, what, default, msg=optparse.SUPPRESS_HELP):
define_option_pair(group, 'enable', 'disable', what, default, msg)

parser = optparse.OptionParser(
formatter=optparse.IndentedHelpFormatter(max_help_position=50),
version=Version.as_string())
Expand Down Expand Up @@ -371,12 +395,6 @@ def process_command_line(args):
target_group.add_option('--compiler-cache',
help='specify a compiler cache to use')

target_group.add_option('--with-compilation-database', dest='with_compilation_database',
action='store_true', default=True, help=optparse.SUPPRESS_HELP)

target_group.add_option('--without-compilation-database', dest='with_compilation_database',
action='store_false', help='disable generation of compile_commands.json')

target_group.add_option('--with-endian', metavar='ORDER', default=None,
help='override byte order guess')

Expand All @@ -385,15 +403,7 @@ def process_command_line(args):
target_group.add_option('--without-os-features', action='append', metavar='FEAT',
help='specify OS features to disable')

target_group.add_option('--enable-experimental-features', dest='enable_experimental_features',
action='store_true', default=False, help='enable building of experimental features and modules')
target_group.add_option('--disable-experimental-features', dest='enable_experimental_features',
action='store_false', help=optparse.SUPPRESS_HELP)

target_group.add_option('--enable-deprecated-features', dest='enable_deprecated_features',
action='store_true', default=True, help=optparse.SUPPRESS_HELP)
target_group.add_option('--disable-deprecated-features', dest='enable_deprecated_features',
action='store_false', help='disable building of deprecated features and modules')
add_with_without_pair(target_group, 'compilation-database', True, 'disable compile_commands.json')

isa_extensions = [
'SSE2', 'SSSE3', 'SSE4.1', 'SSE4.2', 'AVX2', 'BMI2', 'RDRAND', 'RDSEED',
Expand All @@ -414,26 +424,16 @@ def process_command_line(args):
build_group.add_option('--system-cert-bundle', metavar='PATH', default=None,
help='set path to trusted CA bundle')

build_group.add_option('--with-debug-info', action='store_true', default=False, dest='with_debug_info',
help='include debug symbols')
add_with_without_pair(build_group, 'debug-info', False, 'include debug symbols')

build_group.add_option('--with-sanitizers', action='store_true', default=False, dest='with_sanitizers',
help='enable ASan/UBSan checks')
add_with_without_pair(build_group, 'sanitizers', False, 'enable ASan/UBSan checks')

build_group.add_option('--enable-sanitizers', metavar='SAN', default='',
help='enable specific sanitizers')

build_group.add_option('--with-stack-protector', dest='with_stack_protector',
action='store_true', default=None, help=optparse.SUPPRESS_HELP)

build_group.add_option('--without-stack-protector', dest='with_stack_protector',
action='store_false', help='disable stack smashing protections')

build_group.add_option('--with-coverage', action='store_true', default=False, dest='with_coverage',
help='add coverage info and disable opts')
add_with_without_pair(build_group, 'stack-protector', True, 'disable stack smashing protections')

build_group.add_option('--with-coverage-info', action='store_true', default=False, dest='with_coverage_info',
help='add coverage info')
add_with_without_pair(build_group, 'coverage-info', False, 'add coverage info')

build_group.add_option('--enable-shared-library', dest='build_shared_lib',
action='store_true', default=None,
Expand Down Expand Up @@ -518,11 +518,10 @@ def process_command_line(args):
default=True, action='store_false',
help=optparse.SUPPRESS_HELP)

build_group.add_option('--with-valgrind', help='use valgrind API',
dest='with_valgrind', action='store_true', default=False)
add_with_without_pair(build_group, 'valgrind', False, 'use valgrind API')

build_group.add_option('--unsafe-fuzzer-mode', action='store_true', default=False,
help='Disable essential checks for testing')
help=optparse.SUPPRESS_HELP)

build_group.add_option('--build-fuzzers', dest='build_fuzzers',
metavar='TYPE', default=None,
Expand All @@ -531,8 +530,7 @@ def process_command_line(args):
build_group.add_option('--with-fuzzer-lib', metavar='LIB', default=None, dest='fuzzer_lib',
help='additionally link in LIB')

build_group.add_option('--with-debug-asserts', action='store_true', default=False,
help=optparse.SUPPRESS_HELP)
add_with_without_pair(build_group, 'debug-asserts', default=False)

build_group.add_option('--unsafe-terminate-on-asserts', action='store_true', default=False,
help=optparse.SUPPRESS_HELP)
Expand All @@ -543,48 +541,20 @@ def process_command_line(args):
build_group.add_option('--build-tool', default='make',
help="specify the build tool (make, ninja)")

build_group.add_option('--with-pkg-config', action='store_true', default=None,
help=optparse.SUPPRESS_HELP)
build_group.add_option('--without-pkg-config', dest='with_pkg_config', action='store_false',
help=optparse.SUPPRESS_HELP)

build_group.add_option('--with-cmake-config', action='store_true', default=True,
help=optparse.SUPPRESS_HELP)
build_group.add_option('--without-cmake-config', dest='with_cmake_config', action='store_false',
help=optparse.SUPPRESS_HELP)
add_with_without_pair(build_group, 'pkg-config', default=None)
add_with_without_pair(build_group, 'cmake-config', default=True)

docs_group = optparse.OptionGroup(parser, 'Documentation Options')

docs_group.add_option('--with-documentation', action='store_true',
help=optparse.SUPPRESS_HELP)

docs_group.add_option('--without-documentation', action='store_false',
default=True, dest='with_documentation',
help='Skip building/installing documentation')

docs_group.add_option('--with-sphinx', action='store_true',
default=None, help='Use Sphinx')
add_with_without_pair(docs_group, 'documentation', True, 'skip building/installing documentation')

docs_group.add_option('--without-sphinx', action='store_false',
dest='with_sphinx', help=optparse.SUPPRESS_HELP)
add_with_without_pair(docs_group, 'sphinx', None, 'run Sphinx to generate docs')

docs_group.add_option('--with-pdf', action='store_true',
default=False, help='Use Sphinx to generate PDF doc')
add_with_without_pair(docs_group, 'pdf', False, 'run Sphinx to generate PDF doc')

docs_group.add_option('--without-pdf', action='store_false',
dest='with_pdf', help=optparse.SUPPRESS_HELP)
add_with_without_pair(docs_group, 'rst2man', None, 'run rst2man to generate man page')

docs_group.add_option('--with-rst2man', action='store_true',
default=None, help='Use rst2man to generate man page')

docs_group.add_option('--without-rst2man', action='store_false',
dest='with_rst2man', help=optparse.SUPPRESS_HELP)

docs_group.add_option('--with-doxygen', action='store_true',
default=False, help='Use Doxygen')

docs_group.add_option('--without-doxygen', action='store_false',
dest='with_doxygen', help=optparse.SUPPRESS_HELP)
add_with_without_pair(docs_group, 'doxygen', False, 'run Doxygen')

mods_group = optparse.OptionGroup(parser, 'Module selection')

Expand All @@ -603,6 +573,12 @@ def process_command_line(args):
mods_group.add_option('--minimized-build', action='store_true', dest='no_autoload',
help='minimize build')

add_enable_disable_pair(mods_group, 'experimental-features', False,
'enable building of experimental features and modules')

add_enable_disable_pair(mods_group, 'deprecated-features', True,
'disable building of deprecated features and modules')

# Should be derived from info.txt but this runs too early
third_party = ['boost', 'bzip2', 'lzma', 'commoncrypto', 'sqlite3', 'zlib', 'tpm']

Expand Down Expand Up @@ -690,10 +666,6 @@ def process_command_line(args):
options.no_optimizations = True
options.with_debug_info = True

if options.with_coverage:
options.with_coverage_info = True
options.no_optimizations = True

def parse_multiple_enable(modules):
if modules is None:
return []
Expand Down Expand Up @@ -2221,7 +2193,7 @@ def test_exe_extra_ldflags():
'build_fuzzers': options.build_fuzzers,
'build_examples': 'examples' in options.build_targets,

'build_coverage' : options.with_coverage_info or options.with_coverage,
'build_coverage' : options.with_coverage_info,

'symlink_shared_lib': options.build_shared_lib and osinfo.shared_lib_uses_symlinks,

Expand Down
7 changes: 1 addition & 6 deletions doc/building.rst
Original file line number Diff line number Diff line change
Expand Up @@ -836,15 +836,10 @@ Enable specific sanitizers. See ``src/build-data/cc`` for more information.

Disable stack smashing protections. **not recommended**

``--with-coverage``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Add coverage info and disable optimizations

``--with-coverage-info``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Add coverage info, but leave optimizations alone
Add coverage info

``--disable-shared-library``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down

0 comments on commit d9edacb

Please sign in to comment.