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

Add HFSM2 Recipe #22647

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
7 changes: 7 additions & 0 deletions recipes/hfsm2/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
sources:
"2.5.0":
url: "https://github.com/andrew-gresyk/HFSM2/archive/refs/tags/2.5.0.zip"
sha256: "e295f8bccacc9d40eb04f08414e5abe623913453bad1d2b5b70210bf8080b309"
"2.4.0":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do need both versions? Otherwise, I would ask adding only the latest to save the CI. In case someone asks 2.4.0, so no problem, we add it later.

url: "https://github.com/andrew-gresyk/HFSM2/archive/refs/tags/2.4.0.zip"
sha256: "d9863aa7cd0ff1ba2c451dcb256e1275c6e6e6619c3809ef92da831493e2b7ca"
44 changes: 44 additions & 0 deletions recipes/hfsm2/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import os

from conan import ConanFile
from conan.tools.files import copy
from conan.tools.build import check_min_cppstd
from conan.tools.layout import basic_layout
from conan.tools.files import get

required_conan_version = ">=2.0.16"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
required_conan_version = ">=2.0.16"
required_conan_version = ">=1.54.0"

Conan 1.x support is still mandatory in CCI.


class Hfsm2Conan(ConanFile):
name = "hfsm2"
description = "High-Performance Hierarchical Finite State Machine Framework"
license = "MIT"
topics = ("embedded", "fsm", "state-machine", "cpp" "modern-cpp", "game-development",

Check warning on line 15 in recipes/hfsm2/all/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Implicit string concatenation found in tuple
"cpp11", "embedded-systems", "template-metaprogramming", "header-only",
"mit-license", "fsm-library", "hierarchical-state-machine", "game-dev", "hfsm")
homepage = "https://hfsm.dev/"
url = "https://github.com/conan-io/conan-center-index"

package_type = "header-library"
exports_sources = "include/*"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
exports_sources = "include/*"

That's only required when export from source, which means, both recipe and source are the same repository. As example: https://docs.conan.io/2/tutorial/developing_packages/local_package_development_flow.html

settings = "os", "arch", "compiler", "build_type"
no_copy_source = True

def layout(self):
basic_layout(self, src_folder="src")

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, 11)

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def package(self):
# This will also copy the "include" folder
copy(self, os.path.join(self.exports_sources, "*.hpp"), self.source_folder, self.package_folder)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# This will also copy the "include" folder
copy(self, os.path.join(self.exports_sources, "*.hpp"), self.source_folder, self.package_folder)
copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses"))
copy(self, "*.hpp", self.source_folder, self.package_folder)
  • The license must be copied to the licenses folder. The CI will send an error in case missing
  • The first after of copy is reserved to pattern only. Try to keep it simple.


def package_info(self):
# For header-only packages, libdirs and bindirs are not used
# so it's necessary to set those as empty.
self.cpp_info.bindirs = []
self.cpp_info.libdirs = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# For header-only packages, libdirs and bindirs are not used
# so it's necessary to set those as empty.
self.cpp_info.bindirs = []
self.cpp_info.libdirs = []
self.cpp_info.bindirs = []
self.cpp_info.libdirs = []

Please, add an empty line to avoid future errors with git diff. Plus, template comments are not really needed.

8 changes: 8 additions & 0 deletions recipes/hfsm2/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(PackageTest CXX)

find_package(hfsm2 REQUIRED CONFIG)

add_executable(example example.cpp)
target_link_libraries(example PRIVATE hfsm2::hfsm2)
set_property(TARGET example PROPERTY CXX_STANDARD 11)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
set_property(TARGET example PROPERTY CXX_STANDARD 11)
set_property(TARGET example PROPERTY CXX_STANDARD 11)

Missing empty EOL. To the CI, it's an error.

26 changes: 26 additions & 0 deletions recipes/hfsm2/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "example")
self.run(bin_path, env="conanrun")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.run(bin_path, env="conanrun")
self.run(bin_path, env="conanrun")

Missing empty EOL. To the CI, it's an error.

45 changes: 45 additions & 0 deletions recipes/hfsm2/all/test_package/example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <assert.h>
#include <hfsm2/machine.hpp>

struct Context {
bool on = false;
};

using Config = hfsm2::Config
::ContextT<Context&>;

using M = hfsm2::MachineT<Config>;

using FSM = M::PeerRoot<
struct Off,
struct On
>;

struct Off
: FSM::State
{
void enter(PlanControl& control) {
control.context().on = false;
}
};

struct On
: FSM::State
{
void enter(PlanControl& control) {
control.context().on = true;
}
};

int
main() {
Context context;
FSM::Instance machine{context};

machine.changeTo<On>();
machine.update();

assert(context.on == true);

return 0;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
}

Missing empty EOL. To the CI, it's an error.

5 changes: 5 additions & 0 deletions recipes/hfsm2/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
versions:
"2.5.0":
folder: all
"2.4.0":
folder: all
Loading