Skip to content

watcher-c: add new recipe #25574

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

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions recipes/watcher-c/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sources:
"0.13.1":
url: "https://github.com/e-dant/watcher/archive/release/0.13.1.tar.gz"
sha256: "2d8d07fec990c709dda9089f309691238c0af816ab29d7ff87ec13d738943258"
patches:
"0.13.1":
- patch_file: "patches/0.13.1-0001-disable-test.patch"
patch_description: "disable test and python binding"
patch_type: "conan"
115 changes: 115 additions & 0 deletions recipes/watcher-c/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.apple import fix_apple_shared_install_name
from conan.tools.build import check_min_cppstd, stdcpp_library
from conan.tools.env import VirtualBuildEnv
from conan.tools.files import copy, get, export_conandata_patches, apply_conandata_patches, rename
from conan.tools.layout import basic_layout
from conan.tools.meson import Meson, MesonToolchain
from conan.tools.scm import Version
from conan.tools.apple import is_apple_os
from conan.tools.microsoft import is_msvc
import os

required_conan_version = ">=1.53.0"

class WatcherCConan(ConanFile):
name = "watcher-c"
description = "Using the watcher library from C"
license = "MIT"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/e-dant/watcher"
topics = ("watch", "filesystem", "event")
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}

@property
def _min_cppstd(self):
return 17

@property
def _compilers_minimum_version(self):
return {
"gcc": "8",
"clang": "7",
"apple-clang": "12",
"Visual Studio": "16",
"msvc": "192",
}

def export_sources(self):
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if is_msvc(self):
del self.options.shared
self.package_type = "static-library"
if self.options.get_safe("shared"):
self.options.rm_safe("fPIC")

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

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, self._min_cppstd)
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if minimum_version and Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(
f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support."
)

def build_requirements(self):
self.tool_requires("meson/[>=1.2.3 <2]")
if not self.conf.get("tools.gnu:pkg_config", default=False, check_type=str):
self.tool_requires("pkgconf/[>=2.2 <3]")

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

def generate(self):
tc = MesonToolchain(self)
if "shared" not in self.options:
tc.project_options["default_library"] = "static"
tc.generate()
tc = VirtualBuildEnv(self)
tc.generate()

def build(self):
apply_conandata_patches(self)
meson = Meson(self)
meson.configure()
meson.build()

def package(self):
copy(self, "license", self.source_folder, os.path.join(self.package_folder, "licenses"))
meson = Meson(self)
meson.install()

fix_apple_shared_install_name(self)

if is_msvc(self):
rename(self, os.path.join(self.package_folder, "lib", "libwatcher-c.a"), os.path.join(self.package_folder, "lib", "watcher-c.lib"))

def package_info(self):
self.cpp_info.libs = ["watcher-c"]
if not self.options.get_safe("shared", False):
libcxx = stdcpp_library(self)
if libcxx:
self.cpp_info.system_libs.append(libcxx)
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.extend(["m", "pthread"])
if is_apple_os(self):
self.cpp_info.frameworks = ["CoreFoundation", "CoreServices"]
38 changes: 38 additions & 0 deletions recipes/watcher-c/all/patches/0.13.1-0001-disable-test.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
diff --git a/meson.build b/meson.build
index a1ff4c6..caecc5f 100644
--- a/meson.build
+++ b/meson.build
@@ -5,4 +5,4 @@ project(
default_options : ['c_std=c99', 'cpp_std=c++17'],
)
subdir('watcher-c')
-subdir('watcher-py')
+# subdir('watcher-py')
diff --git a/watcher-c/meson.build b/watcher-c/meson.build
index 38aa9c5..6af98e3 100644
--- a/watcher-c/meson.build
+++ b/watcher-c/meson.build
@@ -32,14 +32,14 @@ libwatcher_c = library(
version : meson.project_version(),
)

-test_libwatcher_c = executable(
- 'test-watcher-c',
- ['src/test-watcher-c.c'],
- include_directories : ['include'],
- link_with : [libwatcher_c],
- build_rpath : '/usr/local/lib',
- install_rpath : '/usr/local/lib',
- install : false,
-)
+# test_libwatcher_c = executable(
+# 'test-watcher-c',
+# ['src/test-watcher-c.c'],
+# include_directories : ['include'],
+# link_with : [libwatcher_c],
+# build_rpath : '/usr/local/lib',
+# install_rpath : '/usr/local/lib',
+# install : false,
+# )

subdir('include')
32 changes: 32 additions & 0 deletions recipes/watcher-c/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.layout import basic_layout
from conan.tools.meson import Meson
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "PkgConfigDeps", "MesonToolchain", "VirtualRunEnv", "VirtualBuildEnv"
test_type = "explicit"

def layout(self):
basic_layout(self)

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

def build_requirements(self):
self.tool_requires("meson/[>=1.2.3 <2]")
if not self.conf.get("tools.gnu:pkg_config", default=False, check_type=str):
self.tool_requires("pkgconf/[>=2.2 <3]")

def build(self):
meson = Meson(self)
meson.configure()
meson.build()

def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")
5 changes: 5 additions & 0 deletions recipes/watcher-c/all/test_package/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
project('test_package', 'c')
package_dep = dependency('watcher-c')
executable('test_package',
sources : ['test_package.c'],
dependencies : [package_dep])
19 changes: 19 additions & 0 deletions recipes/watcher-c/all/test_package/test_package.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "wtr/watcher-c.h"
#include <stdio.h>

void callback(struct wtr_watcher_event event, void* _ctx) {
printf(
"path name: %s, effect type: %d path type: %d, effect time: %ld, associated path name: %s\n",
event.path_name,
event.effect_type,
event.path_type,
event.effect_time,
event.associated_path_name ? event.associated_path_name : ""
);
}

int main() {
void* watcher = wtr_watcher_open(".", callback, NULL);
wtr_watcher_close(watcher);
return 0;
}
3 changes: 3 additions & 0 deletions recipes/watcher-c/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"0.13.1":
folder: all