From db7e48943f038fc113ca4b9d6952c50ec4046916 Mon Sep 17 00:00:00 2001 From: Louise Poubel Date: Tue, 12 Apr 2022 13:04:10 -0700 Subject: [PATCH 1/6] [ign to gz] C++ namespaces Signed-off-by: Louise Poubel --- include/ignition/utils/Environment.hh | 4 +-- include/ignition/utils/ImplPtr.hh | 11 +++++--- include/ignition/utils/NeverDestroyed.hh | 18 ++++++------ include/ignition/utils/config.hh.in | 7 +++++ include/ignition/utils/detail/DefaultOps.hh | 6 ++-- include/ignition/utils/detail/ImplPtr.hh | 6 ++-- src/Environment.cc | 2 +- src/Environment_TEST.cc | 2 +- src/NeverDestroyed_TEST.cc | 10 +++---- .../all_symbols_have_version.bash.in | 4 +-- test/integration/deprecated_TEST.cc | 28 +++++++++++++++++++ test/integration/implptr/ImplPtr_TEST.cc | 2 +- .../implptr/implptr_test_classes.cc | 6 ++-- .../implptr/implptr_test_classes.hh | 4 +-- 14 files changed, 77 insertions(+), 33 deletions(-) create mode 100644 test/integration/deprecated_TEST.cc diff --git a/include/ignition/utils/Environment.hh b/include/ignition/utils/Environment.hh index 658a13f..cc00429 100644 --- a/include/ignition/utils/Environment.hh +++ b/include/ignition/utils/Environment.hh @@ -23,7 +23,7 @@ #include -namespace ignition +namespace gz { namespace utils { @@ -68,7 +68,7 @@ bool IGNITION_UTILS_VISIBLE unsetenv(const std::string &_name); } } // namespace utils -} // namespace ignition +} // namespace gz #endif // IGNITION_UTILS_ENVIRONMENT_HH_ diff --git a/include/ignition/utils/ImplPtr.hh b/include/ignition/utils/ImplPtr.hh index 8eba453..f312e7d 100644 --- a/include/ignition/utils/ImplPtr.hh +++ b/include/ignition/utils/ImplPtr.hh @@ -21,14 +21,16 @@ #include #include +#include #include #include #include -namespace ignition +namespace gz { namespace utils { + inline namespace IGNITION_UTILS_VERSION_NAMESPACE { ////////////////////////////////////////////////// /// \brief The ImplPtr class provides a convenient away to achieve the /// @@ -225,21 +227,22 @@ namespace ignition /// created object into it. template UniqueImplPtr MakeUniqueImpl(Args &&..._args); + } } // namespace utils -} // namespace ignition +} // namespace gz /// \brief Add a private ImplPtr to a class as dataPtr. /// This variant takes a forward-declared ImplementationClass as the impl. #define IGN_UTILS_IMPL_PTR_FWD(ImplementationClass, memberName) \ IGN_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING \ - private: ::ignition::utils::ImplPtr memberName; \ + private: ::gz::utils::ImplPtr memberName; \ IGN_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING /// \brief Add a private UniqueImplPtr to a class as dataPtr. /// This variant takes a forward-declared ImplementationClass as the impl. #define IGN_UTILS_UNIQUE_IMPL_PTR_FWD(ImplementationClass, memberName) \ IGN_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING \ - private: ::ignition::utils::UniqueImplPtr memberName; \ + private: ::gz::utils::UniqueImplPtr memberName; \ IGN_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING /// \brief Add a private ImplPtr to a class as dataPtr. diff --git a/include/ignition/utils/NeverDestroyed.hh b/include/ignition/utils/NeverDestroyed.hh index 2ad9351..b163a53 100644 --- a/include/ignition/utils/NeverDestroyed.hh +++ b/include/ignition/utils/NeverDestroyed.hh @@ -22,11 +22,13 @@ #include #include -namespace ignition +#include + +namespace gz { namespace utils { - +inline namespace IGNITION_UTILS_VERSION_NAMESPACE { /// Originally copied from https://github.com/RobotLocomotion/drake/blob/v0.36.0/common/never_destroyed.h /// Originally licensed BSD 3-Clause (https://github.com/RobotLocomotion/drake/blob/v0.36.0/LICENSE.TXT) /// Re-licensed Apache-2.0 with permission from: @@ -62,11 +64,11 @@ namespace utils /// /// static Singleton& getInstance() /// { -/// static ignition::utils::NeverDestroyed instance; +/// static gz::utils::NeverDestroyed instance; /// return instance.access(); /// } /// private: -/// friend ignition::utils::NeverDestroyed; +/// friend gz::utils::NeverDestroyed; /// Singleton() = default; /// }; /// @endcode @@ -78,7 +80,7 @@ namespace utils /// Foo ParseFoo(const std::string& foo_string) /// { /// using Dict = std::unordered_map; -/// static const ignition::utils::NeverDestroyed string_to_enum +/// static const gz::utils::NeverDestroyed string_to_enum /// { /// std::initializer_list /// { @@ -95,7 +97,7 @@ namespace utils /// @code /// const std::vector& GetConstantMagicNumbers() /// { -/// static const ignition::utils::NeverDestroyed> result +/// static const gz::utils::NeverDestroyed> result /// { /// []() /// { @@ -155,8 +157,8 @@ class NeverDestroyed private: typename std::aligned_storage::type storage; }; - +} } // namespace utils -} // namespace ignition +} // namespace gz #endif // IGNITION_UTILS_NEVERDESTROYED_HH_ diff --git a/include/ignition/utils/config.hh.in b/include/ignition/utils/config.hh.in index 0396d6d..9679bcd 100644 --- a/include/ignition/utils/config.hh.in +++ b/include/ignition/utils/config.hh.in @@ -15,3 +15,10 @@ #cmakedefine IGNITION_UTILS_BUILD_TYPE_PROFILE 1 #cmakedefine IGNITION_UTILS_BUILD_TYPE_DEBUG 1 #cmakedefine IGNITION_UTILS_BUILD_TYPE_RELEASE 1 + +namespace gz +{ +} + +// TODO(chapulina) Add deprecation warnings when using "ignition". +namespace ignition = gz; diff --git a/include/ignition/utils/detail/DefaultOps.hh b/include/ignition/utils/detail/DefaultOps.hh index 0c966cc..5cb7532 100644 --- a/include/ignition/utils/detail/DefaultOps.hh +++ b/include/ignition/utils/detail/DefaultOps.hh @@ -20,10 +20,11 @@ #include -namespace ignition +namespace gz { namespace utils { + inline namespace IGNITION_UTILS_VERSION_NAMESPACE { namespace detail { ////////////////////////////////////////////////// @@ -76,9 +77,10 @@ namespace ignition public: CopyConstruct construct; public: CopyAssign assign; }; + } } // namespace detail } // namespace utils -} // namespace ignition +} // namespace gz #endif // IGNITION_UTILS__DETAIL__DEFAULTOPS_HH_ diff --git a/include/ignition/utils/detail/ImplPtr.hh b/include/ignition/utils/detail/ImplPtr.hh index 0926f29..56fcee9 100644 --- a/include/ignition/utils/detail/ImplPtr.hh +++ b/include/ignition/utils/detail/ImplPtr.hh @@ -22,10 +22,11 @@ #include -namespace ignition +namespace gz { namespace utils { + inline namespace IGNITION_UTILS_VERSION_NAMESPACE { namespace detail { ////////////////////////////////////////////////// @@ -145,7 +146,8 @@ namespace ignition new T{std::forward(args)...}, &detail::DefaultDelete); } + } } // namespace utils -} // namespace ignition +} // namespace gz #endif // IGNITION_UTILS__DETAIL__IMPLPTR_HH_ diff --git a/src/Environment.cc b/src/Environment.cc index 6426b4b..d800e0a 100644 --- a/src/Environment.cc +++ b/src/Environment.cc @@ -21,7 +21,7 @@ #include -namespace ignition +namespace gz { namespace utils { diff --git a/src/Environment_TEST.cc b/src/Environment_TEST.cc index 47661a1..d3a84cf 100644 --- a/src/Environment_TEST.cc +++ b/src/Environment_TEST.cc @@ -19,7 +19,7 @@ #include -using namespace ignition; +using namespace gz; ///////////////////////////////////////////////// TEST(Environment, emptyENV) diff --git a/src/NeverDestroyed_TEST.cc b/src/NeverDestroyed_TEST.cc index b36f1c5..dd34bae 100644 --- a/src/NeverDestroyed_TEST.cc +++ b/src/NeverDestroyed_TEST.cc @@ -63,7 +63,7 @@ GTEST_TEST(NeverDestroyed, NoBoomTest) try { { - ignition::utils::NeverDestroyed foo; + gz::utils::NeverDestroyed foo; } ASSERT_TRUE(true); } @@ -83,11 +83,11 @@ class Singleton public: void operator=(Singleton &&) = delete; public: static Singleton &getInstance() { - static ignition::utils::NeverDestroyed instance; + static gz::utils::NeverDestroyed instance; return instance.Access(); } - private: friend ignition::utils::NeverDestroyed; + private: friend gz::utils::NeverDestroyed; private: Singleton() = default; }; @@ -108,7 +108,7 @@ enum class Foo Foo ParseFoo(const std::string &foo_string) { using Dict = std::unordered_map; - static const ignition::utils::NeverDestroyed string_to_enum{ + static const gz::utils::NeverDestroyed string_to_enum{ std::initializer_list{ {"bar", Foo::kBar}, {"baz", Foo::kBaz}, @@ -127,7 +127,7 @@ GTEST_TEST(NeverDestroyedExample, ParseFoo) using Result = std::vector; const Result &GetConstantMagicNumbers() { - static const ignition::utils::NeverDestroyed result{ + static const gz::utils::NeverDestroyed result{ []() { Result prototype; diff --git a/test/integration/all_symbols_have_version.bash.in b/test/integration/all_symbols_have_version.bash.in index 9be67a7..f950725 100644 --- a/test/integration/all_symbols_have_version.bash.in +++ b/test/integration/all_symbols_have_version.bash.in @@ -5,7 +5,7 @@ VERSIONED_NS=v@PROJECT_VERSION_MAJOR@ IGN_PROJECT=@IGN_DESIGNATION@ # Sanity check - there should be at least one symbol -NUM_SYMBOLS=$(nm $LIBPATH | grep -e "ignition.*$IGN_PROJECT" | wc -l) +NUM_SYMBOLS=$(nm $LIBPATH | grep -e "gz.*$IGN_PROJECT" | wc -l) if [ $NUM_SYMBOLS -eq 0 ] then @@ -14,7 +14,7 @@ then fi # There must be no unversioned symbols -UNVERSIONED_SYMBOLS=$(nm $LIBPATH | grep -e "ignition.*$IGN_PROJECT" | grep -e "$VERSIONED_NS" -v) +UNVERSIONED_SYMBOLS=$(nm $LIBPATH | grep -e "gz.*$IGN_PROJECT" | grep -e "$VERSIONED_NS" -v) UNVERSIONED_SYMBOL_CHARS=$(printf "$UNVERSIONED_SYMBOLS" | wc -m) if [ $UNVERSIONED_SYMBOL_CHARS -ne 0 ] diff --git a/test/integration/deprecated_TEST.cc b/test/integration/deprecated_TEST.cc new file mode 100644 index 0000000..6c3f8d3 --- /dev/null +++ b/test/integration/deprecated_TEST.cc @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2018 Open Source Robotics Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * +*/ + +#include + +#include +#include + +///////////////////////////////////////////////// +TEST(Deprecated, IgnitionNamespace) +{ + auto impl = ignition::utils::MakeImpl(); + ignition::utils::NeverDestroyed neverDestroyed; +} diff --git a/test/integration/implptr/ImplPtr_TEST.cc b/test/integration/implptr/ImplPtr_TEST.cc index 0f02ea2..f128e9c 100644 --- a/test/integration/implptr/ImplPtr_TEST.cc +++ b/test/integration/implptr/ImplPtr_TEST.cc @@ -20,7 +20,7 @@ #include #include "implptr_test_classes.hh" -using namespace ignition::implptr_test_classes; +using namespace gz::implptr_test_classes; ///////////////////////////////////////////////// TEST(ImplPtr, CopyConstruct) diff --git a/test/integration/implptr/implptr_test_classes.cc b/test/integration/implptr/implptr_test_classes.cc index fa4672e..1d13a78 100644 --- a/test/integration/implptr/implptr_test_classes.cc +++ b/test/integration/implptr/implptr_test_classes.cc @@ -20,10 +20,10 @@ #include #include -using namespace ignition; -using namespace ignition::implptr_test_classes; +using namespace gz; +using namespace gz::implptr_test_classes; -class ignition::implptr_test_classes::ObjectPrivate +class gz::implptr_test_classes::ObjectPrivate { public: void TestFunc() { diff --git a/test/integration/implptr/implptr_test_classes.hh b/test/integration/implptr/implptr_test_classes.hh index bfe88ca..cc5904e 100644 --- a/test/integration/implptr/implptr_test_classes.hh +++ b/test/integration/implptr/implptr_test_classes.hh @@ -24,7 +24,7 @@ #include #include -namespace ignition +namespace gz { namespace implptr_test_classes { @@ -117,6 +117,6 @@ namespace ignition }; } // namespace implptr_test_classes -} // namespace ignition +} // namespace gz #endif // IGNITION_UTILS_TEST_IMPLPTR_TEST_CLASSES_HH_ From ca4f3f1ce472d5ac17d7652accbd1df9f560ac97 Mon Sep 17 00:00:00 2001 From: Louise Poubel Date: Tue, 12 Apr 2022 13:21:23 -0700 Subject: [PATCH 2/6] Migration Signed-off-by: Louise Poubel --- Migration.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Migration.md b/Migration.md index 2a50778..56f3c3b 100644 --- a/Migration.md +++ b/Migration.md @@ -5,6 +5,11 @@ Deprecated code produces compile-time warnings. These warning serve as notification to users that their code should be upgraded. The next major release will remove the deprecated code. +## Ignition Utils 1.X to 2.X + +* The `ignition` namespace is deprecated and will be removed in future versions. + Use `gz` instead. + ## Ignition Utils 1.2 to 1.3 Recommended migration: From 5fee87349cdfa442df89e87c9c13a34628c5c95b Mon Sep 17 00:00:00 2001 From: Louise Poubel Date: Tue, 12 Apr 2022 15:49:29 -0700 Subject: [PATCH 3/6] nested namespace trick Signed-off-by: Louise Poubel --- include/ignition/utils/config.hh.in | 32 +++++++++++++++++++++++++++-- test/integration/deprecated_TEST.cc | 7 ++++++- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/include/ignition/utils/config.hh.in b/include/ignition/utils/config.hh.in index 9679bcd..5602d39 100644 --- a/include/ignition/utils/config.hh.in +++ b/include/ignition/utils/config.hh.in @@ -1,4 +1,24 @@ -/* Config.hh. Generated by CMake for @PROJECT_NAME_NO_VERSION@. */ +/* config.hh. Generated by CMake for @PROJECT_NAME_NO_VERSION@. */ + +/* + * Copyright (C) 2018 Open Source Robotics Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef IGNITION_UTILS__CONFIG_HH_ +#define IGNITION_UTILS__CONFIG_HH_ /* Version number */ #define IGNITION_UTILS_MAJOR_VERSION ${PROJECT_VERSION_MAJOR} @@ -16,9 +36,17 @@ #cmakedefine IGNITION_UTILS_BUILD_TYPE_DEBUG 1 #cmakedefine IGNITION_UTILS_BUILD_TYPE_RELEASE 1 +#include + namespace gz { } -// TODO(chapulina) Add deprecation warnings when using "ignition". +// TODO(chapulina) Turn on warnings after entire stack has migrated to gz +// namespace [[deprecated("Use gz namespace.")]] ignition +// { +// using namespace gz; +// } namespace ignition = gz; + +#endif diff --git a/test/integration/deprecated_TEST.cc b/test/integration/deprecated_TEST.cc index 6c3f8d3..de88e0c 100644 --- a/test/integration/deprecated_TEST.cc +++ b/test/integration/deprecated_TEST.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Open Source Robotics Foundation + * Copyright (C) 2022 Open Source Robotics Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,9 @@ #include #include +#include + +IGN_UTILS_WARN_IGNORE__DEPRECATED_DECLARATION ///////////////////////////////////////////////// TEST(Deprecated, IgnitionNamespace) @@ -26,3 +29,5 @@ TEST(Deprecated, IgnitionNamespace) auto impl = ignition::utils::MakeImpl(); ignition::utils::NeverDestroyed neverDestroyed; } + +IGN_UTILS_WARN_RESUME__DEPRECATED_DECLARATION From 162299265867bd90016ab31e4fb6c83bff1f4935 Mon Sep 17 00:00:00 2001 From: Louise Poubel Date: Tue, 12 Apr 2022 17:14:56 -0700 Subject: [PATCH 4/6] cleanup Signed-off-by: Louise Poubel --- include/ignition/utils/config.hh.in | 4 +--- test/integration/deprecated_TEST.cc | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/include/ignition/utils/config.hh.in b/include/ignition/utils/config.hh.in index 5602d39..c6e69ef 100644 --- a/include/ignition/utils/config.hh.in +++ b/include/ignition/utils/config.hh.in @@ -1,7 +1,7 @@ /* config.hh. Generated by CMake for @PROJECT_NAME_NO_VERSION@. */ /* - * Copyright (C) 2018 Open Source Robotics Foundation + * Copyright (C) 2020 Open Source Robotics Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,8 +36,6 @@ #cmakedefine IGNITION_UTILS_BUILD_TYPE_DEBUG 1 #cmakedefine IGNITION_UTILS_BUILD_TYPE_RELEASE 1 -#include - namespace gz { } diff --git a/test/integration/deprecated_TEST.cc b/test/integration/deprecated_TEST.cc index de88e0c..60dfe0f 100644 --- a/test/integration/deprecated_TEST.cc +++ b/test/integration/deprecated_TEST.cc @@ -24,6 +24,7 @@ IGN_UTILS_WARN_IGNORE__DEPRECATED_DECLARATION ///////////////////////////////////////////////// +// Make sure the ignition namespace still works TEST(Deprecated, IgnitionNamespace) { auto impl = ignition::utils::MakeImpl(); From fc3206af6ba60a8864bcdc27824ce9ebdcf40cab Mon Sep 17 00:00:00 2001 From: methylDragon Date: Mon, 16 May 2022 16:58:48 -0700 Subject: [PATCH 5/6] Update header guards Signed-off-by: methylDragon --- test/integration/implptr/implptr_test_classes.hh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/integration/implptr/implptr_test_classes.hh b/test/integration/implptr/implptr_test_classes.hh index cc5904e..f8bad9a 100644 --- a/test/integration/implptr/implptr_test_classes.hh +++ b/test/integration/implptr/implptr_test_classes.hh @@ -15,8 +15,8 @@ * */ -#ifndef IGNITION_UTILS_TEST_IMPLPTR_TEST_CLASSES_HH_ -#define IGNITION_UTILS_TEST_IMPLPTR_TEST_CLASSES_HH_ +#ifndef GZ_UTILS_TEST_IMPLPTR_TEST_CLASSES_HH_ +#define GZ_UTILS_TEST_IMPLPTR_TEST_CLASSES_HH_ #include #include @@ -119,4 +119,4 @@ namespace gz } // namespace implptr_test_classes } // namespace gz -#endif // IGNITION_UTILS_TEST_IMPLPTR_TEST_CLASSES_HH_ +#endif // GZ_UTILS_TEST_IMPLPTR_TEST_CLASSES_HH_ From e88dfe08b2612973bf792440e4f7248485d18e83 Mon Sep 17 00:00:00 2001 From: methylDragon Date: Mon, 16 May 2022 17:23:26 -0700 Subject: [PATCH 6/6] Enable namespace deprecation Signed-off-by: methylDragon --- include/ignition/utils/config.hh.in | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/include/ignition/utils/config.hh.in b/include/ignition/utils/config.hh.in index c6e69ef..685ced2 100644 --- a/include/ignition/utils/config.hh.in +++ b/include/ignition/utils/config.hh.in @@ -36,15 +36,9 @@ #cmakedefine IGNITION_UTILS_BUILD_TYPE_DEBUG 1 #cmakedefine IGNITION_UTILS_BUILD_TYPE_RELEASE 1 -namespace gz +namespace [[deprecated("Use gz namespace.")]] ignition { + using namespace gz; } -// TODO(chapulina) Turn on warnings after entire stack has migrated to gz -// namespace [[deprecated("Use gz namespace.")]] ignition -// { -// using namespace gz; -// } -namespace ignition = gz; - #endif