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

tools: API boosting support for renames. #9442

Merged
merged 6 commits into from
Dec 26, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 2 additions & 2 deletions tools/api_boost/api_boost.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ def ApiBoostTree(target_paths,
file_paths)
# Apply Clang replacements before header fixups, since the replacements
# are all relative to the original file.
for prefix in target_paths:
sp.run(['clang-apply-replacements', PrefixDirectory(prefix)], check=True)
for prefix_dir in set(map(PrefixDirectory, target_paths)):
sp.run(['clang-apply-replacements', prefix_dir], check=True)
# Fixup headers.
p.map(RewriteIncludes, zip(file_paths, api_includes))
finally:
Expand Down
5 changes: 4 additions & 1 deletion tools/api_boost/api_boost_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
map(lambda x: TestCase(*x), [
('elaborated_type', 'ElaboratedTypeLoc type upgrades'),
('using_decl', 'UsingDecl upgrades for named types'),
('rename', 'Annotation-based renaming'),
('decl_ref_expr', 'DeclRefExpr upgrades for named constants'),
]))

Expand Down Expand Up @@ -63,7 +64,9 @@ def ShouldRunTest(test_name):

# Run API booster.
relpath_to_testdata = str(pathlib.Path(path).relative_to(pathlib.Path.cwd()))
api_boost.ApiBoostTree([relpath_to_testdata],
api_boost.ApiBoostTree([
os.path.join(relpath_to_testdata, test.name) for test in TESTS if ShouldRunTest(test.name)
],
generate_compilation_database=True,
build_api_booster=True,
debug_log=True,
Expand Down
16 changes: 14 additions & 2 deletions tools/api_boost/testdata/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,25 @@ envoy_package()
envoy_cc_library(
name = "decl_ref_expr",
srcs = ["decl_ref_expr.cc"],
deps = ["@envoy_api//envoy/config/overload/v2alpha:pkg_cc_proto"],
deps = [
"@envoy_api//envoy/api/v2:pkg_cc_proto",
"@envoy_api//envoy/config/overload/v2alpha:pkg_cc_proto",
],
)

envoy_cc_library(
name = "elaborated_type",
srcs = ["elaborated_type.cc"],
deps = ["@envoy_api//envoy/config/overload/v2alpha:pkg_cc_proto"],
deps = [
"@envoy_api//envoy/api/v2:pkg_cc_proto",
"@envoy_api//envoy/config/overload/v2alpha:pkg_cc_proto",
],
)

envoy_cc_library(
name = "rename",
srcs = ["rename.cc"],
deps = ["@envoy_api//envoy/api/v2/route:pkg_cc_proto"],
)

envoy_cc_library(
Expand Down
7 changes: 7 additions & 0 deletions tools/api_boost/testdata/decl_ref_expr.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "envoy/api/v2/cds.pb.h"
#include "envoy/config/overload/v2alpha/overload.pb.h"

#define ASSERT(x) static_cast<void>(x)

using envoy::config::overload::v2alpha::Trigger;

class ThresholdTriggerImpl {
Expand All @@ -17,5 +20,9 @@ class ThresholdTriggerImpl {
default:
break;
}
envoy::config::overload::v2alpha::ThresholdTrigger::default_instance();
ASSERT(envoy::config::overload::v2alpha::Trigger::kThreshold == Trigger::kThreshold);
envoy::api::v2::Cluster_LbPolicy_Name(0);
static_cast<void>(envoy::api::v2::Cluster::ORIGINAL_DST_LB);
}
};
7 changes: 7 additions & 0 deletions tools/api_boost/testdata/decl_ref_expr.cc.gold
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "envoy/api/v3alpha/cds.pb.h"
#include "envoy/config/overload/v3alpha/overload.pb.h"

#define ASSERT(x) static_cast<void>(x)

using envoy::config::overload::v3alpha::Trigger;

class ThresholdTriggerImpl {
Expand All @@ -17,5 +20,9 @@ public:
default:
break;
}
envoy::config::overload::v3alpha::ThresholdTrigger::default_instance();
ASSERT(envoy::config::overload::v3alpha::Trigger::kThreshold == Trigger::kThreshold);
envoy::api::v3alpha::Cluster_LbPolicy_Name(0);
static_cast<void>(envoy::api::v3alpha::Cluster::ORIGINAL_DST_LB);
}
};
2 changes: 2 additions & 0 deletions tools/api_boost/testdata/elaborated_type.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "envoy/api/v2/cds.pb.h"
#include "envoy/config/overload/v2alpha/overload.pb.h"

class ThresholdTriggerImpl {
public:
ThresholdTriggerImpl(const envoy::config::overload::v2alpha::ThresholdTrigger& /*config*/) {}
void someMethod(envoy::api::v2::Cluster_LbPolicy) {}
};
2 changes: 2 additions & 0 deletions tools/api_boost/testdata/elaborated_type.cc.gold
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "envoy/api/v3alpha/cds.pb.h"
#include "envoy/config/overload/v3alpha/overload.pb.h"

class ThresholdTriggerImpl {
public:
ThresholdTriggerImpl(const envoy::config::overload::v3alpha::ThresholdTrigger& /*config*/) {}
void someMethod(envoy::api::v3alpha::Cluster_LbPolicy) {}
};
7 changes: 7 additions & 0 deletions tools/api_boost/testdata/rename.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "envoy/api/v2/route/route.pb.h"

void test() {
envoy::api::v2::route::RouteAction route_action;
route_action.host_rewrite();
route_action.set_host_rewrite("blah");
}
7 changes: 7 additions & 0 deletions tools/api_boost/testdata/rename.cc.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "envoy/api/v3alpha/route/route.pb.h"

void test() {
envoy::api::v3alpha::route::RouteAction route_action;
route_action.host_rewrite_literal();
route_action.set_host_rewrite_literal("blah");
}
2 changes: 1 addition & 1 deletion tools/check_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"./source/extensions/filters/http/squash/squash_filter.cc",
"./source/server/http/admin.h", "./source/server/http/admin.cc",
"./tools/clang_tools/api_booster/main.cc",
"./tools/clang_tools/api_booster/proto_cxx_utils.h")
"./tools/clang_tools/api_booster/proto_cxx_utils.cc")

# Only one C++ file should instantiate grpc_init
GRPC_INIT_WHITELIST = ("./source/common/grpc/google_grpc_context.cc")
Expand Down
6 changes: 5 additions & 1 deletion tools/clang_tools/api_booster/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ clang_tools_cc_binary(

clang_tools_cc_library(
name = "proto_cxx_utils_lib",
srcs = ["proto_cxx_utils.cc"],
hdrs = ["proto_cxx_utils.h"],
deps = ["@com_google_absl//absl/strings"],
deps = [
"@com_google_absl//absl/strings",
"@com_google_absl//absl/types:optional",
],
)

clang_tools_cc_test(
Expand Down
Loading