diff options
author | Andrew Morrow <acm@mongodb.com> | 2021-03-24 23:42:22 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-03-25 16:17:51 +0000 |
commit | d25e6a800437f65ada43c9bc3502031d346cd128 (patch) | |
tree | 21694cfb06760667bbb186d1dedd585d395f232d | |
parent | 22cd5303336353f6951ff80f9d454b98bb7485c1 (diff) | |
download | mongo-d25e6a800437f65ada43c9bc3502031d346cd128.tar.gz |
SERVER-54695 Disabling warnings as errors should not apply to configure checks by default
-rw-r--r-- | SConstruct | 107 | ||||
-rw-r--r-- | src/third_party/gperftools/SConscript | 4 | ||||
-rw-r--r-- | src/third_party/icu4c-57.1/source/SConscript | 3 | ||||
-rw-r--r-- | src/third_party/kms-message/SConscript | 5 | ||||
-rw-r--r-- | src/third_party/mozjs-60/SConscript | 4 | ||||
-rw-r--r-- | src/third_party/pcre-8.42/SConscript | 4 | ||||
-rw-r--r-- | src/third_party/tomcrypt-1.18.2/SConscript | 4 |
7 files changed, 92 insertions, 39 deletions
diff --git a/SConstruct b/SConstruct index 6b41e8490c7..5a7d524a1b0 100644 --- a/SConstruct +++ b/SConstruct @@ -415,9 +415,14 @@ add_option('build-fast-and-loose', type='choice', ) -add_option('disable-warnings-as-errors', - help="Don't add -Werror to compiler command line", - nargs=0, +add_option("disable-warnings-as-errors", + action="append", + choices=["configure", "source"], + const="source", + default=[], + help="Don't add a warnings-as-errors flag to compiler command lines in selected contexts; defaults to 'source' if no argument is provided", + nargs="?", + type="choice", ) add_option('detect-odr-violations', @@ -1185,12 +1190,38 @@ if get_option('build-tools') == 'next': SCons.Tool.DefaultToolpath.insert(0, os.path.abspath('site_scons/site_tools/next')) env = Environment(variables=env_vars, **envDict) +del envDict # Only print the spinner if stdout is a tty if sys.stdout.isatty(): Progress(['-\r', '\\\r', '|\r', '/\r'], interval=50) -del envDict +# We are going to start running conf tests soon, so setup +# --disable-warnings-as-errors as soon as possible. +def create_werror_generator(flagname): + werror_conftests = 'configure' not in get_option('disable-warnings-as-errors') + werror_source = 'source' not in get_option('disable-warnings-as-errors') + + def generator(target, source, env, for_signature): + if werror_conftests and "conftest" in str(target[0]): + return flagname + + if werror_source: + return flagname + + return str() + + return generator + +env.Append( + CCFLAGS=['$CCFLAGS_GENERATE_WERROR'], + CCFLAGS_GENERATE_WERROR=create_werror_generator('$CCFLAGS_WERROR'), + CXXFLAGS=['$CXXFLAGS_GENERATE_WERROR'], + CXXFLAGS_GENERATE_WERROR=create_werror_generator('$CXXFLAGS_WERROR'), + LINKFLAGS=['$LINKFLAGS_GENERATE_WERROR'], + LINKFLAGS_GENERATE_WERROR=create_werror_generator('$LINKFLAGS_WERROR'), +) + for var in ['CC', 'CXX']: if var not in env: @@ -1429,6 +1460,8 @@ detectSystem = Configure(detectEnv, help=False, custom_tests = { toolchain_search_sequence = [ "GCC", "clang" ] if mongo_platform.is_running_os('windows'): toolchain_search_sequence = [ 'MSVC', 'clang', 'GCC' ] + +detected_toolchain = None for candidate_toolchain in toolchain_search_sequence: if detectSystem.CheckForToolchain(candidate_toolchain, "C++", "CXX", ".cpp"): detected_toolchain = candidate_toolchain @@ -1471,8 +1504,17 @@ elif not detectSystem.CheckForOS(env['TARGET_OS']): detectSystem.Finish() - - +if env.TargetOSIs('posix'): + if env.ToolchainIs('gcc', 'clang'): + env.Append( + CCFLAGS_WERROR=["-Werror"], + CXXFLAGS_WERROR=['-Werror=unused-result'] if env.ToolchainIs('clang') else [], + LINKFLAGS_WERROR=['-Wl,-fatal_warnings' if env.TargetOSIs('darwin') else "-Wl,--fatal-warnings"], + ) +elif env.TargetOSIs('windows'): + env.Append( + CCFLAGS_WERROR=["/WX"] + ) env['CC_VERSION'] = mongo_toolchain.get_toolchain_ver(env, 'CC') env['CXX_VERSION'] = mongo_toolchain.get_toolchain_ver(env, 'CXX') @@ -2264,10 +2306,6 @@ elif env.TargetOSIs('windows'): # object called lock on the stack. env.Append( CCFLAGS=["/we4013", "/we4099", "/we4930"] ) - # Warnings as errors - if not has_option("disable-warnings-as-errors"): - env.Append( CCFLAGS=["/WX"] ) - env.Append( CPPDEFINES=["_CONSOLE","_CRT_SECURE_NO_WARNINGS", "_SCL_SECURE_NO_WARNINGS"] ) # this would be for pre-compiled headers, could play with it later @@ -2445,13 +2483,7 @@ if env.TargetOSIs('posix'): env.Append(CCFLAGS=["-fno-strict-aliasing"]) # env.Append( " -Wconversion" ) TODO: this doesn't really work yet - if env.TargetOSIs('linux', 'darwin', 'solaris'): - if not has_option("disable-warnings-as-errors"): - env.Append( CCFLAGS=["-Werror"] ) - env.Append( CXXFLAGS=["-Woverloaded-virtual"] ) - if env.ToolchainIs('clang') and not has_option('disable-warnings-as-errors'): - env.Append( CXXFLAGS=['-Werror=unused-result'] ) # On OS X, clang doesn't want the pthread flag at link time, or it # issues warnings which make it impossible for us to declare link @@ -2501,15 +2533,6 @@ if env.TargetOSIs('posix'): if optBuild and "treevec" in selected_experimental_optimizations: env.Append(CCFLAGS=["-ftree-vectorize"]) - # Promote linker warnings into errors. We can't yet do this on OS X because its linker considers - # noall_load obsolete and warns about it. - if not has_option("disable-warnings-as-errors"): - env.Append( - LINKFLAGS=[ - '-Wl,-fatal_warnings' if env.TargetOSIs('darwin') else "-Wl,--fatal-warnings", - ] - ) - wiredtiger = False if get_option('wiredtiger') == 'on': # Wiredtiger only supports 64-bit architecture, and will fail to compile on 32-bit @@ -2790,13 +2813,27 @@ def doConfigure(myenv): if test_flag.startswith("-Wno-") and not test_flag.startswith("-Wno-error="): test_flags.append(re.sub("^-Wno-", "-W", test_flag)) - cloned = env.Clone() + # If the user has selected ``configure` in + # `disable-warnings-as-errors`, the usual mechanisms that + # would inject Werror or similar are disabled for + # conftests. But AddFlagIfSupported requires that those flags + # be used. Disable the generators so we have explicit control. + cloned = env.Clone( + CCFLAGS_GENERATE_WERROR=[], + CXXFLAGS_GENERATE_WERROR=[], + LINKFLAGS_GENERATE_WERROR=[], + ) + cloned.Append(**test_mutation) - # For GCC, we don't need anything since bad flags are already errors, but - # adding -Werror won't hurt. For clang, bad flags are only warnings, so we need -Werror - # to make them real errors. - cloned.Append(CCFLAGS=['-Werror']) + # Add these *after* the test mutation, so that the mutation + # can't step on the warnings-as-errors state. + cloned.Append( + CCFLAGS=["$CCFLAGS_WERROR"], + CXXFLAGS=["$CXXFLAGS_WERROR"], + LINKFLAGS=["$LINKFLAGS_WERROR"], + ) + conf = Configure(cloned, help=False, custom_tests = { 'CheckFlag' : lambda ctx : CheckFlagTest(ctx, tool, extension, flag) }) @@ -2990,14 +3027,18 @@ def doConfigure(myenv): }; """ - context.Message('Checking -Wnon-virtual-dtor for false positives... ') + context.Message('Checking if -Wnon-virtual-dtor works reasonably... ') ret = context.TryCompile(textwrap.dedent(test_body), ".cpp") context.Result(ret) return ret myenvClone = myenv.Clone() - myenvClone.Append( CCFLAGS=['-Werror'] ) - myenvClone.Append( CXXFLAGS=["-Wnon-virtual-dtor"] ) + myenvClone.Append( + CCFLAGS=[ + '$CCFLAGS_WERROR', + '-Wnon-virtual-dtor', + ] + ) conf = Configure(myenvClone, help=False, custom_tests = { 'CheckNonVirtualDtor' : CheckNonVirtualDtor, }) diff --git a/src/third_party/gperftools/SConscript b/src/third_party/gperftools/SConscript index 4cc7596feb4..4f12718d26c 100644 --- a/src/third_party/gperftools/SConscript +++ b/src/third_party/gperftools/SConscript @@ -103,7 +103,9 @@ def removeIfPresent(lst, item): except ValueError: pass -for to_remove in ['-Werror', "-Wsign-compare","-Wall","-Werror=unused-result"]: +env['CCFLAGS_WERROR'] = [] +env['CXXFLAGS_WERROR'] = [] +for to_remove in ["-Wsign-compare", "-Wall"]: removeIfPresent(env['CCFLAGS'], to_remove) if not env.TargetOSIs('windows'): diff --git a/src/third_party/icu4c-57.1/source/SConscript b/src/third_party/icu4c-57.1/source/SConscript index 4486c01cc5b..35267e35a25 100644 --- a/src/third_party/icu4c-57.1/source/SConscript +++ b/src/third_party/icu4c-57.1/source/SConscript @@ -40,7 +40,8 @@ def removeIfPresent(lst, item): except ValueError: pass -for to_remove in ['-Werror', '-Wall', '-W']: +env['CCFLAGS_WERROR'] = [] +for to_remove in ['-Wall', '-W']: removeIfPresent(env['CCFLAGS'], to_remove) # Suppress sign-compare warnings. diff --git a/src/third_party/kms-message/SConscript b/src/third_party/kms-message/SConscript index 0ad6e82cfb2..e54fd075efc 100644 --- a/src/third_party/kms-message/SConscript +++ b/src/third_party/kms-message/SConscript @@ -3,13 +3,16 @@ Import("env") env = env.Clone() +env['CCFLAGS_WERROR'] = [] +env['CXXFLAGS_WERROR'] = [] + def removeIfPresent(lst, item): try: lst.remove(item) except ValueError: pass -for to_remove in ['-Werror', "-Wsign-compare", "-Wall", "-Werror=unused-result"]: +for to_remove in ["-Wsign-compare", "-Wall"]: removeIfPresent(env['CCFLAGS'], to_remove) removeIfPresent(env['CFLAGS'], to_remove) diff --git a/src/third_party/mozjs-60/SConscript b/src/third_party/mozjs-60/SConscript index 91fbd82743b..393776dd571 100644 --- a/src/third_party/mozjs-60/SConscript +++ b/src/third_party/mozjs-60/SConscript @@ -8,13 +8,15 @@ Import([ env = env.Clone() env.InjectThirdParty(libraries=['zlib']) +env['CCFLAGS_WERROR'] = [] + def removeIfPresent(lst, item): try: lst.remove(item) except ValueError: pass -for to_remove in ['-Werror', '-Wall', '-W', '/W3', '-Wsign-compare']: +for to_remove in ['-Wall', '-W', '/W3', '-Wsign-compare']: removeIfPresent(env['CCFLAGS'], to_remove) # See what -D's show up in make. The AB_CD one might change, but we're little diff --git a/src/third_party/pcre-8.42/SConscript b/src/third_party/pcre-8.42/SConscript index 71cc36ea5c5..7abb80b2f24 100644 --- a/src/third_party/pcre-8.42/SConscript +++ b/src/third_party/pcre-8.42/SConscript @@ -6,13 +6,15 @@ env = env.Clone() env.Append( CPPDEFINES=[ "HAVE_CONFIG_H", ] ) +env['CCFLAGS_WERROR'] = [] + def removeIfPresent(lst, item): try: lst.remove(item) except ValueError: pass -for to_remove in ['-Werror', '-Wall', '-W']: +for to_remove in ['-Wall', '-W']: removeIfPresent(env['CCFLAGS'], to_remove) # Directories that include generated config.h for various platforms diff --git a/src/third_party/tomcrypt-1.18.2/SConscript b/src/third_party/tomcrypt-1.18.2/SConscript index e65a117983e..0d47496892a 100644 --- a/src/third_party/tomcrypt-1.18.2/SConscript +++ b/src/third_party/tomcrypt-1.18.2/SConscript @@ -6,13 +6,15 @@ Import([ env = env.Clone() +env['CCFLAGS_WERROR'] = [] + def removeIfPresent(lst, item): try: lst.remove(item) except ValueError: pass -for to_remove in ['-Werror', '-Wall', '-W']: +for to_remove in ['-Wall', '-W']: removeIfPresent(env['CCFLAGS'], to_remove) env.Prepend(CPPPATH=[ |