-
Notifications
You must be signed in to change notification settings - Fork 64
[tools] Add system package manger with ncurses as example #177
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
Merged
Merged
Changes from 17 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
d92cc05
Add system package manger with ncurses
uilianries db363a0
Add entry for system example in docs
uilianries 577947b
Add ci script to validate new example
uilianries 1588288
Use invalid configuration if not linux
uilianries 3874e44
Add consumer application for ncurses
uilianries 249976d
Execute test only on Linux
uilianries fef2c93
Simplify consumer package
uilianries b130314
Add support for Macos
uilianries 8818e19
Add support for FreeBSD
uilianries f4dcb75
Elaborate better example using ncurses
uilianries 4326fc1
Fix exported source file name
uilianries 950af44
Avoid interactive command on CI
uilianries 668cbbd
Simplify consumer example
uilianries ecf1d3f
Update documentation url for sys reqs example
uilianries c9325e2
Add support for FreeBSD
uilianries e8e45a2
Use official CMake target name for Curses
uilianries 8969488
Only run consumer example on supported Os
uilianries 774b34c
Update examples/tools/system/package_manager/consumer/conanfile.py
uilianries c1d6595
Update examples/tools/system/package_manager/consumer/conanfile.py
uilianries 1e9d1d0
Fix expected curses cmake target name
uilianries 46a4e24
Enforce terminfo for CI
uilianries e3607c1
Do not run the example app with build
uilianries 240f393
Do not run the example app with build - take 2
uilianries File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| from test.examples_tools import run | ||
| import re | ||
| import os | ||
| import sys | ||
|
|
||
|
|
||
| print("- Packaging system ncurses library using Conan -") | ||
|
|
||
| if sys.platform != "linux": | ||
| print("INFO: Skipping test, only for Linux due to system requirements.") | ||
| sys.exit(0) | ||
|
|
||
| confs = ["tools.system.package_manager:mode=install", | ||
| "tools.system.package_manager:sudo=true", | ||
| "tools.build:verbosity=verbose", | ||
| "tools.compilation:verbosity=verbose"] | ||
|
|
||
| out = run("conan create . {}".format(" ".join(["-c " + conf for conf in confs]))) | ||
|
|
||
| assert "ncurses/system: System requirements" | ||
| assert "package(): WARN: No files in this package" in out | ||
|
|
||
| print("- Consuming Conan package ncurses/system -") | ||
|
|
||
| out = run("conan build consumer/ --name=ncurses-version --version=0.1.0 {}".format(" ".join(["-c " + conf for conf in confs]))) | ||
|
|
||
| assert "Conan: Target declared 'ncurses::ncurses'" in out |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| from conan import ConanFile | ||
| from conan.tools.system import package_manager | ||
| from conan.tools.gnu import PkgConfig | ||
| from conan.errors import ConanInvalidConfiguration | ||
|
|
||
| required_conan_version = ">=2.0" | ||
|
|
||
|
|
||
| class SysNcursesConan(ConanFile): | ||
| name = "ncurses" | ||
| version = "system" | ||
| description = "A textual user interfaces that work across a wide variety of terminals" | ||
| topics = ("curses", "terminal", "toolkit") | ||
| homepage = "https://invisible-mirror.net/archives/ncurses/" | ||
| license = "MIT" | ||
| package_type = "shared-library" | ||
| settings = "os", "arch", "compiler", "build_type" | ||
|
|
||
| def package_id(self): | ||
| self.info.clear() | ||
|
|
||
| def validate(self): | ||
| supported_os = ["Linux", "Macos", "FreeBSD"] | ||
| if self.settings.os not in supported_os: | ||
| raise ConanInvalidConfiguration(f"{self.ref} wraps a system package only supported by {supported_os}.") | ||
|
|
||
| def system_requirements(self): | ||
| dnf = package_manager.Dnf(self) | ||
| dnf.install(["ncurses-devel"], update=True, check=True) | ||
|
|
||
| yum = package_manager.Yum(self) | ||
| yum.install(["ncurses-devel"], update=True, check=True) | ||
|
|
||
| apt = package_manager.Apt(self) | ||
| apt.install(["libncurses-dev"], update=True, check=True) | ||
|
|
||
| pacman = package_manager.PacMan(self) | ||
| pacman.install(["ncurses"], update=True, check=True) | ||
|
|
||
| zypper = package_manager.Zypper(self) | ||
| zypper.install(["ncurses"], update=True, check=True) | ||
|
|
||
| brew = package_manager.Brew(self) | ||
| brew.install(["ncurses"], update=True, check=True) | ||
|
|
||
| pkg = package_manager.Pkg(self) | ||
| pkg.install(["ncurses"], update=True, check=True) | ||
|
|
||
| def package_info(self): | ||
| self.cpp_info.bindirs = [] | ||
| self.cpp_info.includedirs = [] | ||
| self.cpp_info.libdirs = [] | ||
|
|
||
| self.cpp_info.set_property("cmake_file_name", "Curses") | ||
| self.cpp_info.set_property("cmake_target_name", "Curses::Curses") | ||
| self.cpp_info.set_property("cmake_additional_variables_prefixes", ["CURSES",]) | ||
|
|
||
| pkg_config = PkgConfig(self, 'ncurses') | ||
| pkg_config.fill_cpp_info(self.cpp_info, is_system=True) |
9 changes: 9 additions & 0 deletions
9
examples/tools/system/package_manager/consumer/CMakeLists.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| cmake_minimum_required(VERSION 3.15) | ||
| project(ncurses_version C) | ||
|
|
||
| find_package(Curses CONFIG REQUIRED) | ||
|
|
||
| add_executable(${PROJECT_NAME} ncurses_version.c) | ||
| target_link_libraries(${PROJECT_NAME} PRIVATE Curses::Curses) | ||
|
|
||
| install(TARGETS ${PROJECT_NAME} DESTINATION bin) |
30 changes: 30 additions & 0 deletions
30
examples/tools/system/package_manager/consumer/conanfile.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| from conan import ConanFile | ||
| from conan.tools.build import can_run | ||
| from conan.tools.cmake import cmake_layout, CMake | ||
| import os | ||
|
|
||
|
|
||
| class AppNCursesVersionConan(ConanFile): | ||
| settings = "os", "compiler", "build_type", "arch" | ||
| generators = "CMakeDeps", "CMakeToolchain" | ||
| package_type = "application" | ||
| exports_sources = "CMakeLists.txt", "ncurses_version.c" | ||
|
|
||
| @property | ||
| def _supported_os(self): | ||
| return ["Linux", "Macos", "FreeBSD"] | ||
|
|
||
| def requirements(self): | ||
| if self.settings.os in _supported_os: | ||
| self.requires("ncurses/system") | ||
|
|
||
| def layout(self): | ||
| cmake_layout(self) | ||
|
|
||
| def build(self): | ||
| cmake = CMake(self) | ||
| cmake.configure() | ||
| cmake.build() | ||
|
|
||
| if self.settings.os in _supported_os: | ||
uilianries marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| self.run(os.path.join(self.build_folder, "ncurses_version"), env="conanrun") | ||
26 changes: 26 additions & 0 deletions
26
examples/tools/system/package_manager/consumer/ncurses_version.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| #include <stdlib.h> | ||
| #include <stdio.h> | ||
| #include <string.h> | ||
|
|
||
| #include <ncurses.h> | ||
|
|
||
|
|
||
| int main(void) { | ||
| int max_y, max_x; | ||
| char message [256] = {0}; | ||
|
|
||
| initscr(); | ||
|
|
||
| start_color(); | ||
| init_pair(1, COLOR_BLUE, COLOR_WHITE); | ||
| getmaxyx(stdscr, max_y, max_x); | ||
|
|
||
| snprintf(message, sizeof(message), "Conan 2.x Examples - Installed ncurses version: %s\n", curses_version()); | ||
| attron(COLOR_PAIR(1)); | ||
| mvprintw(max_y / 2, max_x / 2 - (strlen(message) / 2), "%s", message); | ||
| attroff(COLOR_PAIR(1)); | ||
|
|
||
| refresh(); | ||
|
|
||
| return EXIT_SUCCESS; | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.