Skip to content

Commit 1155eb3

Browse files
committed
PIP-209: Build C++ client in standalone repo
1 parent 5f42cdf commit 1155eb3

11 files changed

+1188
-23
lines changed

CMakeLists.txt

+8-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ cmake_minimum_required(VERSION 3.4)
2222
project (pulsar-cpp)
2323
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake_modules")
2424

25-
execute_process(COMMAND ${CMAKE_SOURCE_DIR}/../src/gen-pulsar-version-macro.py OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE PVM)
25+
execute_process(COMMAND cat ${CMAKE_SOURCE_DIR}/version.txt OUTPUT_STRIP_TRAILING_WHITESPACE
26+
OUTPUT_VARIABLE PULSAR_CLIENT_VERSION)
27+
message(STATUS "Pulsar Client version: ${PULSAR_CLIENT_VERSION}")
28+
29+
execute_process(COMMAND ${CMAKE_SOURCE_DIR}/gen-pulsar-version-macro.py OUTPUT_STRIP_TRAILING_WHITESPACE
30+
OUTPUT_VARIABLE PULSAR_CLIENT_VERSION_MACRO)
31+
2632
set(PVM_COMMENT "This is generated from Version.h.in by CMAKE. DO NOT EDIT DIRECTLY")
2733
configure_file(templates/Version.h.in include/pulsar/Version.h @ONLY)
2834

@@ -221,7 +227,7 @@ else()
221227
find_library(LIB_SNAPPY NAMES snappy libsnappy)
222228
endif ()
223229

224-
find_package(CURL REQUIRED)
230+
find_package(CURL REQUIRED)
225231
if (${CMAKE_VERSION} VERSION_GREATER "3.12")
226232
set(COMMON_LIBS ${COMMON_LIBS} CURL::libcurl)
227233
endif ()

gen-pulsar-version-macro.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
#
20+
21+
import re, sys
22+
23+
version = open("version.txt").read()
24+
m = re.search(r'^(\d+)\.(\d+)\.(\d+)', version)
25+
26+
version_macro = 0
27+
for i in range(3):
28+
version_macro += int(m.group(3 - i)) * (1000 ** i)
29+
print(version_macro)

lib/CMakeLists.txt

+2-5
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919

2020
file(GLOB PULSAR_SOURCES *.cc *.h lz4/*.cc lz4/*.h checksum/*.cc checksum/*.h stats/*.cc stats/*.h c/*.cc c/*.h auth/*.cc auth/*.h auth/athenz/*.cc auth/athenz/*.h)
2121

22-
execute_process(COMMAND ${CMAKE_SOURCE_DIR}/../src/get-project-version.py OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE PV)
23-
set (CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -D_PULSAR_VERSION_INTERNAL_=\\\"${PV}\\\"")
24-
2522
if (NOT PROTOC_PATH)
2623
set(PROTOC_PATH protoc)
2724
endif()
@@ -36,9 +33,9 @@ set(PROTO_SOURCES ${LIB_AUTOGEN_DIR}/PulsarApi.pb.cc ${LIB_AUTOGEN_DIR}/PulsarAp
3633
set(PULSAR_SOURCES ${PULSAR_SOURCES} ${PROTO_SOURCES})
3734
ADD_CUSTOM_COMMAND(
3835
OUTPUT ${PROTO_SOURCES}
39-
COMMAND ${PROTOC_PATH} -I ../../pulsar-common/src/main/proto ../../pulsar-common/src/main/proto/PulsarApi.proto --cpp_out=${LIB_AUTOGEN_DIR}
36+
COMMAND ${PROTOC_PATH} -I ../proto ../proto/PulsarApi.proto --cpp_out=${LIB_AUTOGEN_DIR}
4037
DEPENDS
41-
../../pulsar-common/src/main/proto/PulsarApi.proto
38+
../proto/PulsarApi.proto
4239
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
4340

4441
set(LIBRARY_VERSION $ENV{PULSAR_LIBRARY_VERSION})

lib/Commands.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
#include "Commands.h"
2020
#include "MessageImpl.h"
21-
#include "VersionInternal.h"
21+
#include "pulsar/Version.h"
2222
#include "pulsar/MessageBuilder.h"
2323
#include "LogUtils.h"
2424
#include "PulsarApi.pb.h"
@@ -217,7 +217,7 @@ SharedBuffer Commands::newConnect(const AuthenticationPtr& authentication, const
217217
BaseCommand cmd;
218218
cmd.set_type(BaseCommand::CONNECT);
219219
CommandConnect* connect = cmd.mutable_connect();
220-
connect->set_client_version(_PULSAR_VERSION_INTERNAL_);
220+
connect->set_client_version(PULSAR_VERSION_STR);
221221
connect->set_auth_method_name(authentication->getAuthMethodName());
222222
connect->set_protocol_version(ProtocolVersion_MAX);
223223

@@ -245,7 +245,7 @@ SharedBuffer Commands::newAuthResponse(const AuthenticationPtr& authentication,
245245
BaseCommand cmd;
246246
cmd.set_type(BaseCommand::AUTH_RESPONSE);
247247
CommandAuthResponse* authResponse = cmd.mutable_authresponse();
248-
authResponse->set_client_version(_PULSAR_VERSION_INTERNAL_);
248+
authResponse->set_client_version(PULSAR_VERSION_STR);
249249

250250
AuthData* authData = authResponse->mutable_response();
251251
authData->set_auth_method_name(authentication->getAuthMethodName());

lib/HTTPLookupService.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ Result HTTPLookupService::sendHTTPRequest(std::string completeUrl, std::string &
157157
while (++reqCount <= MAX_HTTP_REDIRECTS) {
158158
CURL *handle;
159159
CURLcode res;
160-
std::string version = std::string("Pulsar-CPP-v") + _PULSAR_VERSION_INTERNAL_;
160+
std::string version = std::string("Pulsar-CPP-v") + PULSAR_VERSION_STR;
161161
handle = curl_easy_init();
162162

163163
if (!handle) {

lib/HTTPLookupService.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <lib/LookupService.h>
2323
#include <lib/ClientImpl.h>
2424
#include <lib/Url.h>
25-
#include <lib/VersionInternal.h>
25+
#include <pulsar/Version.h>
2626
#include <lib/ServiceNameResolver.h>
2727

2828
namespace pulsar {

0 commit comments

Comments
 (0)