99from conan .tools .cmake import CMakeDeps
1010from conan .tools .cmake import CMakeToolchain
1111from 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
1314from conan .tools .scm import Git
14- from conan .tools .system import package_manager
1515
1616required_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' ])
0 commit comments