Skip to content

Commit

Permalink
test: link test-only version linkstamp (envoyproxy#12171)
Browse files Browse the repository at this point in the history
* split version_linkstamp to another bazel target
* add test_version_linkstamp which is static and link it to tests

All tests except those take envoy binary directly (i.e. //test/exe/...) will be cached more efficiently, especially in a manual_stamp defined environment such as Windows.

Signed-off-by: Lizan Zhou <lizan@tetrate.io>
Signed-off-by: scheler <santosh.cheler@appdynamics.com>
  • Loading branch information
lizan authored and scheler committed Aug 4, 2020
1 parent 39e5c5f commit 827242a
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 29 deletions.
5 changes: 0 additions & 5 deletions bazel/envoy_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ def envoy_cc_library(
external_deps = [],
tcmalloc_dep = None,
repository = "",
linkstamp = None,
tags = [],
deps = [],
strip_include_prefix = None,
Expand Down Expand Up @@ -122,10 +121,6 @@ def envoy_cc_library(
include_prefix = envoy_include_prefix(native.package_name()),
alwayslink = 1,
linkstatic = envoy_linkstatic(),
linkstamp = select({
repository + "//bazel:windows_x86_64": None,
"//conditions:default": linkstamp,
}),
strip_include_prefix = strip_include_prefix,
)

Expand Down
6 changes: 6 additions & 0 deletions bazel/envoy_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def envoy_cc_fuzz_test(
name = test_lib_name,
deps = deps + envoy_stdlib_deps() + [
repository + "//test/fuzz:fuzz_runner_lib",
repository + "//test/test_common:test_version_linkstamp",
],
repository = repository,
tags = tags,
Expand Down Expand Up @@ -179,6 +180,7 @@ def envoy_cc_test(
malloc = tcmalloc_external_dep(repository),
deps = envoy_stdlib_deps() + deps + [envoy_external_dep_path(dep) for dep in external_deps + ["googletest"]] + [
repository + "//test:main",
repository + "//test/test_common:test_version_linkstamp",
],
# from https://github.com/google/googletest/blob/6e1970e2376c14bf658eb88f655a054030353f9f/googlemock/src/gmock.cc#L51
# 2 - by default, mocks act as StrictMocks.
Expand Down Expand Up @@ -232,12 +234,16 @@ def envoy_cc_test_library(
def envoy_cc_test_binary(
name,
tags = [],
deps = [],
**kargs):
envoy_cc_binary(
name,
testonly = 1,
linkopts = _envoy_test_linkopts(),
tags = tags + ["compilation_db_dep"],
deps = deps + [
"@envoy//test/test_common:test_version_linkstamp",
],
**kargs
)

Expand Down
44 changes: 26 additions & 18 deletions source/common/version/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load(
"//bazel:envoy_build_system.bzl",
"envoy_basic_cc_library",
"envoy_cc_library",
"envoy_package",
"envoy_select_boringssl",
Expand All @@ -14,11 +15,12 @@ genrule(
srcs = ["//:VERSION"],
outs = ["version_number.h"],
cmd = """echo "#define BUILD_VERSION_NUMBER \\"$$(cat $<)\\"" >$@""",
visibility = ["//visibility:private"],
)

genrule(
name = "generate_version_linkstamp",
outs = ["lib/version_linkstamp.h"],
outs = ["manual_linkstamp.cc"],
cmd = select({
# Only iOS builds typically follow this logic, OS/X is built as a normal binary
"//bazel:apple": "$(location :generate_version_linkstamp.sh) Library >> $@",
Expand All @@ -29,12 +31,7 @@ genrule(
# Used here because generate_version_linkstamp.sh depends on the workspace status files.
stamp = 1,
tools = [":generate_version_linkstamp.sh"],
)

genrule(
name = "generate_version_linkstamp_empty",
outs = ["empty/version_linkstamp.h"],
cmd = """>$@""",
visibility = ["//visibility:private"],
)

envoy_cc_library(
Expand All @@ -52,24 +49,35 @@ envoy_cc_library(
envoy_cc_library(
name = "version_lib",
srcs = ["version.cc"],
hdrs = select({
"//bazel:manual_stamp": [":generate_version_linkstamp"],
# By default the header file is empty.
# This is done so that the definitions linked via the linkstamp rule don't cause collisions.
"//conditions:default": [":generate_version_linkstamp_empty"],
}),
copts = envoy_select_boringssl(
["-DENVOY_SSL_VERSION=\\\"BoringSSL-FIPS\\\""],
["-DENVOY_SSL_VERSION=\\\"BoringSSL\\\""],
),
linkstamp = "version_linkstamp.cc",
strip_include_prefix = select({
"//bazel:manual_stamp": "lib",
"//conditions:default": "empty",
}),
deps = [
":version_includes",
"//source/common/common:macros",
"//source/common/protobuf:utility_lib",
],
)

envoy_basic_cc_library(
name = "manual_version_linkstamp",
srcs = [":generate_version_linkstamp"],
visibility = ["//visibility:private"],
)

envoy_basic_cc_library(
name = "version_linkstamp",
linkstamp = select({
"//bazel:manual_stamp": None,
"//conditions:default": "version_linkstamp.cc",
}),
# Linking this library makes build cache inefficient, limiting this to //source/exe package only.
# Tests are linked with //test/test_common:test_version_linkstamp.
visibility = ["//source/exe:__pkg__"],
deps = select({
"//bazel:manual_stamp": [":manual_version_linkstamp"],
"//conditions:default": [],
}),
alwayslink = 1,
)
1 change: 0 additions & 1 deletion source/common/version/version.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "common/common/fmt.h"
#include "common/common/macros.h"
#include "common/protobuf/utility.h"
#include "common/version/version_linkstamp.h"

#include "absl/strings/numbers.h"
#include "absl/strings/str_split.h"
Expand Down
15 changes: 11 additions & 4 deletions source/exe/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ alias(
envoy_cc_binary(
name = "envoy-static",
stamped = True,
deps = ["envoy_main_entry_lib"],
deps = [":envoy_main_entry_lib"],
)

envoy_cc_library(
Expand Down Expand Up @@ -56,7 +56,7 @@ envoy_cc_library(
)

envoy_cc_library(
name = "envoy_main_common_lib",
name = "main_common_lib",
srcs = ["main_common.cc"],
hdrs = ["main_common.h"],
deps = [
Expand All @@ -80,6 +80,14 @@ envoy_cc_library(
}),
)

envoy_cc_library(
name = "envoy_main_common_lib",
deps = [
":main_common_lib",
"//source/common/version:version_linkstamp",
],
)

envoy_cc_library(
name = "envoy_common_with_core_extensions_lib",
deps = [
Expand All @@ -96,10 +104,9 @@ envoy_cc_library(

envoy_cc_library(
name = "envoy_main_common_with_core_extensions_lib",
srcs = ["main_common.cc"],
hdrs = ["main_common.h"],
deps = [
":envoy_common_with_core_extensions_lib",
":main_common_lib",
":platform_impl_lib",
":process_wide_lib",
"//source/common/api:os_sys_calls_lib",
Expand Down
2 changes: 1 addition & 1 deletion test/exe/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ envoy_cc_test(
tags = ["fails_on_windows"],
deps = [
"//source/common/api:api_lib",
"//source/exe:envoy_main_common_lib",
"//source/exe:main_common_lib",
"//test/mocks/runtime:runtime_mocks",
"//test/test_common:contention_lib",
"//test/test_common:environment_lib",
Expand Down
6 changes: 6 additions & 0 deletions test/test_common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,9 @@ envoy_cc_test(
":utility_lib",
],
)

envoy_basic_cc_library(
name = "test_version_linkstamp",
srcs = ["test_version_linkstamp.cc"],
alwayslink = 1,
)
6 changes: 6 additions & 0 deletions test/test_common/test_version_linkstamp.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// NOLINT(namespace-envoy)
extern const char build_scm_revision[];
extern const char build_scm_status[];

const char build_scm_revision[] = "0";
const char build_scm_status[] = "test";

0 comments on commit 827242a

Please sign in to comment.