-
Notifications
You must be signed in to change notification settings - Fork 583
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce a NOP template for cc (#533)
Signed-off-by: Martin Conte Mac Donell <reflejo@gmail.com>
- Loading branch information
Showing
7 changed files
with
110 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
load("@bazel_skylib//rules:common_settings.bzl", "string_flag") | ||
|
||
config_setting( | ||
name = "windows_x86_64", | ||
values = {"cpu": "x64_windows"}, | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
string_flag( | ||
name = "template-flavor", | ||
build_setting_default = "", | ||
visibility = ["//visibility:public"], | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "ccnop", | ||
srcs = [ | ||
"file.go", | ||
"register.go", | ||
], | ||
importpath = "github.com/envoyproxy/protoc-gen-validate/templates/ccnop", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//templates/cc", | ||
"@com_github_lyft_protoc_gen_star//:protoc-gen-star", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package ccnop | ||
|
||
const headerFileTpl = `// Code generated by protoc-gen-validate | ||
// source: {{ .InputPath }} | ||
// DO NOT EDIT!!! | ||
#pragma once | ||
#include <string> | ||
#include "validate/validate.h" | ||
#include "{{ output .File ".h" }}" | ||
{{ range .Package.ProtoName.Split }} | ||
namespace {{ . }} { | ||
{{- end }} | ||
using std::string; | ||
{{ range .AllMessages }} | ||
extern inline bool Validate(__attribute__((unused)) const {{ class . }}& m, __attribute__((unused)) pgv::ValidationMsg* err) { return true; } | ||
{{ end }} | ||
{{ range .Package.ProtoName.Split -}} | ||
} // namespace | ||
{{ end }} | ||
#define X_{{ .Package.ProtoName.ScreamingSnakeCase }}_{{ .File.InputPath.BaseName | screaming_snake_case }}(X) \ | ||
{{ range .AllMessages -}} | ||
{{- if not (ignored .) -}} | ||
X({{class . }}) \ | ||
{{ end -}} | ||
{{ end }} | ||
` | ||
|
||
const moduleFileTpl = `// Code generated by protoc-gen-validate | ||
// source: {{ .InputPath }} | ||
// DO NOT EDIT!!! | ||
#include "{{ output .File ".validate.h" }}" | ||
namespace pgv { | ||
namespace validate { | ||
using std::string; | ||
{{ range .AllMessages }} | ||
{{- if not (ignored .) -}} | ||
{{- if not (disabled .) -}} | ||
pgv::Validator<{{ class . }}> {{ staticVarName . }}(static_cast<bool(*)(const {{ class .}}&, pgv::ValidationMsg*)>({{ package .}}::Validate)); | ||
{{- end -}} | ||
{{ end }} | ||
{{ end }} | ||
} // namespace validate | ||
} // namespace pgv | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package ccnop | ||
|
||
import ( | ||
"text/template" | ||
|
||
"github.com/envoyproxy/protoc-gen-validate/templates/cc" | ||
pgs "github.com/lyft/protoc-gen-star" | ||
) | ||
|
||
func RegisterModule(tpl *template.Template, params pgs.Parameters) { | ||
cc.RegisterModule(tpl, params) | ||
template.Must(tpl.Parse(moduleFileTpl)) | ||
} | ||
|
||
func RegisterHeader(tpl *template.Template, params pgs.Parameters) { | ||
cc.RegisterHeader(tpl, params) | ||
template.Must(tpl.Parse(headerFileTpl)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters