Skip to content

Commit

Permalink
Extract foo library into a separate library (#1043)
Browse files Browse the repository at this point in the history
  • Loading branch information
esigo authored Oct 30, 2021
1 parent 838d962 commit af75379
Show file tree
Hide file tree
Showing 29 changed files with 69 additions and 282 deletions.
2 changes: 2 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
add_subdirectory(common)
include_directories(common)
if(WITH_OTLP_GRPC OR WITH_OTLP_HTTP)
add_subdirectory(otlp)
add_subdirectory(grpc)
Expand Down
1 change: 1 addition & 0 deletions examples/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(foo_library)
16 changes: 16 additions & 0 deletions examples/common/foo_library/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package(default_visibility = ["//visibility:public"])

cc_library(
name = "common_foo_library",
srcs = [
"foo_library.cc",
],
hdrs = [
"foo_library.h",
],
defines = ["BAZEL_BUILD"],
deps = [
"//api",
"//sdk:headers",
],
)
3 changes: 3 additions & 0 deletions examples/common/foo_library/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_library(common_foo_library foo_library.h foo_library.cc)
target_link_libraries(common_foo_library PUBLIC ${CMAKE_THREAD_LIBS_INIT}
opentelemetry_api)
File renamed without changes.
File renamed without changes.
16 changes: 1 addition & 15 deletions examples/jaeger/BUILD
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
cc_library(
name = "foo_library",
srcs = [
"foo_library/foo_library.cc",
],
hdrs = [
"foo_library/foo_library.h",
],
deps = [
"//api",
"//sdk:headers",
],
)

# TODO: enable bazel build
# cc_binary(
# name = "example_jaeger",
# srcs = [
# "main.cc",
# ],
# deps = [
# ":foo_library",
# "//examples/common/foo_library:common_foo_library",
# "//api",
# "//exporters/jaeger:jaeger_exporter",
# "//sdk/src/trace",
Expand Down
6 changes: 1 addition & 5 deletions examples/jaeger/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
include_directories(${CMAKE_SOURCE_DIR}/exporters/jaeger/include)

add_library(jaeger_foo_library foo_library/foo_library.cc)
target_link_libraries(jaeger_foo_library ${CMAKE_THREAD_LIBS_INIT}
opentelemetry_api)

add_executable(example_jaeger main.cc)
target_link_libraries(
example_jaeger ${CMAKE_THREAD_LIBS_INIT} jaeger_foo_library
example_jaeger ${CMAKE_THREAD_LIBS_INIT} common_foo_library
opentelemetry_trace opentelemetry_exporter_jaeger_trace)
6 changes: 5 additions & 1 deletion examples/jaeger/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
#include "opentelemetry/sdk/trace/tracer_provider.h"
#include "opentelemetry/trace/provider.h"

#include "foo_library/foo_library.h"
#ifdef BAZEL_BUILD
# include "examples/common/foo_library/foo_library.h"
#else
# include "foo_library/foo_library.h"
#endif

namespace trace = opentelemetry::trace;
namespace nostd = opentelemetry::nostd;
Expand Down
15 changes: 1 addition & 14 deletions examples/multi_processor/BUILD
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
cc_library(
name = "foo_multi_library",
srcs = [
"foo_library/foo_library.cc",
],
hdrs = [
"foo_library/foo_library.h",
],
deps = [
"//api",
],
)

cc_binary(
name = "example_multi_processor",
srcs = [
"main.cc",
],
deps = [
":foo_multi_library",
"//api",
"//examples/common/foo_library:common_foo_library",
"//exporters/memory:in_memory_span_exporter",
"//exporters/ostream:ostream_span_exporter",
"//sdk/src/trace",
Expand Down
9 changes: 3 additions & 6 deletions examples/multi_processor/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
include_directories(${CMAKE_SOURCE_DIR}/exporters/ostream/include
${CMAKE_SOURCE_DIR}/exporters/memory/include)

add_library(foo_multi_library foo_library/foo_library.cc)
target_link_libraries(foo_multi_library opentelemetry_exporter_ostream_span
${CMAKE_THREAD_LIBS_INIT} opentelemetry_api)

add_executable(example_multi_processor main.cc)
target_link_libraries(example_multi_processor ${CMAKE_THREAD_LIBS_INIT}
foo_multi_library opentelemetry_trace)
target_link_libraries(
example_multi_processor ${CMAKE_THREAD_LIBS_INIT} common_foo_library
opentelemetry_trace opentelemetry_exporter_ostream_span)
45 changes: 0 additions & 45 deletions examples/multi_processor/foo_library/foo_library.cc

This file was deleted.

6 changes: 0 additions & 6 deletions examples/multi_processor/foo_library/foo_library.h

This file was deleted.

6 changes: 5 additions & 1 deletion examples/multi_processor/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
#include "opentelemetry/trace/provider.h"

// Using an exporter that simply dumps span data to stdout.
#include "foo_library/foo_library.h"
#ifdef BAZEL_BUILD
# include "examples/common/foo_library/foo_library.h"
#else
# include "foo_library/foo_library.h"
#endif
#include "opentelemetry/exporters/memory/in_memory_span_exporter.h"
#include "opentelemetry/exporters/ostream/span_exporter.h"

Expand Down
17 changes: 2 additions & 15 deletions examples/otlp/BUILD
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
cc_library(
name = "foo_library",
srcs = [
"foo_library/foo_library.cc",
],
hdrs = [
"foo_library/foo_library.h",
],
deps = [
"//api",
],
)

cc_binary(
name = "example_otlp_grpc",
srcs = [
"grpc_main.cc",
],
deps = [
":foo_library",
"//api",
"//examples/common/foo_library:common_foo_library",
"//exporters/otlp:otlp_grpc_exporter",
"//sdk/src/trace",
],
Expand All @@ -30,8 +17,8 @@ cc_binary(
"http_main.cc",
],
deps = [
":foo_library",
"//api",
"//examples/common/foo_library:common_foo_library",
"//exporters/otlp:otlp_http_exporter",
"//sdk/src/trace",
],
Expand Down
12 changes: 4 additions & 8 deletions examples/otlp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
include_directories(
${CMAKE_BINARY_DIR}/generated/third_party/opentelemetry-proto)
include_directories(${CMAKE_SOURCE_DIR}/exporters/otlp/include)

add_library(otlp_foo_library foo_library/foo_library.cc)
target_link_libraries(otlp_foo_library ${CMAKE_THREAD_LIBS_INIT}
opentelemetry_api)
${CMAKE_BINARY_DIR}/generated/third_party/opentelemetry-proto
${CMAKE_SOURCE_DIR}/exporters/otlp/include)

if(WITH_OTLP_GRPC)
add_executable(example_otlp_grpc grpc_main.cc)
target_link_libraries(
example_otlp_grpc ${CMAKE_THREAD_LIBS_INIT} otlp_foo_library
example_otlp_grpc ${CMAKE_THREAD_LIBS_INIT} common_foo_library
opentelemetry_trace opentelemetry_exporter_otlp_grpc gRPC::grpc++)
endif()

if(WITH_OTLP_HTTP)
add_executable(example_otlp_http http_main.cc)
target_link_libraries(
example_otlp_http ${CMAKE_THREAD_LIBS_INIT} otlp_foo_library
example_otlp_http ${CMAKE_THREAD_LIBS_INIT} common_foo_library
opentelemetry_trace opentelemetry_exporter_otlp_http)
endif()
36 changes: 0 additions & 36 deletions examples/otlp/foo_library/foo_library.cc

This file was deleted.

6 changes: 0 additions & 6 deletions examples/otlp/foo_library/foo_library.h

This file was deleted.

6 changes: 5 additions & 1 deletion examples/otlp/grpc_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
#include "opentelemetry/sdk/trace/tracer_provider.h"
#include "opentelemetry/trace/provider.h"

#include "foo_library/foo_library.h"
#ifdef BAZEL_BUILD
# include "examples/common/foo_library/foo_library.h"
#else
# include "foo_library/foo_library.h"
#endif

namespace trace = opentelemetry::trace;
namespace nostd = opentelemetry::nostd;
Expand Down
6 changes: 5 additions & 1 deletion examples/otlp/http_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

#include <string>

#include "foo_library/foo_library.h"
#ifdef BAZEL_BUILD
# include "examples/common/foo_library/foo_library.h"
#else
# include "foo_library/foo_library.h"
#endif

namespace trace = opentelemetry::trace;
namespace nostd = opentelemetry::nostd;
Expand Down
16 changes: 1 addition & 15 deletions examples/simple/BUILD
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
cc_library(
name = "foo_library",
srcs = [
"foo_library/foo_library.cc",
],
hdrs = [
"foo_library/foo_library.h",
],
deps = [
"//api",
],
)

cc_binary(
name = "example_simple",
srcs = [
"main.cc",
],
deps = [
":foo_library",
"//api",
"//examples/common/foo_library:common_foo_library",
"//exporters/ostream:ostream_span_exporter",
"//sdk/src/trace",
],
)
9 changes: 3 additions & 6 deletions examples/simple/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
include_directories(${CMAKE_SOURCE_DIR}/exporters/ostream/include)

add_library(foo_library foo_library/foo_library.cc)
target_link_libraries(foo_library opentelemetry_exporter_ostream_span
${CMAKE_THREAD_LIBS_INIT} opentelemetry_api)

add_executable(example_simple main.cc)
target_link_libraries(example_simple ${CMAKE_THREAD_LIBS_INIT} foo_library
opentelemetry_trace)
target_link_libraries(
example_simple ${CMAKE_THREAD_LIBS_INIT} common_foo_library
opentelemetry_trace opentelemetry_exporter_ostream_span)
Loading

0 comments on commit af75379

Please sign in to comment.