Files
gem5/src/base/SConsopts
Daniel R. Carvalho 43b026f3f9 base: Add macros to deprecate namespaces and classes
The GEM5_DEPRECATED_NAMESPACE macro temporarily declares
a namespace with the deprecated name that prints a
warning message when used. It also make sure that when
the old namespace name is used the new name is referenced.

The GEM5_DEPRECATED_CLASS macro deprecates classes that
were renamed, or moved to different namespaces.

Attributes in namespaces are an issue, though.
- Clang only allows from version 6 on, and only when
  using C++17.
- GCC has a bug before version 10 where the deprecated
  attribute was not properly recognized in namespaces:
  https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79817

Possible solutions for GCC < 10:
1)
    \#define GEM5_DEPRECATED_NAMESPACE() \
    namespace gem5 { namespace deprecated { \
        auto namespace_##old_namespace = [](){ \
            GEM5_DEPRECATED("Please use the new namespace: '" \
                          \#new_namespace "'") \
            int old_namespace; \
            return old_namespace; \
        }; \
    }} \
    namespace new_namespace {} \
    namespace old_namespace { \
        using namespace new_namespace; \
    }

    Add the above macro to all headers that previously
    declared the deprecated namespace to trigger a
    warning. This is extremely inconvenient because
    every file that includes that header will trigger
    the deprecation warning, so the compilation output
    gets VERY clogged.
2)  Similar to 1), but do not use the temporary variable
    on declaration. This would require using the variable
    somewhere else, like a respective .c file. This is
    not always possible, so we could resort to adding a
    special file (e.g., base/deprecated_elements.cc)
    containing all uses of the deprecated temporary
    variables.
3)
    \#define GEM5_DEPRECATED_NAMESPACE(old_ns, new_ns) \
        namespace old_ns = new_ns;
    Similar to 3), but simply declare an alias in the
    header files (see above macro) to maintain backwards
    compatibility. Then use the special file to declare
    all deprecation messages.
4)
    Rely on release notes / e-mail to the mailing list
    to inform that those are deprecated.

We have selected option 4 for these problematic instances.

Checking if namespace deprecation is possible is done
through scons.

Jira issues:
https://gem5.atlassian.net/browse/GEM5-975
https://gem5.atlassian.net/browse/GEM5-991

Change-Id: Ide234f6a8707d88a869fa843bf8c61ca7714e4f3
Signed-off-by: Daniel R. Carvalho <odanrc@yahoo.com.br>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/45246
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
Maintainer: Jason Lowe-Power <power.jg@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2021-05-21 10:05:09 +00:00

76 lines
3.3 KiB
Plaintext

# Copyright 2020 Google, Inc.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met: redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer;
# redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution;
# neither the name of the copyright holders nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Import('*')
from gem5_scons import warning
import gem5_scons
with gem5_scons.Configure(main) as conf:
# Check for <fenv.h> (C99 FP environment control)
conf.env['HAVE_FENV'] = conf.CheckHeader('fenv.h', '<>')
if not conf.env['HAVE_FENV']:
warning("Header file <fenv.h> not found.\n"
"This host has no IEEE FP rounding mode control.")
# Check for <png.h> (libpng library needed if wanting to dump
# frame buffer image in png format)
conf.env['HAVE_PNG'] = conf.CheckHeader('png.h', '<>')
if not conf.env['HAVE_PNG']:
warning("Header file <png.h> not found.\n"
"This host has no libpng library.\n"
"Disabling support for PNG framebuffers.")
have_posix_clock = \
conf.CheckLibWithHeader([None, 'rt'], 'time.h', 'C',
'clock_nanosleep(0,0,NULL,NULL);')
if not have_posix_clock:
warning("Can't find library for POSIX clocks.")
# Valgrind gets much less confused if you tell it when you're using
# alternative stacks.
conf.env['HAVE_VALGRIND'] = conf.CheckCHeader('valgrind/valgrind.h')
conf.env['HAVE_DEPRECATED_NAMESPACE'] = conf.TryCompile('''
int main() {return 0;}
namespace [[gnu::deprecated("Test namespace deprecation")]]
test_deprecated_namespace {}
''', '.cc')
if not conf.env['HAVE_DEPRECATED_NAMESPACE']:
warning("Deprecated namespaces are not supported by this compiler.\n"
"Please make sure to check the mailing list for deprecation "
"announcements.")
sticky_vars.Add(BoolVariable('USE_POSIX_CLOCK', 'Use POSIX Clocks',
have_posix_clock))
export_vars.extend([
'HAVE_FENV', 'HAVE_PNG', 'USE_POSIX_CLOCK', 'HAVE_VALGRIND',
'HAVE_DEPRECATED_NAMESPACE'])