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

[conan2] Support Conan 2.x with meta-conan #47

Draft
wants to merge 11 commits into
base: kirkstone
Choose a base branch
from
Draft
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
27 changes: 27 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
The MIT License (MIT)

Copyright (c) 2023 JFrog LTD



Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:



The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.



THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Meta Conan
# Meta Conan: A Yocto layer for Conan client

[![Build Status](https://ci.conan.io/job/meta-conan/job/master/badge/icon)](https://ci.conan.io/job/meta-conan/job/master/)

Expand All @@ -8,18 +8,20 @@ Introduction
This layer collects recipes required to use the Conan Package Manager client in the Yocto builds.
With this layer you can write simple Bitbake recipes to retrieve and deploy Conan packages from an Artifactory repository.

*conan-mosquitto_1.4.15.bb*
*conan-mosquitto_2.0.15.bb*
```
inherit conan

DESCRIPTION = "An open source MQTT broker"
LICENSE = "EPL-1.0"

CONAN_PKG = "mosquitto/1.4.15@bincrafters/stable"
CONAN_PKG = "mosquitto/2.0.15"
````

Read how to use this layer in the Conan documentation: https://docs.conan.io/en/latest/integrations/cross_platform/yocto.html

**WARNING**: The current documentation is outdated and should not work properly

Requirements
------------

Expand All @@ -28,4 +30,4 @@ This layer depends on the `meta-python` layer: https://layers.openembedded.org/l

License
-------
[MIT](https://github.com/conan-io/conan/blob/develop/LICENSE.md)
[MIT](LICENSE.md)
132 changes: 91 additions & 41 deletions classes/conan.bbclass
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
# conan.bbclass
#
# Yocto Project bbclass for Conan.io package manager
#
# This bbclass provides the integration of Conan.io into the Yocto Project
#
# Please open an issue on the GitHub repository if you encounter any problems:
#
# GitHub Repository: https://github.com/conan-io/meta-conan
# Issues: https://github.com/conan-io/meta-conan/issues

PV = "0.2.0"
LICENSE = "MIT"
DEPENDS:append = " python3-conan-native"
S = "${WORKDIR}"
export CONAN_USER_HOME = "${WORKDIR}"
export CONAN_NON_INTERACTIVE = "1"
export CONAN_REVISIONS_ENABLED = "1"

DEPENDS += " python3-conan-native"
export CONAN_HOME="${WORKDIR}/.conan"
export CONAN_DEFAULT_PROFILE="${CONAN_HOME}/profiles/meta_build"

# Need this because we do not use GNU_HASH in the conan builds
# INSANE_SKIP:${PN} = "ldflags"

CONAN_REMOTE_URL ?= ""
CONAN_REMOTE_NAME ?= "conan-yocto"
CONAN_PROFILE_PATH ?= "${WORKDIR}/profiles/meta-conan_deploy"
CONAN_PROFILE_BUILD_PATH ?= "${CONAN_HOME}/profiles/meta_build"
CONAN_PROFILE_HOST_PATH ?= "${CONAN_HOME}/profiles/meta_host"
CONAN_CONFIG_URL ?= ""

CONAN_PROFILE_HOST_OPTIONS ?= ""
CONAN_BUILD_POLICY ?= "never"

conan_do_compile() {
:
Expand All @@ -31,57 +45,93 @@ def map_yocto_arch_to_conan_arch(d, arch_var):
"mips64": "mips64",
"ppc7400": "ppc32"
}.get(arch, arch)
print("Arch value '{}' from '{}' mapped to '{}'".format(arch, arch_var, ret))
bb.note("\nINFO: Arch value '{}' from '{}' mapped to '{}'".format(arch, arch_var, ret))
return ret

do_install[network] = "1"
conan_do_install() {
rm -rf ${WORKDIR}/.conan
if [ ${CONAN_CONFIG_URL} ]; then
echo "Installing Conan configuration from:"
echo ${CONAN_CONFIG_URL}
conan config install ${CONAN_CONFIG_URL}
echo "INFO: Creating Conan home directory: ${CONAN_HOME}"
rm -rf "${CONAN_HOME}"
mkdir -p "${CONAN_HOME}"
echo "INFO: Creating Conan configuration"
echo 'core:non_interactive=1' > "${CONAN_HOME}/global.conf"
if [ -n "${CONAN_CONFIG_URL}" ]; then
echo "Installing Conan configuration from: ${CONAN_CONFIG_URL}"
conan config install "${CONAN_CONFIG_URL}"
else
echo "WARN: No Conan configuration URL provided, using Conan local cache."
fi
if [ "${CONAN_REMOTE_URL}" ]; then
num_of_urls=$( echo ${CONAN_REMOTE_URL} | wc -w )
num_of_names=$( echo ${CONAN_REMOTE_NAME} | wc -w )
if [ ${num_of_urls} -ne ${num_of_names} ]; then
echo "ERROR: number of CONAN_REMOTE_URLs does not equal number of CONAN_REMOTE_NAMEs"
echo "${num_of_urls} CONAN_REMOTE_URLs given"
echo "${num_of_names} CONAN_REMOTE_NAMEs given"

echo "INFO: Configuring Conan remotes"
if [ -n "${CONAN_REMOTE_URL}" ]; then
urls_size=$( echo ${CONAN_REMOTE_URL} | wc -w )
names_size=$( echo ${CONAN_REMOTE_NAME} | wc -w )
echo "INFO: URLS SIZE: ${urls_size}"
echo "INFO: NAMES SIZE: ${names_size}"
if [ "${urls_size}" -ne "${names_size}" ]; then
echo "ERROR: number of CONAN_REMOTE_URL does not equal number of CONAN_REMOTE_NAME"
echo "CONAN_REMOTE_URL size: ${urls_size}"
echo "CONAN_REMOTE_NAME size: ${names_size}"
echo "Please, use empty space as separator for both variables."
exit 1
fi
echo "Configuring the Conan remote:"
awk 'BEGIN{split("${CONAN_REMOTE_NAME}",a) split("${CONAN_REMOTE_URL}", b); for (i in a)
system("conan remote add " a[i] " " b[i]) }'
system("conan remote add --force --index=0 " a[i] " " b[i]) }'
else
echo "WARN: No Conan remotes provided (CONAN_REMOTE_URL), using Conan default remotes."
fi
mkdir -p ${WORKDIR}/profiles
${CC} -dumpfullversion | {
IFS=. read major minor patch
cat > ${WORKDIR}/profiles/meta-conan_deploy <<EOF
build_type="Release"
if [ "${DEBUG_BUILD}" -eq "1" ]; then
build_type="Debug"
fi
cc_major=$(${CC} -dumpfullversion | cut -d'.' -f1)
cc_name=$(echo ${CC} | cut -d' ' -f1)
cxx_name=$(echo ${CXX} | cut -d' ' -f1)

# TODO: libcxx and cppstd should be configurable
libcxx="libstdc++11"
cppstd="gnu17"
echo "INFO: Generating build profile"
conan profile detect --name="${CONAN_PROFILE_BUILD_PATH}"
echo "INFO: Generating host profile"
cat > "${CONAN_PROFILE_HOST_PATH}" <<EOF
[settings]
os_build=Linux
arch_build=${@map_yocto_arch_to_conan_arch(d, 'BUILD_ARCH')}
os=Linux
arch=${@map_yocto_arch_to_conan_arch(d, 'HOST_ARCH')}
compiler=gcc
compiler.version=$major
compiler.libcxx=libstdc++11
build_type=Release
compiler.version=${cc_major}
compiler.libcxx=${libcxx}
compiler.cppstd=${cppstd}
build_type=${build_type}
[options]
${CONAN_PROFILE_HOST_OPTIONS}
EOF
}

echo "Using profile:"
echo ${CONAN_PROFILE_PATH}
conan profile show -pr ${CONAN_PROFILE_PATH}
echo "INFO: Using build profile: ${CONAN_PROFILE_BUILD_PATH}"
echo "INFO: Using host profile: ${CONAN_PROFILE_HOST_PATH}"
conan profile show -pr:h="${CONAN_PROFILE_HOST_PATH}" -pr:b="${CONAN_PROFILE_BUILD_PATH}"

if [ "${CONAN_USER}" ]; then
for NAME in ${CONAN_REMOTE_NAME}
do
conan remote login -p "${CONAN_PASSWORD}" "${NAME}" "${CONAN_USER}"
done
fi
conan install --requires=${CONAN_PKG} --profile ${CONAN_PROFILE_PATH} -of ${D}
for remote_name in ${CONAN_REMOTE_NAME}; do
remote_name_upper=$(echo "${remote_name}" | tr '[a-z]' '[A-Z]' | tr '-' '_')
if [ -z "${CONAN_LOGIN_USERNAME}" ]; then
echo "ERROR: No username provided for remote '${remote_name}'."
echo "Please set CONAN_LOGIN_USERNAME."
exit 1
fi
if [ -z "${CONAN_PASSWORD}" ]; then
echo "ERROR: No password provided for remote '${remote_name}'."
echo "Please set CONAN_PASSWORD_${remote_name_upper} or CONAN_PASSWORD."
exit 1
fi

echo "INFO: Logging in to remote '${remote_name}' as '${CONAN_LOGIN_USERNAME}'"
conan remote login -p "${CONAN_PASSWORD}" "${remote_name}" "${CONAN_LOGIN_USERNAME}"
done

# TODO: Generate a conanfile.txt with all dependencies
# TODO: Generators and Deploy ???
echo "INFO: Installing packages for ${CONAN_PKG}"
conan install --requires="${CONAN_PKG}" -pr:h="${CONAN_PROFILE_HOST_PATH}" -pr:b="${CONAN_PROFILE_BUILD_PATH}" --build="${CONAN_BUILD_POLICY}" -of "${D}"
rm -f ${D}/deploy_manifest.txt
rm -f ${D}/deactivate_*.sh
rm -f ${D}/conan*.sh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@ AUTHOR = "JFrog LTD <[email protected]>"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://LICENSE.md;md5=1e486b3d16485847635c786d2b7bd32a"

SRC_URI[md5sum] = "00e7631ca11eeb3d8072f4586aaf1196"
SRC_URI[sha256sum] = "f9129ae26c4e025c344e7d34e2afaedc924298da6810136a2b7e542143c6638c"
SRC_URI[md5sum] = "361a5a0bdeae1d5bc7bbe96decb23cd1"
SRC_URI[sha256sum] = "695f3ffc512107818dc81e1dd3bab8cb7c4588cd5eced92147ed23de0e7c3b0a"

inherit setuptools3 python3-dir pypi update-alternatives

# Overwrite the script to disable run-time dependency checking
# INFO: Overwrite the script to disable run-time dependency checking

do_install:append(){
rm ${D}${bindir}/conan
cat >> ${D}${bindir}/conan <<EOF
rm "${D}${bindir}/conan"
cat >> "${D}${bindir}/conan" <<EOF
#!/usr/bin/env ${PYTHON_PN}
from conans.conan import run
run()
EOF
chmod 755 ${D}${bindir}/conan
chmod 755 "${D}${bindir}/conan"
}

RDEPENDS:${PN} = "\
Expand All @@ -29,15 +30,8 @@ RDEPENDS:${PN} = "\
python3-pyyaml \
python3-patch-ng \
python3-fasteners \
python3-six \
python3-node-semver \
python3-distro \
python3-pylint \
python3-future \
python3-pygments \
python3-astroid \
python3-deprecation \
python3-tqdm \
python3-jinja2 \
python3-sqlite3 \
"
Expand All @@ -51,15 +45,8 @@ DEPENDS:class-native = "\
python3-pyyaml-native \
python3-patch-ng-native \
python3-fasteners-native \
python3-six-native \
python3-node-semver-native \
python3-distro-native \
python3-pylint-native \
python3-future-native \
python3-pygments-native \
python3-astroid-native \
python3-deprecation-native \
python3-tqdm-native \
python3-jinja2-native \
python3-native \
"
Expand All @@ -72,5 +59,5 @@ ALTERNATIVE_TARGET[conan] = "${bindir}/conan"
BBCLASSEXTEND = "native nativesdk"

do_install:append:class-native() {
sed -i -e 's|^#!.*/usr/bin/env ${PYTHON_PN}|#! /usr/bin/env nativepython3|' ${D}${bindir}/conan
sed -i -e 's|^#!.*/usr/bin/env ${PYTHON_PN}|#! /usr/bin/env nativepython3|' "${D}${bindir}/conan"
}
14 changes: 0 additions & 14 deletions recipes-devtools/python3-node-semver_0.6.1.bb

This file was deleted.

1 change: 0 additions & 1 deletion recipes-devtools/python3-pylint_%.bbappend

This file was deleted.