-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add safeclib/3.6.0 * Use tools.remove_files_by_mask * Use libsafec for alignment with existing distribution packages * Fail test_package if not working constraint handler * Fix licenses * Remove "make check" due to build complaints for test sources * Strip too explicit version from resulting library file name * Limit recipe GCC version to >= 5 * Update recipes/libsafec/all/conanfile.py Co-authored-by: Chris Mc <prince.chrismc@gmail.com> * Disable Werror to allow warnings * Avoid extra patching, use version in the library name * Fix exported includedirs to match original pkg-config package * Update recipes/libsafec/all/test_package/conanfile.py Co-authored-by: Yoann Potinet <intelligide@hotmail.fr> * Update recipes/libsafec/all/conanfile.py Co-authored-by: Anonymous Maarten <madebr@users.noreply.github.com> * Fix includedirs.append * Isolate autotools.configure for better --keep-build support * Add explicit name for pkg_config * Minor name fix * Keep autoreconf in build method * Enforce standard compatibility for exported include path * Revert "Enforce standard compatibility for exported include path" This reverts commit dfda98c. * Disable build for apply-clang with libc++ * Revert "Disable build for apply-clang with libc++" This reverts commit b65111d. * Update recipes/libsafec/all/conanfile.py Co-authored-by: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Co-authored-by: Chris Mc <prince.chrismc@gmail.com> Co-authored-by: Yoann Potinet <intelligide@hotmail.fr> Co-authored-by: Anonymous Maarten <madebr@users.noreply.github.com> Co-authored-by: SpaceIm <30052553+SpaceIm@users.noreply.github.com>
- Loading branch information
1 parent
ff86c41
commit f1f0396
Showing
6 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,4 @@ | ||
sources: | ||
"3.6.0": | ||
url: "https://github.com/rurban/safeclib/archive/v3.6.tar.gz" | ||
sha256: "bd99d4555030719a83807649b3749bc483143b3548278daaa0a4af0fed5dc4de" |
This file contains 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,95 @@ | ||
import glob | ||
import os | ||
|
||
from conans import AutoToolsBuildEnvironment, ConanFile, tools | ||
from conans.errors import ConanInvalidConfiguration | ||
|
||
required_conan_version = ">=1.29.1" | ||
|
||
|
||
class LibSafeCConan(ConanFile): | ||
name = "libsafec" | ||
description = "This library implements the secure C11 Annex K[^5] functions" \ | ||
" on top of most libc implementations, which are missing from them." | ||
url = "https://github.com/conan-io/conan-center-index" | ||
homepage = "https://github.com/rurban/safeclib" | ||
license = "MIT" | ||
topics = ("conan", "safec", "libc") | ||
|
||
settings = "os", "arch", "compiler", "build_type" | ||
options = {"shared": [True, False], "fPIC": [True, False]} | ||
default_options = {"shared": False, "fPIC": True} | ||
|
||
build_requires = "autoconf/2.69", "libtool/2.4.6" | ||
exports_sources = "patches/*" | ||
|
||
__autotools = None | ||
_source_subfolder = "source_subfolder" | ||
|
||
def config_options(self): | ||
if self.settings.os == "Windows": | ||
del self.options.fPIC | ||
|
||
@property | ||
def _supported_compiler(self): | ||
compiler = self.settings.compiler | ||
version = tools.Version(self.settings.compiler.version) | ||
if compiler == "Visual Studio": | ||
return False | ||
if compiler == "gcc" and version < "5": | ||
return False | ||
return True | ||
|
||
def configure(self): | ||
if not self._supported_compiler: | ||
raise ConanInvalidConfiguration( | ||
"libsafec doesn't support {}/{}".format( | ||
self.settings.compiler, self.settings.compiler.version)) | ||
if self.options.shared: | ||
del self.options.fPIC | ||
del self.settings.compiler.libcxx | ||
del self.settings.compiler.cppstd | ||
|
||
def source(self): | ||
tools.get(**self.conan_data["sources"][self.version]) | ||
extracted_dir = glob.glob("safeclib-*")[0] | ||
os.rename(extracted_dir, self._source_subfolder) | ||
|
||
@property | ||
def _autotools(self): | ||
if self.__autotools is None: | ||
self.__autotools = AutoToolsBuildEnvironment(self) | ||
return self.__autotools | ||
|
||
def _autotools_configure(self): | ||
if self.options.shared: | ||
args = ["--enable-shared", "--disable-static"] | ||
else: | ||
args = ["--disable-shared", "--enable-static"] | ||
args.extend(["--disable-doc", "--disable-Werror"]) | ||
if self.settings.build_type in ("Debug", "RelWithDebInfo"): | ||
args.append("--enable-debug") | ||
self._autotools.configure(args=args) | ||
|
||
def build(self): | ||
with tools.chdir(self._source_subfolder): | ||
self.run("autoreconf -fiv", run_environment=True) | ||
self._autotools_configure() | ||
self._autotools.make() | ||
|
||
def package(self): | ||
with tools.chdir(self._source_subfolder): | ||
self._autotools.install() | ||
self.copy("COPYING", src=self._source_subfolder, dst="licenses") | ||
with tools.chdir(os.path.join(self.package_folder, "lib")): | ||
tools.rmdir("pkgconfig") | ||
tools.remove_files_by_mask(".", "*.la") | ||
|
||
def package_info(self): | ||
self.cpp_info.includedirs.append(os.path.join("include", "libsafec")) | ||
self.cpp_info.libs = ["safec-{}".format(self.version)] | ||
self.cpp_info.names["pkg_config"] = "libsafec" | ||
|
||
bin_dir = os.path.join(self.package_folder, "bin") | ||
self.output.info("Appending PATH environment variable: {}".format(bin_dir)) | ||
self.env_info.PATH.append(bin_dir) |
This file contains 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,8 @@ | ||
cmake_minimum_required(VERSION 3.1) | ||
project(test_package C) | ||
|
||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) | ||
conan_basic_setup() | ||
|
||
add_executable(test_package test_package.c) | ||
target_link_libraries(test_package ${CONAN_LIBS}) |
This file contains 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,18 @@ | ||
import os | ||
|
||
from conans import CMake, ConanFile, tools | ||
|
||
|
||
class TestPackageConan(ConanFile): | ||
settings = "os", "compiler", "build_type", "arch" | ||
generators = "cmake" | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def test(self): | ||
if not tools.cross_building(self.settings): | ||
bin_path = os.path.join("bin", "test_package") | ||
self.run(bin_path, run_environment=True) |
This file contains 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,23 @@ | ||
#include <safe_str_lib.h> | ||
#include <stdlib.h> | ||
|
||
void | ||
constraint_handler(const char* msg, void* ptr, errno_t error) | ||
{ | ||
printf("Constraint handler: %s\n", msg); | ||
printf("Success!\n"); | ||
exit(0); | ||
} | ||
|
||
int | ||
main(int argc, char** argv) | ||
{ | ||
char dst[2]; | ||
|
||
set_str_constraint_handler_s(constraint_handler); | ||
|
||
strcpy_s(dst, sizeof dst, "Too long!"); | ||
printf("Fail!\n"); | ||
|
||
return 1; | ||
} |
This file contains 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,3 @@ | ||
versions: | ||
"3.6.0": | ||
folder: all |