Skip to content

Commit a3ee428

Browse files
apolukhinrobot-piglet
authored andcommitted
feat build: synchronize conanfile.py with the one from conan-center PR
Tests: протестировано github CI, на прод не влияет Conan center PR conan-io/conan-center-index#28173 --- Pull Request resolved: #1015 Co-authored-by: antoshkka <[email protected]> Co-authored-by: antoshkka <[email protected]> Co-authored-by: Antony Polukhin <[email protected]> commit_hash:25ab73cb03ff9b746536c13bab83aa668b35d175
1 parent 02b7451 commit a3ee428

File tree

6 files changed

+69
-80
lines changed

6 files changed

+69
-80
lines changed

.github/workflows/ci-conan.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
conanflags: ''
2929
tests-env: 'JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64'
3030
- os: macos-14
31-
conanflags: '-o python_path=python3.11'
31+
conanflags: ''
3232
tests-env: ''
3333

3434
steps:
@@ -66,15 +66,15 @@ jobs:
6666
6767
- name: Install common packages
6868
run: |
69-
pip install "conan==2.8.0"
69+
pip install conan
7070
pip install numpy
7171
${{ matrix.container && 'sudo -u test-user' }} conan profile detect
7272
${{ matrix.container && 'sudo -u test-user' }} conan profile show
7373
7474
- name: Run conan
7575
run: |
7676
${{ matrix.container && 'sudo -u test-user' }} git config --global --add safe.directory `pwd`
77-
${{ matrix.container && 'sudo -u test-user' }} conan create . --build=missing -s:a compiler.cppstd=17 -pr:b=default ${{matrix.conanflags}}
77+
${{ matrix.container && 'sudo -u test-user' }} conan create . --update --build=missing --version=`cat version.txt` -s:a compiler.cppstd=17 -pr:b=default ${{matrix.conanflags}}
7878
7979
- name: Install test dependencies
8080
if: matrix.os == 'ubuntu-22.04'
@@ -86,21 +86,25 @@ jobs:
8686
| sudo tee -a /etc/apt/sources.list.d/mongodb-org-7.0.list
8787
8888
sudo DEBIAN_FRONTEND=noninteractive apt update
89-
sudo DEBIAN_FRONTEND=noninteractive apt install -y postgresql redis mongodb-org mongodb-mongosh locales
89+
sudo DEBIAN_FRONTEND=noninteractive apt install -y postgresql libpq-dev redis mongodb-org mongodb-mongosh locales
9090
${{ matrix.container && 'sudo locale-gen en_US.UTF-8' }}
9191
${{ matrix.container && 'update-locale LC_ALL="en_US.UTF-8" LANG="en_US.UTF-8" LANGUAGE="en_US.UTF-8"' }}
9292
sudo ./scripts/kafka/ubuntu_install_kafka.sh
9393
sudo ./scripts/rabbitmq/ubuntu_install_rabbitmq_server.sh
9494
9595
- name: Test userver conan package
9696
run: |-
97+
mv libraries/easy/samples/0_hello_world samples/
98+
mv libraries/easy/samples/1_hi samples/
9799
mv libraries/easy/samples/3_json samples/
98100
mv scripts/tests/conanfile.py samples/
99101
rm -rf userver/cmake/
100102
cd samples/
101103
102104
USERVER_VERSION=$(${{ matrix.container && 'sudo -u test-user' }} conan list -c -v quiet userver/* | tail -n 1)
103105
for SAMPLE in \
106+
0_hello_world \
107+
1_hi \
104108
3_json \
105109
chaotic_service \
106110
embedded_files \
@@ -116,7 +120,7 @@ jobs:
116120
s3api \
117121
; do
118122
mv conanfile.py $SAMPLE/
119-
echo "Run: ${{ matrix.container && 'sudo -u test-user' }} ${{matrix.tests-env}} conan test $SAMPLE/ --build=never -s:a compiler.cppstd=17 -pr:b=default ${{matrix.conanflags}} ${USERVER_VERSION}"
120-
${{ matrix.container && 'sudo -u test-user' }} ${{matrix.tests-env}} conan test $SAMPLE/ --build=never -s:a compiler.cppstd=17 -pr:b=default ${{matrix.conanflags}} ${USERVER_VERSION}
123+
echo "Run: ${{ matrix.container && 'sudo -u test-user' }} ${{matrix.tests-env}} conan test --build=never -s:a compiler.cppstd=17 -pr:b=default ${{matrix.conanflags}} $SAMPLE/ ${USERVER_VERSION}"
124+
${{ matrix.container && 'sudo -u test-user' }} ${{matrix.tests-env}} conan test --build=never -s:a compiler.cppstd=17 -pr:b=default ${{matrix.conanflags}} $SAMPLE/ ${USERVER_VERSION}
121125
mv $SAMPLE/conanfile.py ./
122126
done

.github/workflows/macos.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
run: |
5757
export SDKROOT="`xcrun --show-sdk-path`"
5858
brew update
59-
brew uninstall cmake
59+
brew uninstall cmake # workaround for `Error: cmake was installed from the local/pinned tap`
6060
brew install $(cat scripts/docs/en/deps/macos.md)
6161
brew install clang-format
6262
brew install lld

conanfile.py

Lines changed: 54 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
from conan.tools.cmake import CMakeDeps
1010
from conan.tools.cmake import CMakeToolchain
1111
from conan.tools.files import copy
12-
from conan.tools.files import load
12+
from conan.tools.files import export_conandata_patches
13+
from conan.tools.files import get
1314
from conan.tools.scm import Git
14-
from conan.tools.system import package_manager
1515

1616
required_conan_version = '>=2.8.0' # pylint: disable=invalid-name
1717

@@ -20,7 +20,7 @@ class UserverConan(ConanFile):
2020
name = 'userver'
2121
description = 'The C++ Asynchronous Framework'
2222
topics = ('framework', 'coroutines', 'asynchronous')
23-
url = 'https://github.com/userver-framework/userver'
23+
url = 'https://github.com/conan-io/conan-center-index'
2424
homepage = 'https://userver.tech/'
2525
license = 'Apache-2.0'
2626
package_type = 'static-library'
@@ -46,10 +46,6 @@ class UserverConan(ConanFile):
4646
'with_s3api': [True, False],
4747
'with_grpc_reflection': [True, False],
4848
'with_grpc_protovalidate': [True, False],
49-
'namespace': ['ANY'],
50-
'namespace_begin': ['ANY'],
51-
'namespace_end': ['ANY'],
52-
'python_path': ['ANY'],
5349
}
5450

5551
default_options = {
@@ -72,10 +68,6 @@ class UserverConan(ConanFile):
7268
'with_s3api': True,
7369
'with_grpc_reflection': True,
7470
'with_grpc_protovalidate': False,
75-
'namespace': 'userver',
76-
'namespace_begin': 'namespace userver {',
77-
'namespace_end': '}',
78-
'python_path': 'python3',
7971
'mongo-c-driver/*:with_sasl': 'cyrus',
8072
'grpc/*:php_plugin': False,
8173
'grpc/*:node_plugin': False,
@@ -91,24 +83,26 @@ class UserverConan(ConanFile):
9183
're2/*:with_icu': True,
9284
}
9385

94-
def export_sources(self):
95-
git = Git(self)
96-
tracked_sources = git.included_files()
97-
# To speed up copying, we take only the root folders
98-
tracked_sources = {f.split('/')[0] for f in tracked_sources}
99-
for i in tracked_sources:
100-
copy(self, f'{i}*', self.recipe_folder, self.export_sources_folder)
101-
102-
def set_version(self):
103-
content = load(
104-
self,
105-
os.path.join(
106-
os.path.dirname(os.path.realpath(__file__)),
107-
'version.txt',
108-
),
109-
)
86+
def source(self):
87+
known_version = (self.conan_data or {}).get('sources', {}).get(self.version)
88+
if known_version:
89+
get(self, **known_version, strip_root=True)
90+
else:
91+
# Running from develop branch, do nothing
92+
pass
11093

111-
self.version = content.strip() # pylint: disable=attribute-defined-outside-init
94+
def export_sources(self):
95+
known_version = (self.conan_data or {}).get('sources', {}).get(self.version)
96+
if known_version:
97+
export_conandata_patches(self)
98+
else:
99+
# Running from develop branch, no patches
100+
git = Git(self)
101+
tracked_sources = git.included_files()
102+
# To speed up copying, we take only the root folders
103+
tracked_sources = {f.split('/')[0] for f in tracked_sources}
104+
for i in tracked_sources:
105+
copy(self, f'{i}*', self.recipe_folder, self.export_sources_folder)
112106

113107
def layout(self):
114108
cmake_layout(self)
@@ -157,7 +151,7 @@ def requirements(self):
157151
self.requires('cyrus-sasl/2.1.28')
158152
if self.options.with_mongodb:
159153
self.requires(
160-
'mongo-c-driver/1.28.0',
154+
'mongo-c-driver/1.30.3',
161155
transitive_headers=True,
162156
transitive_libs=True,
163157
)
@@ -203,44 +197,42 @@ def validate(self):
203197

204198
def generate(self):
205199
tool_ch = CMakeToolchain(self)
206-
tool_ch.variables['CMAKE_FIND_DEBUG_MODE'] = False
200+
tool_ch.cache_variables['CMAKE_FIND_DEBUG_MODE'] = False
207201

208-
tool_ch.variables['USERVER_CONAN'] = True
209-
tool_ch.variables['USERVER_INSTALL'] = True
210-
tool_ch.variables['USERVER_DOWNLOAD_PACKAGES'] = True
211-
tool_ch.variables['USERVER_FEATURE_DWCAS'] = True
212-
tool_ch.variables['USERVER_NAMESPACE'] = self.options.namespace
213-
tool_ch.variables['USERVER_NAMESPACE_BEGIN'] = self.options.namespace_begin
214-
tool_ch.variables['USERVER_NAMESPACE_END'] = self.options.namespace_end
215-
tool_ch.variables['USERVER_PYTHON_PATH'] = self.options.python_path
202+
tool_ch.cache_variables['USERVER_CONAN'] = True
203+
tool_ch.cache_variables['USERVER_INSTALL'] = True
204+
tool_ch.cache_variables['USERVER_DOWNLOAD_PACKAGES'] = True
205+
tool_ch.cache_variables['USERVER_FEATURE_DWCAS'] = True
216206

217-
tool_ch.variables['USERVER_LTO'] = self.options.lto
218-
tool_ch.variables['USERVER_FEATURE_JEMALLOC'] = self.options.with_jemalloc
219-
tool_ch.variables['USERVER_FEATURE_MONGODB'] = self.options.with_mongodb
220-
tool_ch.variables['USERVER_FEATURE_POSTGRESQL'] = self.options.with_postgresql
221-
tool_ch.variables['USERVER_FEATURE_PATCH_LIBPQ'] = self.options.with_postgresql_extra
222-
tool_ch.variables['USERVER_FEATURE_REDIS'] = self.options.with_redis
223-
tool_ch.variables['USERVER_FEATURE_REDIS_TLS'] = self.options.with_redis_tls
224-
tool_ch.variables['USERVER_FEATURE_GRPC'] = self.options.with_grpc
225-
tool_ch.variables['USERVER_FEATURE_CLICKHOUSE'] = self.options.with_clickhouse
226-
tool_ch.variables['USERVER_FEATURE_RABBITMQ'] = self.options.with_rabbitmq
227-
tool_ch.variables['USERVER_FEATURE_UTEST'] = self.options.with_utest
228-
tool_ch.variables['USERVER_FEATURE_TESTSUITE'] = self.options.with_utest
229-
tool_ch.variables['USERVER_FEATURE_KAFKA'] = self.options.with_kafka
230-
tool_ch.variables['USERVER_FEATURE_OTLP'] = self.options.with_otlp
231-
tool_ch.variables['USERVER_FEATURE_SQLITE'] = self.options.with_sqlite
232-
tool_ch.variables['USERVER_FEATURE_EASY'] = self.options.with_easy
233-
tool_ch.variables['USERVER_FEATURE_S3API'] = self.options.with_s3api
234-
tool_ch.variables['USERVER_FEATURE_GRPC_REFLECTION'] = self.options.with_grpc_reflection
235-
tool_ch.variables['USERVER_FEATURE_GRPC_PROTOVALIDATE'] = self.options.with_grpc_protovalidate
207+
tool_ch.cache_variables['USERVER_LTO'] = self.options.lto
208+
tool_ch.cache_variables['USERVER_FEATURE_JEMALLOC'] = self.options.with_jemalloc
209+
tool_ch.cache_variables['USERVER_FEATURE_MONGODB'] = self.options.with_mongodb
210+
tool_ch.cache_variables['USERVER_FEATURE_POSTGRESQL'] = self.options.with_postgresql
211+
tool_ch.cache_variables['USERVER_FEATURE_PATCH_LIBPQ'] = self.options.with_postgresql_extra
212+
tool_ch.cache_variables['USERVER_FEATURE_REDIS'] = self.options.with_redis
213+
tool_ch.cache_variables['USERVER_FEATURE_REDIS_TLS'] = self.options.with_redis_tls
214+
tool_ch.cache_variables['USERVER_FEATURE_GRPC'] = self.options.with_grpc
215+
tool_ch.cache_variables['USERVER_FEATURE_CLICKHOUSE'] = self.options.with_clickhouse
216+
tool_ch.cache_variables['USERVER_FEATURE_RABBITMQ'] = self.options.with_rabbitmq
217+
tool_ch.cache_variables['USERVER_FEATURE_UTEST'] = self.options.with_utest
218+
tool_ch.cache_variables['USERVER_FEATURE_TESTSUITE'] = self.options.with_utest
219+
tool_ch.cache_variables['USERVER_FEATURE_KAFKA'] = self.options.with_kafka
220+
tool_ch.cache_variables['USERVER_FEATURE_OTLP'] = self.options.with_otlp
221+
tool_ch.cache_variables['USERVER_FEATURE_SQLITE'] = self.options.with_sqlite
222+
tool_ch.cache_variables['USERVER_FEATURE_EASY'] = self.options.with_easy
223+
tool_ch.cache_variables['USERVER_FEATURE_S3API'] = self.options.with_s3api
224+
tool_ch.cache_variables['USERVER_FEATURE_GRPC_REFLECTION'] = self.options.with_grpc_reflection
225+
tool_ch.cache_variables['USERVER_FEATURE_GRPC_PROTOVALIDATE'] = self.options.with_grpc_protovalidate
236226

237227
if self.options.with_grpc:
238-
tool_ch.variables['USERVER_GOOGLE_COMMON_PROTOS'] = (
228+
tool_ch.cache_variables['USERVER_GOOGLE_COMMON_PROTOS'] = (
239229
self.dependencies['googleapis'].cpp_info.components['google_rpc_status_proto'].resdirs[0]
240230
)
241231

242232
if self.options.with_otlp:
243-
tool_ch.variables['USERVER_OPENTELEMETRY_PROTO'] = self.dependencies['opentelemetry-proto'].conf_info.get(
233+
tool_ch.cache_variables['USERVER_OPENTELEMETRY_PROTO'] = self.dependencies[
234+
'opentelemetry-proto'
235+
].conf_info.get(
244236
'user.opentelemetry-proto:proto_root',
245237
)
246238

@@ -251,9 +243,9 @@ def generate(self):
251243
def build(self):
252244
# pg_config is required to build psycopg2 from source without system package.
253245
# However, this approach fails on later stage, when venv for tests is built.
254-
# libpq = self.dependencies["libpq"]
255-
# if libpq:
256-
# os.environ["PATH"] = os.environ["PATH"] + ":" + libpq.package_folder+ "/bin"
246+
libpq = self.dependencies['libpq']
247+
if libpq:
248+
os.environ['PATH'] = os.environ['PATH'] + ':' + libpq.package_folder + '/bin'
257249

258250
cmake = CMake(self)
259251
cmake.configure()
@@ -267,12 +259,3 @@ def package_info(self):
267259
# https://docs.conan.io/2/examples/tools/cmake/cmake_toolchain/use_package_config_cmake.html
268260
self.cpp_info.set_property('cmake_find_mode', 'none')
269261
self.cpp_info.builddirs.append(os.path.join('lib', 'cmake', 'userver'))
270-
271-
def system_requirements(self):
272-
if self.options.with_postgresql:
273-
# pg_config is required to build psycopg2 python module from source at
274-
# testsuite venv creation during functional testing of user code.
275-
package_manager.Apt(self).install(['libpq-dev'])
276-
package_manager.Yum(self).install(['libpq-devel'])
277-
package_manager.PacMan(self).install(['libpq-dev'])
278-
package_manager.Zypper(self).install(['libpq-devel'])

libraries/easy/samples/0_hello_world/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
cmake_minimum_required(VERSION 3.14)
12
project(userver-easy-samples-hello-world CXX)
23

34
find_package(

libraries/easy/samples/1_hi/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
cmake_minimum_required(VERSION 3.14)
12
project(userver-easy-samples-hi CXX)
23

34
find_package(

scripts/docs/en/userver/build/build.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,8 @@ Thanks to Open-Source community we have Conan support.
449449
To build the userver Conan package run the following in the userver root directory:
450450
451451
```shell
452-
conan profile new --detect default && conan profile update settings.compiler.libcxx=libstdc++11 default
453-
conan create . --build=missing -pr:b=default
452+
conan profile detect && conan profile show
453+
conan create . --build=missing --version=`cat version.txt` -pr:b=default
454454
```
455455
456456
Make sure to pass flags corresponding to the desired userver libraries, e.g. `-o with_grpc=0`.

0 commit comments

Comments
 (0)