Skip to content
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
23 changes: 19 additions & 4 deletions cmd/protoc-gen-cpp-tableau-loader/embed/hub.pc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
#include <google/protobuf/stubs/status.h>
#include <google/protobuf/text_format.h>

#ifdef _WIN32
#include <direct.h>
#include <windows.h>
#else
#include <sys/stat.h>
#endif

#include <fstream>
#include <sstream>
#include <string>
Expand All @@ -13,6 +20,14 @@
#include "registry.pc.h"

namespace tableau {
#ifdef _WIN32
#undef GetMessage
#define mkdir(path, mode) _mkdir(path)
static constexpr char kPathSeperator = '\\';
#else
static constexpr char kPathSeperator = '/';
#endif

static thread_local std::string g_err_msg;
const std::string& GetErrMsg() { return g_err_msg; }

Expand Down Expand Up @@ -589,9 +604,9 @@ bool Postprocess(Postprocessor postprocessor, MessagerContainer container) {

namespace util {
int Mkdir(const std::string& path) {
std::string path_ = path + "/";
std::string path_ = path + kPathSeperator;
struct stat info;
for (size_t pos = path_.find('/', 0); pos != std::string::npos; pos = path_.find('/', pos)) {
for (size_t pos = path_.find(kPathSeperator, 0); pos != std::string::npos; pos = path_.find(kPathSeperator, pos)) {
++pos;
auto sub_dir = path_.substr(0, pos);
if (stat(sub_dir.c_str(), &info) == 0 && info.st_mode & S_IFDIR) {
Expand All @@ -607,7 +622,7 @@ int Mkdir(const std::string& path) {
}

std::string GetDir(const std::string& path) {
std::size_t pos = path.find_last_of("/\\");
size_t pos = path.find_last_of(kPathSeperator);
if (pos != std::string::npos) {
return path.substr(0, pos);
}
Expand All @@ -624,4 +639,4 @@ std::string GetExt(const std::string& path) {

} // namespace util

} // namespace tableau
} // namespace tableau
2 changes: 1 addition & 1 deletion cmd/protoc-gen-cpp-tableau-loader/embed/hub.pc.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,4 +268,4 @@ class TimeProfiler {

} // namespace util

} // namespace tableau
} // namespace tableau
49 changes: 36 additions & 13 deletions cmd/protoc-gen-cpp-tableau-loader/embed/logger.pc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,25 @@
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#ifdef _WIN32
#include <direct.h>
#include <windows.h>
#else
#include <sys/syscall.h>
#include <sys/time.h>
#include <unistd.h>
#endif

#include <thread>
#include <unordered_map>

#include "hub.pc.h"

#ifdef _WIN32
#define gettid() GetCurrentThreadId()
#else
#define gettid() syscall(SYS_gettid)
#endif

namespace tableau {
namespace log {
Expand Down Expand Up @@ -45,11 +54,13 @@ void SetDefaultLogger(Logger* logger) {
}

int Logger::Init(const std::string& path, Level level) {
std::string dir = path.substr(0, path.find_last_of('/'));
// prepare the specified directory
int status = util::Mkdir(dir);
if (status == -1) {
return status;
std::string dir = util::GetDir(path);
if (!dir.empty()) {
// prepare the specified directory
int status = util::Mkdir(dir);
if (status == -1) {
return status;
}
}
ofs_.open(path, std::ofstream::out | std::ofstream::app);
os_ = &ofs_; // use file stream as output stream
Expand Down Expand Up @@ -88,17 +99,29 @@ void DefaultWrite(std::ostream* os, const SourceLocation& loc, const LevelInfo&

const char* NowStr() {
static char fmt[64], buf[64];
struct tm tm;

#ifdef _WIN32
SYSTEMTIME wtm;
GetLocalTime(&wtm);
tm.tm_year = wtm.wYear - 1900;
tm.tm_mon = wtm.wMonth - 1;
tm.tm_mday = wtm.wDay;
tm.tm_hour = wtm.wHour;
tm.tm_min = wtm.wMinute;
tm.tm_sec = wtm.wSecond;
unsigned int usec = wtm.wMilliseconds * 1000;
#else
struct timeval tv;
struct tm* tm;

gettimeofday(&tv, NULL);
if ((tm = localtime(&tv.tv_sec)) != NULL) {
// strftime(fmt, sizeof fmt, "%Y-%m-%d %H:%M:%S.%%06u %z", tm);
strftime(fmt, sizeof fmt, "%Y-%m-%d %H:%M:%S.%%06u", tm);
snprintf(buf, sizeof buf, fmt, tv.tv_usec);
}
localtime_r(&tv.tv_sec, &tm);
unsigned int usec = tv.tv_usec;
#endif

strftime(fmt, sizeof fmt, "%Y-%m-%d %H:%M:%S.%%06u", &tm);
snprintf(buf, sizeof buf, fmt, usec);
return buf;
}

} // namespace log
} // namespace tableau
} // namespace tableau
5 changes: 1 addition & 4 deletions cmd/protoc-gen-cpp-tableau-loader/embed/logger.pc.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#pragma once
#include <sys/stat.h>
#include <sys/types.h>

#include <fstream>
#include <functional>
#include <iostream>
Expand Down Expand Up @@ -105,4 +102,4 @@ std::string DebugString(const T& a,
#define ATOM_MAP_STR(m) \
tableau::log::DebugString(m, [](std::stringstream& ss, decltype(m)::const_iterator it) { \
ss << "{" << it->first << ": " << it->second << "}"; \
})
})
19 changes: 19 additions & 0 deletions init.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@echo off
setlocal

for /f "delims=" %%i in ('git rev-parse --show-toplevel') do set repoRoot=%%i
cd /d "%repoRoot%"

git submodule update --init --recursive

REM google protobuf
cd third_party\_submodules\protobuf
git checkout v3.19.3
git submodule update --init --recursive

REM Build and install the C++ Protocol Buffer runtime and the Protocol Buffer compiler (protoc)
cd cmake
cmake .
cmake --build .

endlocal
56 changes: 56 additions & 0 deletions test/cpp-tableau-loader/gen.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
@echo off
setlocal
setlocal enabledelayedexpansion

for /f "delims=" %%i in ('git rev-parse --show-toplevel') do set repoRoot=%%i
cd /d "%repoRoot%"

set "PROTOC=%repoRoot%\third_party\_submodules\protobuf\cmake\Debug\protoc.exe"
set "PROTOBUF_PROTO=%repoRoot%\third_party\_submodules\protobuf\src"
set "TABLEAU_PROTO=%repoRoot%\third_party\_submodules\tableau\proto"
set "ROOTDIR=%repoRoot%\test\cpp-tableau-loader"
set "PLGUIN_DIR=%repoRoot%\cmd\protoc-gen-cpp-tableau-loader"
set "PROTOCONF_IN=%repoRoot%\test\proto"
set "PROTOCONF_OUT=%ROOTDIR%\src\protoconf"

REM remove old generated files
if exist "%PROTOCONF_OUT%" rmdir /s /q "%PROTOCONF_OUT%"
mkdir "%PROTOCONF_OUT%"

REM build
pushd "%PLGUIN_DIR%"
go build
popd

set "PATH=%PATH%;%PLGUIN_DIR%"

set protoFiles=
pushd "%PROTOCONF_IN%"
for /R %%f in (*.proto) do (
set protoFiles=!protoFiles! "%%f"
)
popd
"%PROTOC%" ^
--cpp-tableau-loader_out="%PROTOCONF_OUT%" ^
--cpp-tableau-loader_opt=paths=source_relative,registry-shards=2 ^
--cpp_out="%PROTOCONF_OUT%" ^
--proto_path="%PROTOBUF_PROTO%" ^
--proto_path="%TABLEAU_PROTO%" ^
--proto_path="%PROTOCONF_IN%" ^
!protoFiles!

set "TABLEAU_IN=%TABLEAU_PROTO%\tableau\protobuf"
set "TABLEAU_OUT=%ROOTDIR%\src"
REM remove old generated files
if exist "%TABLEAU_OUT%\tableau" rmdir /s /q "%TABLEAU_OUT%\tableau"
mkdir "%TABLEAU_OUT%\tableau"

"%PROTOC%" ^
--cpp_out="%TABLEAU_OUT%" ^
--proto_path="%PROTOBUF_PROTO%" ^
--proto_path="%TABLEAU_PROTO%" ^
"%TABLEAU_IN%\tableau.proto" ^
"%TABLEAU_IN%\wellknown.proto"

endlocal
endlocal
26 changes: 12 additions & 14 deletions test/cpp-tableau-loader/gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ cd "${PLGUIN_DIR}" && go build && cd -
export PATH="${PATH}:${PLGUIN_DIR}"

${PROTOC} \
--plugin "$PLUGIN" \
--cpp-tableau-loader_out="$PROTOCONF_OUT" \
--cpp-tableau-loader_opt=paths=source_relative,registry-shards=2 \
--cpp_out="$PROTOCONF_OUT" \
--proto_path="$PROTOBUF_PROTO" \
--proto_path="$TABLEAU_PROTO" \
--proto_path="$PROTOCONF_IN" \
"$PROTOCONF_IN"/**/*.proto
--cpp-tableau-loader_out="$PROTOCONF_OUT" \
--cpp-tableau-loader_opt=paths=source_relative,registry-shards=2 \
--cpp_out="$PROTOCONF_OUT" \
--proto_path="$PROTOBUF_PROTO" \
--proto_path="$TABLEAU_PROTO" \
--proto_path="$PROTOCONF_IN" \
"$PROTOCONF_IN"/**/*.proto

TABLEAU_IN="./third_party/_submodules/tableau/proto/tableau/protobuf"
TABLEAU_OUT="${ROOTDIR}/src"
Expand All @@ -41,9 +40,8 @@ rm -rfv "$TABLEAU_OUT/tableau"
mkdir -p "$TABLEAU_OUT/tableau"

${PROTOC} \
--cpp_out="$TABLEAU_OUT" \
--proto_path="$PROTOBUF_PROTO" \
--proto_path="$TABLEAU_PROTO" \
"${TABLEAU_PROTO}/tableau/protobuf/tableau.proto" \
"${TABLEAU_PROTO}/tableau/protobuf/wellknown.proto"

--cpp_out="$TABLEAU_OUT" \
--proto_path="$PROTOBUF_PROTO" \
--proto_path="$TABLEAU_PROTO" \
"${TABLEAU_PROTO}/tableau/protobuf/tableau.proto" \
"${TABLEAU_PROTO}/tableau/protobuf/wellknown.proto"
25 changes: 18 additions & 7 deletions test/cpp-tableau-loader/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ file(GLOB_RECURSE SOURCE *.cpp)
# specify the C++ standard
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -g -fPIC -std=c++11 -Wno-deprecated -Wno-unused-variable -Wno-sign-compare -Wno-strict-aliasing -fno-strict-aliasing -DNDEBUG")
if (MSVC)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /DNDEBUG")
else()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -g -fPIC -std=c++11 -Wno-deprecated -Wno-unused-variable -Wno-sign-compare -Wno-strict-aliasing -fno-strict-aliasing -DNDEBUG")
endif()

# root dir define
SET(CMAKE_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
Expand All @@ -30,12 +34,19 @@ SET(COMMON_INCLUDE_DIR
)

# common lib
SET(COMMON_LIB
${PROTOBUF_LIB}/libprotobuf.a
pthread
)

# inlcude
if(MSVC)
SET(COMMON_LIB
${PROTOBUF_ROOT_DIR}/cmake/Debug/libprotobufd.lib
)
SET(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDebug")
else()
SET(COMMON_LIB
${PROTOBUF_LIB}/libprotobuf.a
pthread
)
endif()

# include
include_directories(${PROJECT_SOURCE_DIR} ${COMMON_INCLUDE_DIR} ${PROJECT_SOURCE_DIR}/protoconf)

# add the executable
Expand Down
2 changes: 1 addition & 1 deletion test/cpp-tableau-loader/src/protoconf/hero_conf.pc.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated by protoc-gen-cpp-tableau-loader. DO NOT EDIT.
// versions:
// - protoc-gen-cpp-tableau-loader v0.6.0
// - protoc-gen-cpp-tableau-loader v0.7.0
// - protoc v3.19.3
// source: hero_conf.proto

Expand Down
2 changes: 1 addition & 1 deletion test/cpp-tableau-loader/src/protoconf/hero_conf.pc.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated by protoc-gen-cpp-tableau-loader. DO NOT EDIT.
// versions:
// - protoc-gen-cpp-tableau-loader v0.6.0
// - protoc-gen-cpp-tableau-loader v0.7.0
// - protoc v3.19.3
// source: hero_conf.proto

Expand Down
24 changes: 19 additions & 5 deletions test/cpp-tableau-loader/src/protoconf/hub.pc.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated by protoc-gen-cpp-tableau-loader. DO NOT EDIT.
// versions:
// - protoc-gen-cpp-tableau-loader v0.6.0
// - protoc-gen-cpp-tableau-loader v0.7.0
// - protoc v3.19.3

#include "hub.pc.h"
Expand All @@ -9,6 +9,13 @@
#include <google/protobuf/stubs/status.h>
#include <google/protobuf/text_format.h>

#ifdef _WIN32
#include <direct.h>
#include <windows.h>
#else
#include <sys/stat.h>
#endif

#include <fstream>
#include <sstream>
#include <string>
Expand All @@ -18,6 +25,14 @@
#include "registry.pc.h"

namespace tableau {
#ifdef _WIN32
#undef GetMessage
#define mkdir(path, mode) _mkdir(path)
static constexpr char kPathSeperator = '\\';
#else
static constexpr char kPathSeperator = '/';
#endif

static thread_local std::string g_err_msg;
const std::string& GetErrMsg() { return g_err_msg; }

Expand Down Expand Up @@ -594,9 +609,9 @@ bool Postprocess(Postprocessor postprocessor, MessagerContainer container) {

namespace util {
int Mkdir(const std::string& path) {
std::string path_ = path + "/";
std::string path_ = path + kPathSeperator;
struct stat info;
for (size_t pos = path_.find('/', 0); pos != std::string::npos; pos = path_.find('/', pos)) {
for (size_t pos = path_.find(kPathSeperator, 0); pos != std::string::npos; pos = path_.find(kPathSeperator, pos)) {
++pos;
auto sub_dir = path_.substr(0, pos);
if (stat(sub_dir.c_str(), &info) == 0 && info.st_mode & S_IFDIR) {
Expand All @@ -612,7 +627,7 @@ int Mkdir(const std::string& path) {
}

std::string GetDir(const std::string& path) {
std::size_t pos = path.find_last_of("/\\");
size_t pos = path.find_last_of(kPathSeperator);
if (pos != std::string::npos) {
return path.substr(0, pos);
}
Expand All @@ -630,4 +645,3 @@ std::string GetExt(const std::string& path) {
} // namespace util

} // namespace tableau

Loading