Skip to content

Commit

Permalink
Use semantic version and prevent crash if version is missing (#151)
Browse files Browse the repository at this point in the history
Also explicitly depend on ign-math6

Signed-off-by: Louise Poubel <louise@openrobotics.org>
  • Loading branch information
chapulina authored Jan 4, 2021
1 parent 696bf7b commit 99e0bcb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
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

0 comments on commit 99e0bcb

Please sign in to comment.