Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use semantic version and prevent crash if version is missing #151

Merged
merged 2 commits into from
Jan 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/ci/packages.apt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ libcurl4-openssl-dev
libgflags-dev
libignition-cmake2-dev
libignition-common3-dev
libignition-math6-dev
libignition-msgs5-dev
libignition-tools-dev
libjsoncpp-dev
Expand Down
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ ign_find_package(ZIP REQUIRED PRIVATE)
ign_find_package(ignition-common3 REQUIRED PRIVATE)
set(IGN_COMMON_MAJOR_VER ${ignition-common3_VERSION_MAJOR})

#--------------------------------------
# Find ignition-math
ign_find_package(ignition-math6 REQUIRED PRIVATE)
set(IGN_MSGS_MAJOR_VER ${ignition-math6_VERSION_MAJOR})

#--------------------------------------
# Find ignition-msgs
ign_find_package(ignition-msgs5 REQUIRED PRIVATE)
Expand Down
18 changes: 16 additions & 2 deletions src/LocalCache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <ignition/common/Filesystem.hh>
#include <ignition/common/StringUtils.hh>
#include <ignition/common/Util.hh>
#include <ignition/math/SemanticVersion.hh>

#include "ignition/fuel_tools/ClientConfig.hh"
#include "ignition/fuel_tools/LocalCache.hh"
Expand Down Expand Up @@ -459,11 +460,24 @@ bool LocalCachePrivate::FixPaths(const std::string &_modelVersionedDir,

// Get the <sdf> element with the highest (most recent) version.
tinyxml2::XMLElement *sdfElementLatest = nullptr;
double maxVersion = 0.0;
math::SemanticVersion maxVersion{"0.0"};
tinyxml2::XMLElement *sdfElement = modelElement->FirstChildElement("sdf");
while (sdfElement)
{
double version = std::stod(sdfElement->Attribute("version"));
math::SemanticVersion version;

auto versionAttribute = sdfElement->Attribute("version");
if (nullptr == versionAttribute)
{
version.Parse("0.0.1");
ignwarn << "<sdf> element missing version attribute, assuming version ["
<< version << "]" << std::endl;
}
else
{
version.Parse(versionAttribute);
}

if (version > maxVersion)
{
maxVersion = version;
Expand Down