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

protobuf: simplify test package #23573

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
4 changes: 1 addition & 3 deletions recipes/protobuf/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ project(test_package LANGUAGES CXX)

find_package(protobuf CONFIG REQUIRED)

add_executable(${PROJECT_NAME} test_package.cpp addressbook.proto)
add_executable(${PROJECT_NAME} test_package.cpp)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
if (protobuf_LITE)
Expand All @@ -17,5 +17,3 @@ if(TARGET protobuf::libprotoc)
target_link_libraries(${PROJECT_NAME} PRIVATE protobuf::libprotoc)
endif()

protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS TARGET ${PROJECT_NAME})
protobuf_generate(LANGUAGE cpp TARGET ${PROJECT_NAME} PROTOS addressbook.proto)
11 changes: 7 additions & 4 deletions recipes/protobuf/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ def layout(self):
cmake_layout(self)

def requirements(self):
self.requires(self.tested_reference_str)

def build_requirements(self):
self.tool_requires(self.tested_reference_str)
# note `run=True` so that the runenv can find protoc
self.requires(self.tested_reference_str, run=True)

def generate(self):
tc = CMakeToolchain(self)
Expand All @@ -32,3 +30,8 @@ def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")

# Invoke protoc in the same way CMake would
self.run(f"protoc --proto_path={self.source_folder} --cpp_out={self.build_folder} {self.source_folder}/addressbook.proto", env="conanrun")
assert os.path.exists(os.path.join(self.build_folder,"addressbook.pb.cc"))
assert os.path.exists(os.path.join(self.build_folder,"addressbook.pb.h"))
14 changes: 6 additions & 8 deletions recipes/protobuf/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
#include <cstdlib>
#include <iostream>

#include "addressbook.pb.h"
#include <google/protobuf/timestamp.pb.h>
#include <google/protobuf/util/time_util.h>

int main()
{
std::cout << "Bincrafters\n";
Copy link
Contributor

Choose a reason for hiding this comment

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

😥

google::protobuf::Timestamp ts;
google::protobuf::util::TimeUtil::FromString("1972-01-01T10:00:20.021Z", &ts);
const auto nanoseconds = ts.nanos();

tutorial::Person p;
p.set_id(21);
p.set_name("conan-center-index");
p.set_email("info@conan.io");

std::cout << p.SerializeAsString() << "\n";
std::cout << nanoseconds << "\n";
return EXIT_SUCCESS;
}
8 changes: 0 additions & 8 deletions recipes/protobuf/all/test_v1_package/CMakeLists.txt

This file was deleted.

27 changes: 0 additions & 27 deletions recipes/protobuf/all/test_v1_package/conanfile.py

This file was deleted.

Loading