Skip to content

Commit 40c349c

Browse files
committed
fix install: clean up installation of samples
* Now `USERVER_BUILD_SAMPLES` does not actually build samples and run their tests in-place unless `USERVER_BUILD_TESTS` is also set. `USERVER_BUILD_SAMPLES` + `USERVER_INSTALL` still installs samples. * Moved `libraries/easy/samples` to `samples/easy` for consistency. Now they are installed even if `easy` library itself is disabled. --- * Design decision: samples should always go into `samples/` directory. If there is a risk of cluttering the directory, then create `samples/<library>/` subdirectory with an umbrella `CMakeLists.txt` that will become the root `CMakeLists.txt` after installation. All samples are installed as a single component regardless of whether the libraries are available, following `examples` packages in Qt and other popular multi-module libraries. commit_hash:e843d6f28a15779dd9b4768f3eaff21af321ba74
1 parent ab81a81 commit 40c349c

43 files changed

Lines changed: 99 additions & 114 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci-conan.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ jobs:
100100
101101
- name: Test userver conan package
102102
run: |-
103-
mv libraries/easy/samples/0_hello_world samples/
104-
mv libraries/easy/samples/1_hi samples/
105-
mv libraries/easy/samples/3_json samples/
103+
mv samples/easy/0_hello_world samples/
104+
mv samples/easy/1_hi samples/
105+
mv samples/easy/3_json samples/
106106
mv scripts/tests/conanfile.py samples/
107107
rm -rf userver/cmake/
108108
cd samples/

.mapping.json

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2999,40 +2999,6 @@
29992999
"libraries/CMakeLists.txt":"taxi/uservices/userver/libraries/CMakeLists.txt",
30003000
"libraries/easy/CMakeLists.txt":"taxi/uservices/userver/libraries/easy/CMakeLists.txt",
30013001
"libraries/easy/include/userver/easy.hpp":"taxi/uservices/userver/libraries/easy/include/userver/easy.hpp",
3002-
"libraries/easy/samples/0_hello_world/CMakeLists.txt":"taxi/uservices/userver/libraries/easy/samples/0_hello_world/CMakeLists.txt",
3003-
"libraries/easy/samples/0_hello_world/main.cpp":"taxi/uservices/userver/libraries/easy/samples/0_hello_world/main.cpp",
3004-
"libraries/easy/samples/0_hello_world/testsuite/conftest.py":"taxi/uservices/userver/libraries/easy/samples/0_hello_world/testsuite/conftest.py",
3005-
"libraries/easy/samples/0_hello_world/testsuite/test_basic.py":"taxi/uservices/userver/libraries/easy/samples/0_hello_world/testsuite/test_basic.py",
3006-
"libraries/easy/samples/1_hi/CMakeLists.txt":"taxi/uservices/userver/libraries/easy/samples/1_hi/CMakeLists.txt",
3007-
"libraries/easy/samples/1_hi/main.cpp":"taxi/uservices/userver/libraries/easy/samples/1_hi/main.cpp",
3008-
"libraries/easy/samples/1_hi/testsuite/conftest.py":"taxi/uservices/userver/libraries/easy/samples/1_hi/testsuite/conftest.py",
3009-
"libraries/easy/samples/1_hi/testsuite/test_basic.py":"taxi/uservices/userver/libraries/easy/samples/1_hi/testsuite/test_basic.py",
3010-
"libraries/easy/samples/2_key_value/CMakeLists.txt":"taxi/uservices/userver/libraries/easy/samples/2_key_value/CMakeLists.txt",
3011-
"libraries/easy/samples/2_key_value/main.cpp":"taxi/uservices/userver/libraries/easy/samples/2_key_value/main.cpp",
3012-
"libraries/easy/samples/2_key_value/testsuite/conftest.py":"taxi/uservices/userver/libraries/easy/samples/2_key_value/testsuite/conftest.py",
3013-
"libraries/easy/samples/2_key_value/testsuite/test_basic.py":"taxi/uservices/userver/libraries/easy/samples/2_key_value/testsuite/test_basic.py",
3014-
"libraries/easy/samples/3_json/CMakeLists.txt":"taxi/uservices/userver/libraries/easy/samples/3_json/CMakeLists.txt",
3015-
"libraries/easy/samples/3_json/main.cpp":"taxi/uservices/userver/libraries/easy/samples/3_json/main.cpp",
3016-
"libraries/easy/samples/3_json/schemas/key_value.yaml":"taxi/uservices/userver/libraries/easy/samples/3_json/schemas/key_value.yaml",
3017-
"libraries/easy/samples/3_json/testsuite/conftest.py":"taxi/uservices/userver/libraries/easy/samples/3_json/testsuite/conftest.py",
3018-
"libraries/easy/samples/3_json/testsuite/test_basic.py":"taxi/uservices/userver/libraries/easy/samples/3_json/testsuite/test_basic.py",
3019-
"libraries/easy/samples/4_custom_dependency/CMakeLists.txt":"taxi/uservices/userver/libraries/easy/samples/4_custom_dependency/CMakeLists.txt",
3020-
"libraries/easy/samples/4_custom_dependency/main.cpp":"taxi/uservices/userver/libraries/easy/samples/4_custom_dependency/main.cpp",
3021-
"libraries/easy/samples/4_custom_dependency/testsuite/conftest.py":"taxi/uservices/userver/libraries/easy/samples/4_custom_dependency/testsuite/conftest.py",
3022-
"libraries/easy/samples/4_custom_dependency/testsuite/test_basic.py":"taxi/uservices/userver/libraries/easy/samples/4_custom_dependency/testsuite/test_basic.py",
3023-
"libraries/easy/samples/5_pg_service_template/CMakeLists.txt":"taxi/uservices/userver/libraries/easy/samples/5_pg_service_template/CMakeLists.txt",
3024-
"libraries/easy/samples/5_pg_service_template/configs/static_config.yaml":"taxi/uservices/userver/libraries/easy/samples/5_pg_service_template/configs/static_config.yaml",
3025-
"libraries/easy/samples/5_pg_service_template/postgresql/schemas/db_1.sql":"taxi/uservices/userver/libraries/easy/samples/5_pg_service_template/postgresql/schemas/db_1.sql",
3026-
"libraries/easy/samples/5_pg_service_template/src/main.cpp":"taxi/uservices/userver/libraries/easy/samples/5_pg_service_template/src/main.cpp",
3027-
"libraries/easy/samples/5_pg_service_template/testsuite/conftest.py":"taxi/uservices/userver/libraries/easy/samples/5_pg_service_template/testsuite/conftest.py",
3028-
"libraries/easy/samples/5_pg_service_template/testsuite/test_basic.py":"taxi/uservices/userver/libraries/easy/samples/5_pg_service_template/testsuite/test_basic.py",
3029-
"libraries/easy/samples/6_pg_service_template_no_http_with/CMakeLists.txt":"taxi/uservices/userver/libraries/easy/samples/6_pg_service_template_no_http_with/CMakeLists.txt",
3030-
"libraries/easy/samples/6_pg_service_template_no_http_with/configs/static_config.yaml":"taxi/uservices/userver/libraries/easy/samples/6_pg_service_template_no_http_with/configs/static_config.yaml",
3031-
"libraries/easy/samples/6_pg_service_template_no_http_with/postgresql/schemas/db_1.sql":"taxi/uservices/userver/libraries/easy/samples/6_pg_service_template_no_http_with/postgresql/schemas/db_1.sql",
3032-
"libraries/easy/samples/6_pg_service_template_no_http_with/src/main.cpp":"taxi/uservices/userver/libraries/easy/samples/6_pg_service_template_no_http_with/src/main.cpp",
3033-
"libraries/easy/samples/6_pg_service_template_no_http_with/testsuite/conftest.py":"taxi/uservices/userver/libraries/easy/samples/6_pg_service_template_no_http_with/testsuite/conftest.py",
3034-
"libraries/easy/samples/6_pg_service_template_no_http_with/testsuite/test_basic.py":"taxi/uservices/userver/libraries/easy/samples/6_pg_service_template_no_http_with/testsuite/test_basic.py",
3035-
"libraries/easy/samples/CMakeLists.txt":"taxi/uservices/userver/libraries/easy/samples/CMakeLists.txt",
30363002
"libraries/easy/src/easy.cpp":"taxi/uservices/userver/libraries/easy/src/easy.cpp",
30373003
"libraries/grpc-proto-structs/include/userver/grpc-proto-structs/client/impl/codegen_declarations.hpp":"taxi/uservices/userver/libraries/grpc-proto-structs/include/userver/grpc-proto-structs/client/impl/codegen_declarations.hpp",
30383004
"libraries/grpc-proto-structs/include/userver/grpc-proto-structs/client/impl/codegen_definitions.hpp":"taxi/uservices/userver/libraries/grpc-proto-structs/include/userver/grpc-proto-structs/client/impl/codegen_definitions.hpp",
@@ -4467,6 +4433,40 @@
44674433
"samples/dns-resolver/resolver.cpp":"taxi/uservices/userver/samples/dns-resolver/resolver.cpp",
44684434
"samples/dns-resolver/testsuite/conftest.py":"taxi/uservices/userver/samples/dns-resolver/testsuite/conftest.py",
44694435
"samples/dns-resolver/testsuite/test_basic.py":"taxi/uservices/userver/samples/dns-resolver/testsuite/test_basic.py",
4436+
"samples/easy/0_hello_world/CMakeLists.txt":"taxi/uservices/userver/samples/easy/0_hello_world/CMakeLists.txt",
4437+
"samples/easy/0_hello_world/main.cpp":"taxi/uservices/userver/samples/easy/0_hello_world/main.cpp",
4438+
"samples/easy/0_hello_world/testsuite/conftest.py":"taxi/uservices/userver/samples/easy/0_hello_world/testsuite/conftest.py",
4439+
"samples/easy/0_hello_world/testsuite/test_basic.py":"taxi/uservices/userver/samples/easy/0_hello_world/testsuite/test_basic.py",
4440+
"samples/easy/1_hi/CMakeLists.txt":"taxi/uservices/userver/samples/easy/1_hi/CMakeLists.txt",
4441+
"samples/easy/1_hi/main.cpp":"taxi/uservices/userver/samples/easy/1_hi/main.cpp",
4442+
"samples/easy/1_hi/testsuite/conftest.py":"taxi/uservices/userver/samples/easy/1_hi/testsuite/conftest.py",
4443+
"samples/easy/1_hi/testsuite/test_basic.py":"taxi/uservices/userver/samples/easy/1_hi/testsuite/test_basic.py",
4444+
"samples/easy/2_key_value/CMakeLists.txt":"taxi/uservices/userver/samples/easy/2_key_value/CMakeLists.txt",
4445+
"samples/easy/2_key_value/main.cpp":"taxi/uservices/userver/samples/easy/2_key_value/main.cpp",
4446+
"samples/easy/2_key_value/testsuite/conftest.py":"taxi/uservices/userver/samples/easy/2_key_value/testsuite/conftest.py",
4447+
"samples/easy/2_key_value/testsuite/test_basic.py":"taxi/uservices/userver/samples/easy/2_key_value/testsuite/test_basic.py",
4448+
"samples/easy/3_json/CMakeLists.txt":"taxi/uservices/userver/samples/easy/3_json/CMakeLists.txt",
4449+
"samples/easy/3_json/main.cpp":"taxi/uservices/userver/samples/easy/3_json/main.cpp",
4450+
"samples/easy/3_json/schemas/key_value.yaml":"taxi/uservices/userver/samples/easy/3_json/schemas/key_value.yaml",
4451+
"samples/easy/3_json/testsuite/conftest.py":"taxi/uservices/userver/samples/easy/3_json/testsuite/conftest.py",
4452+
"samples/easy/3_json/testsuite/test_basic.py":"taxi/uservices/userver/samples/easy/3_json/testsuite/test_basic.py",
4453+
"samples/easy/4_custom_dependency/CMakeLists.txt":"taxi/uservices/userver/samples/easy/4_custom_dependency/CMakeLists.txt",
4454+
"samples/easy/4_custom_dependency/main.cpp":"taxi/uservices/userver/samples/easy/4_custom_dependency/main.cpp",
4455+
"samples/easy/4_custom_dependency/testsuite/conftest.py":"taxi/uservices/userver/samples/easy/4_custom_dependency/testsuite/conftest.py",
4456+
"samples/easy/4_custom_dependency/testsuite/test_basic.py":"taxi/uservices/userver/samples/easy/4_custom_dependency/testsuite/test_basic.py",
4457+
"samples/easy/5_pg_service_template/CMakeLists.txt":"taxi/uservices/userver/samples/easy/5_pg_service_template/CMakeLists.txt",
4458+
"samples/easy/5_pg_service_template/configs/static_config.yaml":"taxi/uservices/userver/samples/easy/5_pg_service_template/configs/static_config.yaml",
4459+
"samples/easy/5_pg_service_template/postgresql/schemas/db_1.sql":"taxi/uservices/userver/samples/easy/5_pg_service_template/postgresql/schemas/db_1.sql",
4460+
"samples/easy/5_pg_service_template/src/main.cpp":"taxi/uservices/userver/samples/easy/5_pg_service_template/src/main.cpp",
4461+
"samples/easy/5_pg_service_template/testsuite/conftest.py":"taxi/uservices/userver/samples/easy/5_pg_service_template/testsuite/conftest.py",
4462+
"samples/easy/5_pg_service_template/testsuite/test_basic.py":"taxi/uservices/userver/samples/easy/5_pg_service_template/testsuite/test_basic.py",
4463+
"samples/easy/6_pg_service_template_no_http_with/CMakeLists.txt":"taxi/uservices/userver/samples/easy/6_pg_service_template_no_http_with/CMakeLists.txt",
4464+
"samples/easy/6_pg_service_template_no_http_with/configs/static_config.yaml":"taxi/uservices/userver/samples/easy/6_pg_service_template_no_http_with/configs/static_config.yaml",
4465+
"samples/easy/6_pg_service_template_no_http_with/postgresql/schemas/db_1.sql":"taxi/uservices/userver/samples/easy/6_pg_service_template_no_http_with/postgresql/schemas/db_1.sql",
4466+
"samples/easy/6_pg_service_template_no_http_with/src/main.cpp":"taxi/uservices/userver/samples/easy/6_pg_service_template_no_http_with/src/main.cpp",
4467+
"samples/easy/6_pg_service_template_no_http_with/testsuite/conftest.py":"taxi/uservices/userver/samples/easy/6_pg_service_template_no_http_with/testsuite/conftest.py",
4468+
"samples/easy/6_pg_service_template_no_http_with/testsuite/test_basic.py":"taxi/uservices/userver/samples/easy/6_pg_service_template_no_http_with/testsuite/test_basic.py",
4469+
"samples/easy/CMakeLists.txt":"taxi/uservices/userver/samples/easy/CMakeLists.txt",
44704470
"samples/embedded_files/CMakeLists.txt":"taxi/uservices/userver/samples/embedded_files/CMakeLists.txt",
44714471
"samples/embedded_files/main.cpp":"taxi/uservices/userver/samples/embedded_files/main.cpp",
44724472
"samples/embedded_files/src/hello_handler.cpp":"taxi/uservices/userver/samples/embedded_files/src/hello_handler.cpp",

CMakeLists.txt

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,20 +345,37 @@ _userver_export_targets()
345345
_userver_make_install_config()
346346

347347
if(USERVER_BUILD_SAMPLES AND USERVER_FEATURE_CORE)
348-
add_subdirectory(samples)
348+
if(USERVER_BUILD_TESTS)
349+
add_subdirectory(samples)
350+
endif()
351+
352+
# Install the whole samples tree, but drop the master samples/CMakeLists.txt: it writes
353+
# a fake userverConfig.cmake stub and would shadow the real installed userver. The leaf
354+
# samples' own CMakeLists.txt files live in subdirectories and are kept, so the anchored
355+
# "samples/CMakeLists.txt" pattern only matches the top-level file.
356+
_userver_directory_install(
357+
COMPONENT examples
358+
DIRECTORY "${USERVER_ROOT_DIR}/samples"
359+
DESTINATION share/userver
360+
EXCLUDE_PATTERNS "samples/CMakeLists.txt"
361+
)
362+
# NON_FINDABLE: the 'examples' install/CPack component only ships sample sources.
363+
_userver_install_component(COMPONENT examples NON_FINDABLE)
364+
# libuserver-samples, not libuserver-samples-dev
365+
set(CPACK_DEBIAN_SAMPLES_PACKAGE_NAME libuserver-examples)
349366
endif()
350367

351368
if(USERVER_FEATURE_CORE)
352369
_userver_directory_install(
353370
COMPONENT core
354371
PROGRAMS "${USERVER_ROOT_DIR}/scripts/userver-create-service.py"
355-
DESTINATION ${CMAKE_INSTALL_BINDIR}/
372+
DESTINATION ${CMAKE_INSTALL_BINDIR}
356373
RENAME userver-create-service
357374
)
358375
_userver_directory_install(
359376
COMPONENT core
360377
DIRECTORY "${USERVER_ROOT_DIR}/service_template"
361-
DESTINATION ${CMAKE_INSTALL_DATADIR}/userver/
378+
DESTINATION ${CMAKE_INSTALL_DATADIR}/userver
362379
)
363380
endif()
364381

libraries/easy/CMakeLists.txt

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,3 @@ userver_module(
77
UTEST_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*_test.cpp"
88
COMPONENT_DEPENDS core
99
)
10-
11-
if(USERVER_BUILD_SAMPLES)
12-
# Imitate an installed userver for the leaf find_package(userver) calls.
13-
file(WRITE "${CMAKE_BINARY_DIR}/package_stubs/userverConfig.cmake" "")
14-
15-
add_subdirectory(samples)
16-
17-
# Install the easy samples as a standalone project under
18-
# share/userver/samples/easy (a dedicated subdirectory so they do not clutter
19-
# the root userver samples). The trailing slash installs the directory
20-
# contents, including samples/CMakeLists.txt which becomes the project root.
21-
_userver_directory_install(
22-
COMPONENT examples
23-
DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/samples/"
24-
DESTINATION "${CMAKE_INSTALL_DATADIR}/userver/samples/easy"
25-
)
26-
27-
# Clean up the fake userver installation above to avoid messing with
28-
# find_package(userver) in the parent project.
29-
file(REMOVE "${CMAKE_BINARY_DIR}/package_stubs/userverConfig.cmake")
30-
endif()

libraries/easy/include/userver/easy.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ std::string FormatToJsonString(const T& value) {
9494
///
9595
/// This component can be registered in the component list and used by any client. For example:
9696
///
97-
/// @snippet libraries/easy/samples/6_pg_service_template_no_http_with/src/main.cpp main
97+
/// @snippet samples/easy/6_pg_service_template_no_http_with/src/main.cpp main
9898
template <class Dependencies>
9999
class DependenciesComponent : public impl::DependenciesBase {
100100
public:

samples/CMakeLists.txt

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -172,20 +172,10 @@ if(USERVER_FEATURE_S3API)
172172
add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}-s3api)
173173
endif()
174174

175-
# Install the whole samples tree, but drop this master CMakeLists.txt: it writes a
176-
# fake userverConfig.cmake stub (above) and would shadow the real installed userver.
177-
# The leaf samples' own CMakeLists.txt files live in subdirectories and are kept, so
178-
# the anchored "samples/CMakeLists.txt" pattern only matches this top-level file.
179-
_userver_directory_install(
180-
COMPONENT examples
181-
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
182-
DESTINATION share/userver
183-
EXCLUDE_PATTERNS "samples/CMakeLists.txt"
184-
)
185-
# NON_FINDABLE: the 'examples' install/CPack component only ships sample sources.
186-
_userver_install_component(COMPONENT examples NON_FINDABLE)
187-
# libuserver-samples, not libuserver-samples-dev
188-
set(CPACK_DEBIAN_SAMPLES_PACKAGE_NAME libuserver-examples)
175+
if(USERVER_FEATURE_EASY)
176+
add_subdirectory(easy)
177+
add_dependencies(${PROJECT_NAME} userver-easy-samples)
178+
endif()
189179

190180
# Clean up fake userver installation above to avoid messing with find_package(userver) in the parent project.
191181
file(REMOVE "${CMAKE_BINARY_DIR}/package_stubs/userverConfig.cmake")
File renamed without changes.
File renamed without changes.
File renamed without changes.

libraries/easy/samples/0_hello_world/testsuite/test_basic.py renamed to samples/easy/0_hello_world/testsuite/test_basic.py

File renamed without changes.

0 commit comments

Comments
 (0)