-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
USD -> SDF: Added cmd line tool (#862)
Signed-off-by: ahcorde <ahcorde@gmail.com> Co-authored-by: Ashton Larkin <42042756+adlarkin@users.noreply.github.com>
- Loading branch information
Showing
4 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* 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. | ||
* 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 <iostream> | ||
#include <string> | ||
|
||
#include <ignition/utils/cli/CLI.hpp> | ||
|
||
#include "sdf/config.hh" | ||
|
||
////////////////////////////////////////////////// | ||
/// \brief Enumeration of available commands | ||
enum class Command | ||
{ | ||
kNone, | ||
}; | ||
|
||
////////////////////////////////////////////////// | ||
/// \brief Structure to hold all filenames | ||
struct Options | ||
{ | ||
/// \brief Command to execute | ||
Command command{Command::kNone}; | ||
|
||
/// \brief input filename | ||
std::string inputFilename{"input.usd"}; | ||
|
||
/// \brief output filename | ||
std::string outputFilename{"output.sdf"}; | ||
}; | ||
|
||
void runCommand(const Options &/*_opt*/) | ||
{ | ||
// TODO(ahcorde): Call here the USD to SDF converter code | ||
std::cerr << "USD to SDF conversion is not implemented yet.\n"; | ||
} | ||
|
||
void addFlags(CLI::App &_app) | ||
{ | ||
auto opt = std::make_shared<Options>(); | ||
|
||
_app.add_option("input", | ||
opt->inputFilename, | ||
"Input filename. Defaults to input.usd unless otherwise specified."); | ||
|
||
_app.add_option("output", | ||
opt->outputFilename, | ||
"Output filename. Defaults to output.sdf unless otherwise specified."); | ||
|
||
_app.callback([&_app, opt](){ | ||
runCommand(*opt); | ||
}); | ||
} | ||
|
||
////////////////////////////////////////////////// | ||
int main(int argc, char** argv) | ||
{ | ||
CLI::App app{"USD to SDF converter"}; | ||
|
||
app.set_help_all_flag("--help-all", "Show all help"); | ||
|
||
app.add_flag_callback("--version", [](){ | ||
std::cout << SDF_VERSION_FULL << std::endl; | ||
throw CLI::Success(); | ||
}); | ||
|
||
addFlags(app); | ||
CLI11_PARSE(app, argc, argv); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* 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. | ||
* 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 <string> | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include <ignition/common/Filesystem.hh> | ||
#include <ignition/utilities/ExtraTestMacros.hh> | ||
|
||
#include "test_config.h" | ||
#include "test_utils.hh" | ||
|
||
#ifdef _WIN32 | ||
#define popen _popen | ||
#define pclose _pclose | ||
#endif | ||
|
||
static std::string usd2sdfCommand() | ||
{ | ||
return ignition::common::joinPaths(std::string(PROJECT_BINARY_DIR), "bin", | ||
"usd2sdf"); | ||
} | ||
|
||
///////////////////////////////////////////////// | ||
std::string custom_exec_str(std::string _cmd) | ||
{ | ||
_cmd += " 2>&1"; | ||
FILE *pipe = popen(_cmd.c_str(), "r"); | ||
|
||
if (!pipe) | ||
return "ERROR"; | ||
|
||
char buffer[128]; | ||
std::string result = ""; | ||
|
||
while (!feof(pipe)) | ||
{ | ||
if (fgets(buffer, 128, pipe) != NULL) | ||
result += buffer; | ||
} | ||
|
||
pclose(pipe); | ||
return result; | ||
} | ||
|
||
///////////////////////////////////////////////// | ||
TEST(version_cmd, IGN_UTILS_TEST_DISABLED_ON_WIN32(SDF)) | ||
{ | ||
// Check a good SDF file | ||
{ | ||
std::string output = | ||
custom_exec_str(usd2sdfCommand() + " --version"); | ||
|
||
EXPECT_EQ(output, std::string(SDF_VERSION_FULL) + "\n"); | ||
|
||
// TODO(ahcorde): Check the contents of outputUsdFilePath when the parser | ||
// is implemented | ||
} | ||
} |