Skip to content

Commit

Permalink
feat: add autoware_version_manager package
Browse files Browse the repository at this point in the history
Signed-off-by: M. Fatih Cırıt <mfc@leodrive.ai>
  • Loading branch information
M. Fatih Cırıt committed Jul 14, 2023
1 parent 9989140 commit 85490dc
Show file tree
Hide file tree
Showing 11 changed files with 303 additions and 0 deletions.
23 changes: 23 additions & 0 deletions autoware_version_manager/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
cmake_minimum_required(VERSION 3.14)
project(autoware_version_manager)

find_package(autoware_cmake REQUIRED)
autoware_package()

set(NODE_NAME ${PROJECT_NAME}_node)
set(EXEC_NAME ${PROJECT_NAME}_exe)

ament_auto_add_library(${NODE_NAME}
src/include/autoware_version_manager_core.hpp
src/include/parse_version.hpp
src/include/version_types.hpp
src/autoware_version_manager_core.cpp
src/parse_version.cpp)

rclcpp_components_register_node(${NODE_NAME}
PLUGIN "autoware_version_manager::AutowareVersionManagerNode"
EXECUTABLE ${EXEC_NAME})

ament_auto_package(INSTALL_TO_SHARE
launch
data)
1 change: 1 addition & 0 deletions autoware_version_manager/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# autoware_version_manager
5 changes: 5 additions & 0 deletions autoware_version_manager/data/version-autoware.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Autoware version (CalVer with YYYY.MINOR.MICRO)

year: 2023
minor: 7
micro: 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Autoware component interface version (SemVer)

major: 1
minor: 0
patch: 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<launch>
<arg name="path_version_autoware" default="$(find-pkg-share autoware_version_manager)/data/version-autoware.yaml"/>
<arg name="path_version_component_interface" default="$(find-pkg-share autoware_version_manager)/data/version-component-interface.yaml"/>


<node pkg="autoware_version_manager" exec="autoware_version_manager_exe" name="autoware_version_manager" output="screen">
<param name="path_version_autoware" value="$(var path_version_autoware)"/>
<param name="path_version_component_interface" value="$(var path_version_component_interface)"/>
</node>
</launch>
29 changes: 29 additions & 0 deletions autoware_version_manager/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0"?>
<package format="2">
<name>autoware_version_manager</name>
<version>0.0.0</version>
<description>The autoware_version_manager package</description>

<maintainer email="mfc@leodrive.ai">M. Fatih Cırıt</maintainer>
<maintainer email="isamu.takagi@tier4.jp">Takagi, Isamu</maintainer>

<license>Apache License 2.0</license>

<author email="mfc@leodrive.ai">M. Fatih Cırıt</author>

<buildtool_depend>ament_cmake_auto</buildtool_depend>
<buildtool_depend>autoware_cmake</buildtool_depend>

<depend>autoware_system_msgs</depend>
<depend>rclcpp</depend>
<depend>rclcpp_components</depend>
<depend>yaml_cpp_vendor</depend>

<test_depend>ament_cmake_ros</test_depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>autoware_lint_common</test_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
54 changes: 54 additions & 0 deletions autoware_version_manager/src/autoware_version_manager_core.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2023 The Autoware 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/autoware_version_manager_core.hpp"

#include "include/parse_version.hpp"
#include "include/version_types.hpp"

#include <rclcpp/rclcpp.hpp>

namespace autoware_version_manager
{

AutowareVersionManagerNode::AutowareVersionManagerNode(const rclcpp::NodeOptions & node_options)
: rclcpp::Node("autoware_version_manager_node", node_options)
{
const std::filesystem::path path_version_autoware =
declare_parameter<std::string>("path_version_autoware");
const std::filesystem::path path_version_component_interface =
declare_parameter<std::string>("path_version_component_interface");

try {
version_autoware_ = parse_version::parse_autoware_version(path_version_autoware);
version_component_interface_ =
parse_version::parse_interface_version(path_version_component_interface);
} catch (const std::exception & e) {
RCLCPP_ERROR(get_logger(), "Failed to parse version: %s", e.what());
exit(EXIT_FAILURE);
}

// print
RCLCPP_INFO(
get_logger(), "Autoware version: %d.%d.%d", version_autoware_.year, version_autoware_.minor,
version_autoware_.micro);
RCLCPP_INFO(
get_logger(), "Component interface version: %d.%d.%d", version_component_interface_.major,
version_component_interface_.minor, version_component_interface_.patch);
}

} // namespace autoware_version_manager

#include <rclcpp_components/register_node_macro.hpp>
RCLCPP_COMPONENTS_REGISTER_NODE(autoware_version_manager::AutowareVersionManagerNode)
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2023 The Autoware 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 AUTOWARE_VERSION_MANAGER_CORE_HPP_
#define AUTOWARE_VERSION_MANAGER_CORE_HPP_

#include "version_types.hpp"

#include <rclcpp/rclcpp.hpp>

#include <autoware_system_msgs/srv/get_version.hpp>

namespace autoware_version_manager
{
class AutowareVersionManagerNode : public rclcpp::Node
{
public:
explicit AutowareVersionManagerNode(const rclcpp::NodeOptions & node_options);

private:
VersionAutoware version_autoware_;
VersionInterface version_component_interface_;
};

} // namespace autoware_version_manager

#endif // AUTOWARE_VERSION_MANAGER_CORE_HPP_
38 changes: 38 additions & 0 deletions autoware_version_manager/src/include/parse_version.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2023 The Autoware 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 PARSE_VERSION_HPP_
#define PARSE_VERSION_HPP_

#include "version_types.hpp"

#include <yaml-cpp/yaml.h>

#include <filesystem>

namespace autoware_version_manager
{
namespace parse_version
{

VersionAutoware parse_autoware_version(const YAML::Node & yaml_node);
VersionAutoware parse_autoware_version(const std::filesystem::path & path);

VersionInterface parse_interface_version(const YAML::Node & yaml_node);
VersionInterface parse_interface_version(const std::filesystem::path & path);

} // namespace parse_version
} // namespace autoware_version_manager

#endif // PARSE_VERSION_HPP_
40 changes: 40 additions & 0 deletions autoware_version_manager/src/include/version_types.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2023 The Autoware 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 VERSION_TYPES_HPP_
#define VERSION_TYPES_HPP_

namespace autoware_version_manager
{
// Autoware version (CalVer with YYYY.MINOR.MICRO)
// https://calver.org/#scheme
struct VersionAutoware
{
int year; // year of release
int minor; // increments for non-breaking changes
int micro; // increments for bug fixes or patches
};

// Autoware component interface version (SemVer)
// https://semver.org/
struct VersionInterface
{
int major; // increments for breaking changes
int minor; // increments for non-breaking changes
int patch; // increments for bug fixes or patches
};

} // namespace autoware_version_manager

#endif // VERSION_TYPES_HPP_
59 changes: 59 additions & 0 deletions autoware_version_manager/src/parse_version.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2023 The Autoware 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/parse_version.hpp"

#include "include/version_types.hpp"

#include <yaml-cpp/yaml.h>

#include <filesystem>

namespace autoware_version_manager
{
namespace parse_version
{

VersionAutoware parse_autoware_version(const YAML::Node & yaml_node)
{
VersionAutoware version;
version.year = yaml_node["year"].as<int>();
version.minor = yaml_node["minor"].as<int>();
version.micro = yaml_node["micro"].as<int>();
return version;
}

VersionAutoware parse_autoware_version(const std::filesystem::path & path)
{
YAML::Node yaml_node = YAML::LoadFile(path.string());
return parse_autoware_version(yaml_node);
}

VersionInterface parse_interface_version(const YAML::Node & yaml_node)
{
VersionInterface version;
version.major = yaml_node["major"].as<int>();
version.minor = yaml_node["minor"].as<int>();
version.patch = yaml_node["patch"].as<int>();
return version;
}

VersionInterface parse_interface_version(const std::filesystem::path & path)
{
YAML::Node yaml_node = YAML::LoadFile(path.string());
return parse_interface_version(yaml_node);
}

} // namespace parse_version
} // namespace autoware_version_manager

0 comments on commit 85490dc

Please sign in to comment.