From 4c05d18ca2673d2707803e185ae1e2bee45faf57 Mon Sep 17 00:00:00 2001 From: Bi0T1N Date: Thu, 17 Mar 2022 14:15:34 +0100 Subject: [PATCH 01/14] Add unittest for EmbeddedSpec with existing mappings Signed-off-by: Bi0T1N --- src/SDF_TEST.cc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/SDF_TEST.cc b/src/SDF_TEST.cc index ca14549df..8ff466102 100644 --- a/src/SDF_TEST.cc +++ b/src/SDF_TEST.cc @@ -559,6 +559,27 @@ TEST(SDF, Version) EXPECT_STREQ(SDF_VERSION, sdf::SDF::Version().c_str()); } +///////////////////////////////////////////////// +TEST(SDF, EmbeddedSpec) +{ + std::string result; + std::string output; + + result = sdf::SDF::EmbeddedSpec("actor.sdf", false); + EXPECT_NE(result.find(""), std::string::npos); + EXPECT_NE(result.find(""), std::string::npos); + result = sdf::SDF::EmbeddedSpec("actor.sdf", true); + EXPECT_NE(result.find(""), std::string::npos); + EXPECT_NE(result.find(""), std::string::npos); + + result = sdf::SDF::EmbeddedSpec("root.sdf", false); + EXPECT_NE(result.find("SDFormat base element"), std::string::npos); + EXPECT_NE(result.find("name=\"version\" type=\"string\""), std::string::npos); + result = sdf::SDF::EmbeddedSpec("root.sdf", true); + EXPECT_NE(result.find("SDFormat base element"), std::string::npos); + EXPECT_NE(result.find("name=\"version\" type=\"string\""), std::string::npos); +} + ///////////////////////////////////////////////// TEST(SDF, FilePath) { From 814cfe2b5a8ce9c17337c371de599d51b47d07a2 Mon Sep 17 00:00:00 2001 From: Bi0T1N Date: Thu, 17 Mar 2022 14:22:51 +0100 Subject: [PATCH 02/14] Add unittest for EmbeddedSpec for non-existing mappings this uses internal functions from GoogleTests to capture the stderr message but according to the documentation it should be fine to use them: // All macros ending with _ and symbols defined in an // internal namespace are subject to change without notice. Code // outside Google Test MUST NOT USE THEM DIRECTLY. Macros that don't // end with _ are part of Google Test's public API and can be used by // code outside Google Test. see https://github.com/google/googletest/blob/main/googletest/include/gtest/internal/gtest-port.h Signed-off-by: Bi0T1N --- src/SDF_TEST.cc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/SDF_TEST.cc b/src/SDF_TEST.cc index 8ff466102..0edde11fa 100644 --- a/src/SDF_TEST.cc +++ b/src/SDF_TEST.cc @@ -580,6 +580,26 @@ TEST(SDF, EmbeddedSpec) EXPECT_NE(result.find("name=\"version\" type=\"string\""), std::string::npos); } +TEST(SDF, EmbeddedSpecNonExistent) +{ + std::string result; + std::string output; + + testing::internal::CaptureStderr(); + result = sdf::SDF::EmbeddedSpec("unavailable.sdf", false); + output = testing::internal::GetCapturedStderr(); + EXPECT_NE(output.find("Unable to find SDF filename"), std::string::npos); + EXPECT_NE(output.find("with version"), std::string::npos); + EXPECT_TRUE(result.empty()); + + output = ""; + testing::internal::CaptureStderr(); + result = sdf::SDF::EmbeddedSpec("unavailable.sdf", true); + output = testing::internal::GetCapturedStderr(); + EXPECT_TRUE(output.empty()); + EXPECT_TRUE(result.empty()); +} + ///////////////////////////////////////////////// TEST(SDF, FilePath) { From 3901028a0cc7566761573f6f5e042866f57f5db1 Mon Sep 17 00:00:00 2001 From: Bi0T1N Date: Thu, 17 Mar 2022 16:04:10 +0100 Subject: [PATCH 03/14] Port embedSdf script from Ruby to Python3 - removes Ruby dependency (see #274) - improvements for cpplint checks (e.g. copyright header) Signed-off-by: Bi0T1N --- sdf/CMakeLists.txt | 2 +- sdf/embedSdf.py | 147 +++++++++++++++++++++++++++++++++++++++++++++ sdf/embedSdf.rb | 45 -------------- 3 files changed, 148 insertions(+), 46 deletions(-) create mode 100644 sdf/embedSdf.py delete mode 100755 sdf/embedSdf.rb diff --git a/sdf/CMakeLists.txt b/sdf/CMakeLists.txt index 127458d91..133c4459d 100644 --- a/sdf/CMakeLists.txt +++ b/sdf/CMakeLists.txt @@ -15,7 +15,7 @@ add_dependencies(schema schema1_10) # Generate the EmbeddedSdf.cc file, which contains all the supported SDF # descriptions in a map of strings. The parser.cc file uses EmbeddedSdf.hh. execute_process( - COMMAND ${RUBY} ${CMAKE_SOURCE_DIR}/sdf/embedSdf.rb + COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/sdf/embedSdf.py WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/sdf" OUTPUT_FILE "${PROJECT_BINARY_DIR}/src/EmbeddedSdf.cc" ) diff --git a/sdf/embedSdf.py b/sdf/embedSdf.py new file mode 100644 index 000000000..6e5af2f22 --- /dev/null +++ b/sdf/embedSdf.py @@ -0,0 +1,147 @@ +#!/usr/bin/env python3 +from pathlib import Path + +""""Script for generating a C++ file that contains the content from all SDF files""" + +# The list of supported SDF specification versions. This will let us drop +# versions without removing the directories. +SUPPORTED_SDF_VERSIONS = ['1.9', '1.8', '1.7', '1.6', '1.5', '1.4', '1.3', '1.2'] + +# The list of supported SDF conversions. This list includes versions that +# a user can convert an existing SDF version to. +SUPPORTED_SDF_CONVERSIONS = ['1.9', '1.8', '1.7', '1.6', '1.5', '1.4', '1.3'] + +# whitespace indentation for C++ code +INDENTATION = ' ' + + +def get_copyright_notice() -> str: + """ + Provides the copyrigt notice for the C++ file + + :returns: copyright notice + """ + res = [] + res.append('/*') + res.append(' * Copyright 2022 Open Source Robotics Foundation') + res.append(' *') + res.append(' * Licensed under the Apache License, Version 2.0 (the "License");') + res.append(' * you may not use this file except in compliance with the License.') + res.append(' * You may obtain a copy of the License at') + res.append(' *') + res.append(' * http://www.apache.org/licenses/LICENSE-2.0') + res.append(' *') + res.append(' * Unless required by applicable law or agreed to in writing, software') + res.append(' * distributed under the License is distributed on an "AS IS" BASIS,') + res.append(' * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.') + res.append(' * See the License for the specific language governing permissions and') + res.append(' * limitations under the License.') + res.append(' *') + res.append('*/') + res.append('') + return '\n'.join(res) + + +def get_file_header_prolog() -> str: + """ + Provides the include statement, namespace and variable declaration of the C++ file + + :returns: prolog of the C++ file + """ + res = [] + res.append('#include "EmbeddedSdf.hh"') + res.append('') + res.append('namespace sdf') + res.append('{') + res.append('inline namespace SDF_VERSION_NAMESPACE') + res.append('{') + res.append('/////////////////////////////////////////////////') + res.append('const std::map &GetEmbeddedSdf()') + res.append('{') + res.append(INDENTATION + 'static const std::map result {') + res.append('') + return '\n'.join(res) + + +def embed_sdf_content(arg_path: str, arg_file_content: str) -> str: + """ + Generates a string pair with the folder and filename as well as the content of the file + + :param arg_path: Foldername and filename of the SDF + :param arg_file_content: Content of the provided file + :returns: raw string literal mapping pair for the std::map + """ + res = [] + res.append('// NOLINT') + res.append('{') + res.append(f'"{arg_path}",') + res.append('R"__sdf_literal__(') + res.append(f'{arg_file_content}') + res.append(')__sdf_literal__"') + res.append('},') + res.append('') + return '\n'.join(res) + + +def get_map_content(arg_pathlist: Path) -> str: + """ + Generates a string pair with the folder and filename as well as the content + of the file in ascending order + + :param arg_pathlist: Foldername and all filenames inside it + :returns: mapping pairs for the std::map + """ + map_str = '' + files = [] + for path in pathlist: + files.append(str(path)) + # get ascending order + files.sort() + for file in files: + with Path(file).open() as f: + content = f.read() + map_str += embed_sdf_content(file, content) + return map_str + + +def get_file_header_epilog() -> str: + """ + Provides the return statement and the closing brackets of the C++ file + + :returns: epilog of the C++ file + """ + res = [] + res.append('') + res.append(INDENTATION + '};') + res.append('') + res.append(INDENTATION + 'return result;') + res.append('}') + res.append('') + res.append('}') + res.append('} // namespace sdf') + res.append('') + return '\n'.join(res) + + +if __name__ == "__main__": + copyright = get_copyright_notice() + prolog = get_file_header_prolog() + + map_str = "" + for sdf_version in SUPPORTED_SDF_VERSIONS: + pathlist = Path(sdf_version).glob('*.sdf') + map_str += get_map_content(pathlist) + + for sdf_conversion in SUPPORTED_SDF_CONVERSIONS: + pathlist = Path(sdf_conversion).glob('*.convert') + map_str += get_map_content(pathlist) + + # remove the last comma + map_str = map_str[:-2] + + epilog = get_file_header_epilog() + + output = copyright + prolog + map_str + epilog + + # output to stdin so that CMake can read it and create the appropriate file + print(output) diff --git a/sdf/embedSdf.rb b/sdf/embedSdf.rb deleted file mode 100755 index 488ff698d..000000000 --- a/sdf/embedSdf.rb +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env ruby - -# The list of supported SDF specification versions. This will let us drop -# versions without removing the directories. -supportedSdfVersions = ['1.10', '1.9', '1.8', '1.7', '1.6', '1.5', '1.4', '1.3', '1.2'] - -# The list of supported SDF conversions. This list includes versions that -# a user can convert an existing SDF version to. -supportedSdfConversions = ['1.10', '1.9', '1.8', '1.7', '1.6', '1.5', '1.4', '1.3'] - -puts %q! -#include "EmbeddedSdf.hh" - -namespace sdf { -inline namespace SDF_VERSION_NAMESPACE { - -const std::map &GetEmbeddedSdf() { - static const std::map result{ -! - -# Stores the contents of the file in the map. -def embed(pathname) - puts "{\"#{pathname}\", R\"__sdf_literal__(" - infile = File.open(pathname) - puts infile.read - puts ")__sdf_literal__\"}," -end - -# Embed the supported *.sdf files. -supportedSdfVersions.each do |version| - Dir.glob("#{version}/*.sdf").sort.each { |file| embed(file) } -end - -# Embed the supported *.convert files. -supportedSdfConversions.each do |version| - Dir.glob("#{version}/*.convert").sort.each { |file| embed(file) } -end -puts %q! - }; - return result; -} - -} -} -! From f7c502c20ecfe4651c326e6b37a43012f005dbb0 Mon Sep 17 00:00:00 2001 From: Bi0T1N Date: Fri, 18 Mar 2022 17:56:29 +0100 Subject: [PATCH 04/14] Hardcode separator in generated C++ mapping to '/' it should not be operating system dependent because it is hardcoded to '/' in the C++ file that performs the lookup Signed-off-by: Bi0T1N --- sdf/embedSdf.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sdf/embedSdf.py b/sdf/embedSdf.py index 6e5af2f22..ee88342a5 100644 --- a/sdf/embedSdf.py +++ b/sdf/embedSdf.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -from pathlib import Path +from pathlib import Path, PurePosixPath """"Script for generating a C++ file that contains the content from all SDF files""" @@ -94,7 +94,9 @@ def get_map_content(arg_pathlist: Path) -> str: map_str = '' files = [] for path in pathlist: - files.append(str(path)) + # dir separator is hardcoded to '/' in C++ mapping + posix_path = PurePosixPath(path) + files.append(str(posix_path)) # get ascending order files.sort() for file in files: From 59fb65672d5997e3d2e9b2096cf173be4c5c8c89 Mon Sep 17 00:00:00 2001 From: Bi0T1N Date: Fri, 18 Mar 2022 21:18:05 +0100 Subject: [PATCH 05/14] Output variable to trace Windows issue Signed-off-by: Bi0T1N --- src/SDF_TEST.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SDF_TEST.cc b/src/SDF_TEST.cc index 0edde11fa..cbe2414d4 100644 --- a/src/SDF_TEST.cc +++ b/src/SDF_TEST.cc @@ -588,7 +588,7 @@ TEST(SDF, EmbeddedSpecNonExistent) testing::internal::CaptureStderr(); result = sdf::SDF::EmbeddedSpec("unavailable.sdf", false); output = testing::internal::GetCapturedStderr(); - EXPECT_NE(output.find("Unable to find SDF filename"), std::string::npos); + EXPECT_NE(output.find("Unable to find SDF filename"), std::string::npos) << output; EXPECT_NE(output.find("with version"), std::string::npos); EXPECT_TRUE(result.empty()); From 30fbd1d158826c8f5aebbd53a827a49dc89ff362 Mon Sep 17 00:00:00 2001 From: Bi0T1N Date: Fri, 18 Mar 2022 22:23:20 +0100 Subject: [PATCH 06/14] Revert "Output variable to trace Windows issue" This reverts commit 2322458a6a12d0ddb28cd2fb612c65098faecfd0. Signed-off-by: Bi0T1N --- src/SDF_TEST.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SDF_TEST.cc b/src/SDF_TEST.cc index cbe2414d4..0edde11fa 100644 --- a/src/SDF_TEST.cc +++ b/src/SDF_TEST.cc @@ -588,7 +588,7 @@ TEST(SDF, EmbeddedSpecNonExistent) testing::internal::CaptureStderr(); result = sdf::SDF::EmbeddedSpec("unavailable.sdf", false); output = testing::internal::GetCapturedStderr(); - EXPECT_NE(output.find("Unable to find SDF filename"), std::string::npos) << output; + EXPECT_NE(output.find("Unable to find SDF filename"), std::string::npos); EXPECT_NE(output.find("with version"), std::string::npos); EXPECT_TRUE(result.empty()); From f10c255b60801cbb2c476f64976c628a35477a96 Mon Sep 17 00:00:00 2001 From: Bi0T1N Date: Fri, 18 Mar 2022 22:26:32 +0100 Subject: [PATCH 07/14] Refactor code to avoid GTest GetCapturedStderr it's the same approach as in parser_TEST.cc Signed-off-by: Bi0T1N --- src/SDF_TEST.cc | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/SDF_TEST.cc b/src/SDF_TEST.cc index 0edde11fa..12d50d0a9 100644 --- a/src/SDF_TEST.cc +++ b/src/SDF_TEST.cc @@ -563,7 +563,6 @@ TEST(SDF, Version) TEST(SDF, EmbeddedSpec) { std::string result; - std::string output; result = sdf::SDF::EmbeddedSpec("actor.sdf", false); EXPECT_NE(result.find(""), std::string::npos); @@ -583,21 +582,32 @@ TEST(SDF, EmbeddedSpec) TEST(SDF, EmbeddedSpecNonExistent) { std::string result; - std::string output; - testing::internal::CaptureStderr(); + // Capture sdferr output + std::stringstream stderr_buffer; + auto old = std::cerr.rdbuf(stderr_buffer.rdbuf()); + +#ifdef _WIN32 + sdf::Console::Instance()->SetQuiet(false); +#endif + result = sdf::SDF::EmbeddedSpec("unavailable.sdf", false); - output = testing::internal::GetCapturedStderr(); - EXPECT_NE(output.find("Unable to find SDF filename"), std::string::npos); - EXPECT_NE(output.find("with version"), std::string::npos); + EXPECT_NE(stderr_buffer.str().find("Unable to find SDF filename"), std::string::npos); + EXPECT_NE(stderr_buffer.str().find("with version"), std::string::npos); EXPECT_TRUE(result.empty()); - output = ""; - testing::internal::CaptureStderr(); + // clear the contents of the buffer + stderr_buffer.str(""); + result = sdf::SDF::EmbeddedSpec("unavailable.sdf", true); - output = testing::internal::GetCapturedStderr(); - EXPECT_TRUE(output.empty()); + EXPECT_TRUE(stderr_buffer.str().empty()); EXPECT_TRUE(result.empty()); + + // Revert cerr rdbuf to not interfere with other tests + std::cerr.rdbuf(old); +#ifdef _WIN32 + sdf::Console::Instance()->SetQuiet(true); +#endif } ///////////////////////////////////////////////// From 42c1cb0aa87579a07e00a111d53f0a78de374cbf Mon Sep 17 00:00:00 2001 From: Bi0T1N Date: Fri, 1 Jul 2022 22:38:15 +0200 Subject: [PATCH 08/14] Use Python3_EXECUTABLE variable for command execution Signed-off-by: Bi0T1N --- sdf/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdf/CMakeLists.txt b/sdf/CMakeLists.txt index 133c4459d..b3ab2a484 100644 --- a/sdf/CMakeLists.txt +++ b/sdf/CMakeLists.txt @@ -15,7 +15,7 @@ add_dependencies(schema schema1_10) # Generate the EmbeddedSdf.cc file, which contains all the supported SDF # descriptions in a map of strings. The parser.cc file uses EmbeddedSdf.hh. execute_process( - COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/sdf/embedSdf.py + COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/sdf/embedSdf.py WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/sdf" OUTPUT_FILE "${PROJECT_BINARY_DIR}/src/EmbeddedSdf.cc" ) From 468e0c0e0d3f72e521e01f285e3aafae33619beb Mon Sep 17 00:00:00 2001 From: Bi0T1N Date: Fri, 1 Jul 2022 23:54:57 +0200 Subject: [PATCH 09/14] Fix line length for cpplint Signed-off-by: Bi0T1N --- src/SDF_TEST.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/SDF_TEST.cc b/src/SDF_TEST.cc index 12d50d0a9..df5143977 100644 --- a/src/SDF_TEST.cc +++ b/src/SDF_TEST.cc @@ -566,10 +566,12 @@ TEST(SDF, EmbeddedSpec) result = sdf::SDF::EmbeddedSpec("actor.sdf", false); EXPECT_NE(result.find(""), std::string::npos); - EXPECT_NE(result.find(""), std::string::npos); + EXPECT_NE(result.find(""), + std::string::npos); result = sdf::SDF::EmbeddedSpec("actor.sdf", true); EXPECT_NE(result.find(""), std::string::npos); - EXPECT_NE(result.find(""), std::string::npos); + EXPECT_NE(result.find(""), + std::string::npos); result = sdf::SDF::EmbeddedSpec("root.sdf", false); EXPECT_NE(result.find("SDFormat base element"), std::string::npos); @@ -592,7 +594,8 @@ TEST(SDF, EmbeddedSpecNonExistent) #endif result = sdf::SDF::EmbeddedSpec("unavailable.sdf", false); - EXPECT_NE(stderr_buffer.str().find("Unable to find SDF filename"), std::string::npos); + EXPECT_NE(stderr_buffer.str().find("Unable to find SDF filename"), + std::string::npos); EXPECT_NE(stderr_buffer.str().find("with version"), std::string::npos); EXPECT_TRUE(result.empty()); From 37a40549c603f9e52a34492c3395fb22d92767a3 Mon Sep 17 00:00:00 2001 From: Bi0T1N Date: Sat, 20 Aug 2022 21:50:13 +0200 Subject: [PATCH 10/14] Use multiline strings in combination with cleandoc Signed-off-by: Bi0T1N --- sdf/embedSdf.py | 92 +++++++++++++++++++++++++------------------------ 1 file changed, 47 insertions(+), 45 deletions(-) diff --git a/sdf/embedSdf.py b/sdf/embedSdf.py index ee88342a5..5b7648162 100644 --- a/sdf/embedSdf.py +++ b/sdf/embedSdf.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +import inspect from pathlib import Path, PurePosixPath """"Script for generating a C++ file that contains the content from all SDF files""" @@ -13,7 +14,8 @@ # whitespace indentation for C++ code INDENTATION = ' ' - +# newline character +NEWLINE = '\n' def get_copyright_notice() -> str: """ @@ -21,25 +23,25 @@ def get_copyright_notice() -> str: :returns: copyright notice """ - res = [] - res.append('/*') - res.append(' * Copyright 2022 Open Source Robotics Foundation') - res.append(' *') - res.append(' * Licensed under the Apache License, Version 2.0 (the "License");') - res.append(' * you may not use this file except in compliance with the License.') - res.append(' * You may obtain a copy of the License at') - res.append(' *') - res.append(' * http://www.apache.org/licenses/LICENSE-2.0') - res.append(' *') - res.append(' * Unless required by applicable law or agreed to in writing, software') - res.append(' * distributed under the License is distributed on an "AS IS" BASIS,') - res.append(' * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.') - res.append(' * See the License for the specific language governing permissions and') - res.append(' * limitations under the License.') - res.append(' *') - res.append('*/') - res.append('') - return '\n'.join(res) + res = inspect.cleandoc(""" + /* + * Copyright 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. + * 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. + * + */ + """) + return res + 2*NEWLINE def get_file_header_prolog() -> str: @@ -48,19 +50,19 @@ def get_file_header_prolog() -> str: :returns: prolog of the C++ file """ - res = [] - res.append('#include "EmbeddedSdf.hh"') - res.append('') - res.append('namespace sdf') - res.append('{') - res.append('inline namespace SDF_VERSION_NAMESPACE') - res.append('{') - res.append('/////////////////////////////////////////////////') - res.append('const std::map &GetEmbeddedSdf()') - res.append('{') - res.append(INDENTATION + 'static const std::map result {') - res.append('') - return '\n'.join(res) + res = inspect.cleandoc(""" + #include "EmbeddedSdf.hh" + + namespace sdf + { + inline namespace SDF_VERSION_NAMESPACE + { + ///////////////////////////////////////////////// + const std::map &GetEmbeddedSdf() + { + static const std::map result { + """) + return res + NEWLINE def embed_sdf_content(arg_path: str, arg_file_content: str) -> str: @@ -80,7 +82,7 @@ def embed_sdf_content(arg_path: str, arg_file_content: str) -> str: res.append(')__sdf_literal__"') res.append('},') res.append('') - return '\n'.join(res) + return NEWLINE.join(res) def get_map_content(arg_pathlist: Path) -> str: @@ -112,17 +114,17 @@ def get_file_header_epilog() -> str: :returns: epilog of the C++ file """ - res = [] - res.append('') - res.append(INDENTATION + '};') - res.append('') - res.append(INDENTATION + 'return result;') - res.append('}') - res.append('') - res.append('}') - res.append('} // namespace sdf') - res.append('') - return '\n'.join(res) + res = inspect.cleandoc(""" + }; + + return result; + } + + } + } // namespace sdf + + """) + return NEWLINE + res if __name__ == "__main__": From 26fcd3148f623799b5a703da9abcbe0d742fcbb6 Mon Sep 17 00:00:00 2001 From: Bi0T1N Date: Sat, 20 Aug 2022 21:55:00 +0200 Subject: [PATCH 11/14] Use function argument variable Signed-off-by: Bi0T1N --- sdf/embedSdf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdf/embedSdf.py b/sdf/embedSdf.py index 5b7648162..3e1df5070 100644 --- a/sdf/embedSdf.py +++ b/sdf/embedSdf.py @@ -95,7 +95,7 @@ def get_map_content(arg_pathlist: Path) -> str: """ map_str = '' files = [] - for path in pathlist: + for path in arg_pathlist: # dir separator is hardcoded to '/' in C++ mapping posix_path = PurePosixPath(path) files.append(str(posix_path)) From 25adf7988258135c3de976751fd36a0ca8b4df75 Mon Sep 17 00:00:00 2001 From: Bi0T1N Date: Sat, 20 Aug 2022 22:37:53 +0200 Subject: [PATCH 12/14] Add changes for new SDF version 1.10 Signed-off-by: Bi0T1N --- sdf/embedSdf.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdf/embedSdf.py b/sdf/embedSdf.py index 3e1df5070..b89607fa6 100644 --- a/sdf/embedSdf.py +++ b/sdf/embedSdf.py @@ -6,11 +6,11 @@ # The list of supported SDF specification versions. This will let us drop # versions without removing the directories. -SUPPORTED_SDF_VERSIONS = ['1.9', '1.8', '1.7', '1.6', '1.5', '1.4', '1.3', '1.2'] +SUPPORTED_SDF_VERSIONS = ['1.10', '1.9', '1.8', '1.7', '1.6', '1.5', '1.4', '1.3', '1.2'] # The list of supported SDF conversions. This list includes versions that # a user can convert an existing SDF version to. -SUPPORTED_SDF_CONVERSIONS = ['1.9', '1.8', '1.7', '1.6', '1.5', '1.4', '1.3'] +SUPPORTED_SDF_CONVERSIONS = ['1.10', '1.9', '1.8', '1.7', '1.6', '1.5', '1.4', '1.3'] # whitespace indentation for C++ code INDENTATION = ' ' From faf92e4616e2d46be0ce607b318bcc5ab8dada6d Mon Sep 17 00:00:00 2001 From: Bi0T1N Date: Sat, 20 Aug 2022 22:50:51 +0200 Subject: [PATCH 13/14] Use testing::RedirectConsoleStream to capture errors Signed-off-by: Bi0T1N --- src/SDF_TEST.cc | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/SDF_TEST.cc b/src/SDF_TEST.cc index df5143977..315343e12 100644 --- a/src/SDF_TEST.cc +++ b/src/SDF_TEST.cc @@ -21,6 +21,9 @@ #include #include +#include "test_config.hh" +#include "test_utils.hh" + #include "sdf/sdf.hh" class SDFUpdateFixture @@ -587,10 +590,15 @@ TEST(SDF, EmbeddedSpecNonExistent) // Capture sdferr output std::stringstream stderr_buffer; - auto old = std::cerr.rdbuf(stderr_buffer.rdbuf()); - + sdf::testing::RedirectConsoleStream redir( + sdf::Console::Instance()->GetMsgStream(), &stderr_buffer); #ifdef _WIN32 sdf::Console::Instance()->SetQuiet(false); + sdf::testing::ScopeExit revertSetQuiet( + [] + { + sdf::Console::Instance()->SetQuiet(true); + }); #endif result = sdf::SDF::EmbeddedSpec("unavailable.sdf", false); @@ -605,12 +613,6 @@ TEST(SDF, EmbeddedSpecNonExistent) result = sdf::SDF::EmbeddedSpec("unavailable.sdf", true); EXPECT_TRUE(stderr_buffer.str().empty()); EXPECT_TRUE(result.empty()); - - // Revert cerr rdbuf to not interfere with other tests - std::cerr.rdbuf(old); -#ifdef _WIN32 - sdf::Console::Instance()->SetQuiet(true); -#endif } ///////////////////////////////////////////////// From bbe6714da64b1890f37c21b642d0cd4507928785 Mon Sep 17 00:00:00 2001 From: Bi0T1N Date: Sat, 17 Dec 2022 18:01:08 +0100 Subject: [PATCH 14/14] Make Python a build dependency Signed-off-by: Bi0T1N --- sdf/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sdf/CMakeLists.txt b/sdf/CMakeLists.txt index b3ab2a484..4691138ec 100644 --- a/sdf/CMakeLists.txt +++ b/sdf/CMakeLists.txt @@ -12,6 +12,10 @@ add_subdirectory(1.10) add_custom_target(schema) add_dependencies(schema schema1_10) +if (NOT Python3_Interpreter_FOUND) + gz_build_error("Python is required to generate the C++ file with the SDF content") +endif() + # Generate the EmbeddedSdf.cc file, which contains all the supported SDF # descriptions in a map of strings. The parser.cc file uses EmbeddedSdf.hh. execute_process(