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

nspr: bump + modernize + no tools.os_info in build_requirements #7212

Merged
merged 10 commits into from
Mar 7, 2022
Merged
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
12 changes: 6 additions & 6 deletions recipes/nspr/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
sources:
"4.24":
sha256: 90a59a0df6a11528749647fe18401cc7e03881e3e63c309f8c520ce06dd413d0
url: https://ftp.mozilla.org/pub/nspr/releases/v4.24/src/nspr-4.24.tar.gz
"4.27":
sha256: 6d495192b6ab00a3c28db053492cf794329f7c0351a5728db198111a1816e89b
url: https://ftp.mozilla.org/pub/nspr/releases/v4.27/src/nspr-4.27.tar.gz
"4.29":
sha256: 22286bdb8059d74632cc7c2865c139e63953ecfb33bf4362ab58827e86e92582
url: https://ftp.mozilla.org/pub/nspr/releases/v4.29/src/nspr-4.29.tar.gz
"4.32":
sha256: bb6bf4f534b9559cf123dcdc6f9cd8167de950314a90a88b2a329c16836e7f6c
url: https://ftp.mozilla.org/pub/nspr/releases/v4.32/src/nspr-4.32.tar.gz
"4.27":
url: "https://ftp.mozilla.org/pub/nspr/releases/v4.27/src/nspr-4.27.tar.gz"
sha256: "6d495192b6ab00a3c28db053492cf794329f7c0351a5728db198111a1816e89b"
"4.24":
url: "https://ftp.mozilla.org/pub/nspr/releases/v4.24/src/nspr-4.24.tar.gz"
sha256: "90a59a0df6a11528749647fe18401cc7e03881e3e63c309f8c520ce06dd413d0"
65 changes: 40 additions & 25 deletions recipes/nspr/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,39 @@
from conans import ConanFile, tools, AutoToolsBuildEnvironment
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
from conans import ConanFile, tools, AutoToolsBuildEnvironment
from conan.tools.microsoft import msvc_runtime_flag
from conans import ConanFile, tools, AutoToolsBuildEnvironment

from conans.errors import ConanInvalidConfiguration
import conan.tools.files
from contextlib import contextmanager
import os
import contextlib

required_conan_version = ">=1.33"
required_conan_version = ">=1.33.0"

class NsprConan(ConanFile):
name = "nspr"
homepage = "https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSPR"
description = "Netscape Portable Runtime (NSPR) provides a platform-neutral API for system level and libc-like functions."
topics = ("conan", "nspr", "libc")
topics = ("nspr", "libc")
url = "https://github.com/conan-io/conan-center-index"
settings = "os", "compiler", "arch", "build_type"
license = "MPL-2.0"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_mozilla": [True, False],
"win32_target": ["winnt", "win95"]
"win32_target": ["winnt", "win95"],
}
default_options = {
"shared": False,
"fPIC": True,
"with_mozilla": True,
"win32_target": "winnt",
}

generators = "cmake"

_autotools = None

@property
def _is_msvc(self):
return self.settings.compiler in ["Visual Studio", "msvc"]

@property
def _source_subfolder(self):
return "source_subfolder"
Expand All @@ -45,10 +49,10 @@ def config_options(self):
del self.options.win32_target

def configure(self):
del self.settings.compiler.cppstd
del self.settings.compiler.libcxx
if self.options.shared:
del self.options.fPIC
del self.settings.compiler.cppstd
del self.settings.compiler.libcxx

def validate(self):
# https://bugzilla.mozilla.org/show_bug.cgi?id=1658671
Expand All @@ -58,19 +62,20 @@ def validate(self):

def source(self):
tools.get(**self.conan_data["sources"][self.version],
strip_root=True)
conan.tools.files.rename(self, "nspr", self._source_subfolder)
destination="tmp", strip_root=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

Feature request? strip_root=2

Copy link
Member

@uilianries uilianries Sep 22, 2021

Choose a reason for hiding this comment

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

It worth an issue

Copy link
Contributor

Choose a reason for hiding this comment

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

please fill a feature request to conan client

os.rename(os.path.join("tmp", "nspr"), self._source_subfolder)
tools.rmdir("tmp")

def build_requirements(self):
if self._settings_build.os == "Windows" :
if self._settings_build.os == "Windows":
self.build_requires("mozilla-build/3.3")
if not tools.get_env("CONAN_BASH_PATH"):
self.build_requires("msys2/cci.latest")

@contextmanager
@contextlib.contextmanager
def _build_context(self):
if self.settings.compiler == "Visual Studio":
with tools.vcvars(self.settings):
if self._is_msvc:
with tools.vcvars(self):
with tools.environment_append({"CC": "cl", "CXX": "cl", "LD": "link"}):
yield
else:
Expand All @@ -79,30 +84,34 @@ def _build_context(self):
def _configure_autotools(self):
if self._autotools:
return self._autotools
self._autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows)
yes_no = lambda v: "yes" if v else "no"
conf_args = [
"--with-mozilla" if self.options.with_mozilla else "--without-mozilla",
"--with-mozilla={}".format(yes_no(self.options.with_mozilla)),
"--enable-64bit={}".format(yes_no(self.settings.arch in ("armv8", "x86_64", "mips64", "ppc64", "ppc64le"))),
"--enable-strip={}".format(yes_no(self.settings.build_type not in ("Debug", "RelWithDebInfo"))),
"--enable-debug={}".format(yes_no(self.settings.build_type == "Debug")),
"--datarootdir={}".format(tools.unix_path(os.path.join(self.package_folder, "res"))),
"--disable-cplus",
"--enable-64bit" if self.settings.arch in ("armv8", "x86_64") else "--disable-64bit",
"--disable-strip" if self.settings.build_type == "RelWithDebInfo" else "--enable-strip",
"--enable-debug" if self.settings.build_type == "Debug" else "--disable-debug",
]
Comment on lines +90 to 99
Copy link
Contributor

Choose a reason for hiding this comment

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

there are dupicated opions here.

Copy link
Contributor

Choose a reason for hiding this comment

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

might be a merge artifact

if self.settings.compiler == "Visual Studio":
if self._is_msvc:
conf_args.extend([
"{}-pc-mingw32".format("x86_64" if self.settings.arch == "x86_64" else "x86"),
"--enable-static-rtl" if "MT" in str(self.settings.compiler.runtime) else "--disable-static-rtl",
"--enable-debug-rtl" if "d" in str(self.settings.compiler.runtime) else "--disable-debug-rtl",
"--enable-static-rtl={}".format(yes_no("MT" in self.settings.compiler.runtime)),
"--enable-debug-rtl={}".format(yes_no("d" in self.settings.compiler.runtime)),
SSE4 marked this conversation as resolved.
Show resolved Hide resolved
Comment on lines +103 to +104
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"--enable-static-rtl={}".format(yes_no("MT" in self.settings.compiler.runtime)),
"--enable-debug-rtl={}".format(yes_no("d" in self.settings.compiler.runtime)),
"--enable-static-rtl={}".format(yes_no("MT" in msvc_runtime_flag(self))),
"--enable-debug-rtl={}".format(yes_no("d" in msvc_runtime_flag(self))),

])
elif self.settings.os == "Android":
conf_args.extend([
"--with-android-ndk={}".format(os.environ["NDK_ROOT"]),
"--with-android-ndk={}".format(tools.get_env(["NDK_ROOT"])),
"--with-android-version={}".format(self.settings.os.api_level),
"--with-android-platform={}".format(os.environ["ANDROID_PLATFORM"]),
"--with-android-toolchain={}".format(os.environ["ANDROID_TOOLCHAIN"]),
"--with-android-platform={}".format(tools.get_env("ANDROID_PLATFORM")),
"--with-android-toolchain={}".format(tools.get_env("ANDROID_TOOLCHAIN")),
])
elif self.settings.os == "Windows":
conf_args.append("--enable-win32-target={}".format(self.options.win32_target))
self._autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows)

env = self._autotools.vars
if self.settings.os == "Macos":
if self.settings.arch == "armv8":
Expand Down Expand Up @@ -132,8 +141,8 @@ def package(self):
if self.options.shared:
os.mkdir(os.path.join(self.package_folder, "bin"))
for lib in self._library_names:
libsuffix = "lib" if self.settings.compiler == "Visual Studio" else "a"
libprefix = "" if self.settings.compiler == "Visual Studio" else "lib"
libsuffix = "lib" if self._is_msvc else "a"
libprefix = "" if self._is_msvc else "lib"
if self.options.shared:
os.unlink(os.path.join(self.package_folder, "lib", "{}{}_s.{}".format(libprefix, lib, libsuffix)))
os.rename(os.path.join(self.package_folder, "lib", "{}.dll".format(lib)),
Expand Down Expand Up @@ -184,3 +193,9 @@ def package_info(self):
self.cpp_info.system_libs.extend(["dl", "pthread"])
elif self.settings.os == "Windows":
self.cpp_info.system_libs.extend(["winmm", "ws2_32"])

aclocal = tools.unix_path(os.path.join(self.package_folder, "res", "aclocal"))
self.output.info("Appending AUTOMAKE_CONAN_INCLUDES environment variable: {}".format(aclocal))
self.env_info.AUTOMAKE_CONAN_INCLUDES.append(aclocal)

self.cpp_info.resdirs = ["res"]
12 changes: 6 additions & 6 deletions recipes/nspr/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

set(CMAKE_CXX_STANDARD 11)
project(test_package C)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
conan_basic_setup(TARGETS)

find_package(nspr REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE nspr::nspr)
2 changes: 1 addition & 1 deletion recipes/nspr/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"
generators = "cmake", "cmake_find_package_multi"

def build(self):
cmake = CMake(self)
Expand Down
26 changes: 26 additions & 0 deletions recipes/nspr/all/test_package/test_package.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <nspr.h>

#include <stdio.h>

static int primordial(int argc, char *argv[]) {
if (PR_Initialized() != PR_TRUE) {
fprintf(stderr, "NSPR not initialized!\n");
return 1;
}
fprintf(stderr, "Inside primordial function\n");
return 0;
}

int main(int argc, char *argv[]) {
int versionOk = PR_VersionCheck(PR_VERSION);
if (versionOk == 0) {
fprintf(stderr, "PR_VersionCheck() failed\n");
return 1;
}
printf(PR_NAME " version %s\n", PR_GetVersion());
PR_Initialize(primordial, argc, argv, 0);

PR_ProcessExit(0);
fprintf(stderr, "PR_ProcessExit failed\n");
return 1;
}
30 changes: 0 additions & 30 deletions recipes/nspr/all/test_package/test_package.cpp

This file was deleted.

8 changes: 4 additions & 4 deletions recipes/nspr/config.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
versions:
"4.24":
folder: all
"4.27":
"4.32":
folder: all
"4.29":
folder: all
"4.32":
"4.27":
folder: all
"4.24":
folder: all