Skip to content

Commit b8122ad

Browse files
uilianriesczoido
andauthored
[tools] Add system package manger with ncurses as example (#177)
* Add system package manger with ncurses Signed-off-by: Uilian Ries <[email protected]> * Add entry for system example in docs Signed-off-by: Uilian Ries <[email protected]> * Add ci script to validate new example Signed-off-by: Uilian Ries <[email protected]> * Use invalid configuration if not linux Signed-off-by: Uilian Ries <[email protected]> * Add consumer application for ncurses Signed-off-by: Uilian Ries <[email protected]> * Execute test only on Linux Signed-off-by: Uilian Ries <[email protected]> * Simplify consumer package Signed-off-by: Uilian Ries <[email protected]> * Add support for Macos Signed-off-by: Uilian Ries <[email protected]> * Add support for FreeBSD Signed-off-by: Uilian Ries <[email protected]> * Elaborate better example using ncurses Signed-off-by: Uilian Ries <[email protected]> * Fix exported source file name Signed-off-by: Uilian Ries <[email protected]> * Avoid interactive command on CI Signed-off-by: Uilian Ries <[email protected]> * Simplify consumer example Signed-off-by: Uilian Ries <[email protected]> * Update documentation url for sys reqs example Signed-off-by: Uilian Ries <[email protected]> * Add support for FreeBSD Signed-off-by: Uilian Ries <[email protected]> * Use official CMake target name for Curses Signed-off-by: Uilian Ries <[email protected]> * Only run consumer example on supported Os Signed-off-by: Uilian Ries <[email protected]> * Update examples/tools/system/package_manager/consumer/conanfile.py Co-authored-by: Carlos Zoido <[email protected]> * Update examples/tools/system/package_manager/consumer/conanfile.py Co-authored-by: Carlos Zoido <[email protected]> * Fix expected curses cmake target name Signed-off-by: Uilian Ries <[email protected]> * Enforce terminfo for CI Signed-off-by: Uilian Ries <[email protected]> * Do not run the example app with build Signed-off-by: Uilian Ries <[email protected]> * Do not run the example app with build - take 2 Signed-off-by: Uilian Ries <[email protected]> --------- Signed-off-by: Uilian Ries <[email protected]> Co-authored-by: Carlos Zoido <[email protected]>
1 parent a1fac4b commit b8122ad

File tree

6 files changed

+149
-0
lines changed

6 files changed

+149
-0
lines changed

examples/tools/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,7 @@
2929

3030
- Build [ROS packages inside their workspace](ros/rosenv/workspace) using the [fmt library from Conan Center](https://conan.io/center/recipes/fmt) and consuming them also as transitive dependencies.
3131
- Build a [ROS navigation package](ros/rosenv/navigation_ws) that sends goals to a mobile robot from a YAML file using the [yaml-cpp library from Conan Center](https://conan.io/center/recipes/yaml-cpp).
32+
33+
### [tools.system](system)
34+
35+
- Wrap a [system package](system/package_manager/) using Conan and [ncurses](https://invisible-island.net/ncurses/). [Docs](https://docs.conan.io/2/examples/tools/system/package_manager.html)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from test.examples_tools import run
2+
import sys
3+
4+
5+
print("- Packaging system ncurses library using Conan -")
6+
7+
if sys.platform != "linux":
8+
print("INFO: Skipping test, only for Linux due to system requirements.")
9+
sys.exit(0)
10+
11+
confs = ["tools.system.package_manager:mode=install",
12+
"tools.system.package_manager:sudo=true",
13+
"tools.build:verbosity=verbose",
14+
"tools.compilation:verbosity=verbose"]
15+
16+
out = run("conan create . {}".format(" ".join(["-c " + conf for conf in confs])))
17+
18+
assert "ncurses/system: System requirements"
19+
assert "package(): WARN: No files in this package" in out
20+
21+
print("- Consuming Conan package ncurses/system -")
22+
23+
out = run("conan build consumer/ --name=ncurses-version --version=0.1.0 {}".format(" ".join(["-c " + conf for conf in confs])))
24+
25+
assert "The example application has been successfully built" in out
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
from conan import ConanFile
2+
from conan.tools.system import package_manager
3+
from conan.tools.gnu import PkgConfig
4+
from conan.errors import ConanInvalidConfiguration
5+
6+
required_conan_version = ">=2.0"
7+
8+
9+
class SysNcursesConan(ConanFile):
10+
name = "ncurses"
11+
version = "system"
12+
description = "A textual user interfaces that work across a wide variety of terminals"
13+
topics = ("curses", "terminal", "toolkit")
14+
homepage = "https://invisible-mirror.net/archives/ncurses/"
15+
license = "MIT"
16+
package_type = "shared-library"
17+
settings = "os", "arch", "compiler", "build_type"
18+
19+
def package_id(self):
20+
self.info.clear()
21+
22+
def validate(self):
23+
supported_os = ["Linux", "Macos", "FreeBSD"]
24+
if self.settings.os not in supported_os:
25+
raise ConanInvalidConfiguration(f"{self.ref} wraps a system package only supported by {supported_os}.")
26+
27+
def system_requirements(self):
28+
dnf = package_manager.Dnf(self)
29+
dnf.install(["ncurses-devel"], update=True, check=True)
30+
31+
yum = package_manager.Yum(self)
32+
yum.install(["ncurses-devel"], update=True, check=True)
33+
34+
apt = package_manager.Apt(self)
35+
apt.install(["libncurses-dev"], update=True, check=True)
36+
37+
pacman = package_manager.PacMan(self)
38+
pacman.install(["ncurses"], update=True, check=True)
39+
40+
zypper = package_manager.Zypper(self)
41+
zypper.install(["ncurses"], update=True, check=True)
42+
43+
brew = package_manager.Brew(self)
44+
brew.install(["ncurses"], update=True, check=True)
45+
46+
pkg = package_manager.Pkg(self)
47+
pkg.install(["ncurses"], update=True, check=True)
48+
49+
def package_info(self):
50+
self.cpp_info.bindirs = []
51+
self.cpp_info.includedirs = []
52+
self.cpp_info.libdirs = []
53+
54+
self.cpp_info.set_property("cmake_file_name", "Curses")
55+
self.cpp_info.set_property("cmake_target_name", "Curses::Curses")
56+
self.cpp_info.set_property("cmake_additional_variables_prefixes", ["CURSES",])
57+
58+
pkg_config = PkgConfig(self, 'ncurses')
59+
pkg_config.fill_cpp_info(self.cpp_info, is_system=True)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
cmake_minimum_required(VERSION 3.15)
2+
project(ncurses_version C)
3+
4+
find_package(Curses CONFIG REQUIRED)
5+
6+
add_executable(${PROJECT_NAME} ncurses_version.c)
7+
target_link_libraries(${PROJECT_NAME} PRIVATE Curses::Curses)
8+
9+
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from conan import ConanFile
2+
from conan.tools.build import can_run
3+
from conan.tools.cmake import cmake_layout, CMake
4+
import os
5+
6+
7+
class AppNCursesVersionConan(ConanFile):
8+
settings = "os", "compiler", "build_type", "arch"
9+
generators = "CMakeDeps", "CMakeToolchain"
10+
package_type = "application"
11+
exports_sources = "CMakeLists.txt", "ncurses_version.c"
12+
13+
def requirements(self):
14+
if self.settings.os in ["Linux", "Macos", "FreeBSD"]:
15+
self.requires("ncurses/system")
16+
17+
def layout(self):
18+
cmake_layout(self)
19+
20+
def build(self):
21+
cmake = CMake(self)
22+
cmake.configure()
23+
cmake.build()
24+
25+
app_path = os.path.join(self.build_folder, "ncurses_version")
26+
self.output.info(f"The example application has been successfully built.\nPlease run the executable using: '{app_path}'")
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <stdlib.h>
2+
#include <stdio.h>
3+
#include <string.h>
4+
5+
#include <ncurses.h>
6+
7+
8+
int main(void) {
9+
int max_y, max_x;
10+
char message [256] = {0};
11+
12+
initscr();
13+
14+
start_color();
15+
init_pair(1, COLOR_BLUE, COLOR_WHITE);
16+
getmaxyx(stdscr, max_y, max_x);
17+
18+
snprintf(message, sizeof(message), "Conan 2.x Examples - Installed ncurses version: %s\n", curses_version());
19+
attron(COLOR_PAIR(1));
20+
mvprintw(max_y / 2, max_x / 2 - (strlen(message) / 2), "%s", message);
21+
attroff(COLOR_PAIR(1));
22+
23+
refresh();
24+
25+
return EXIT_SUCCESS;
26+
}

0 commit comments

Comments
 (0)