|
|
|
@ -58,12 +58,18 @@ compile_edition_defaults = rule( |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
def _embed_edition_defaults_impl(ctx): |
|
|
|
|
if ctx.attr.encoding == "base64": |
|
|
|
|
args = "--encoding=base64" |
|
|
|
|
elif ctx.attr.encoding == "octal": |
|
|
|
|
args = "--encoding=octal" |
|
|
|
|
else: |
|
|
|
|
fail("Unknown encoding %s" % ctx.attr.encoding) |
|
|
|
|
ctx.actions.run_shell( |
|
|
|
|
outputs = [ctx.outputs.output], |
|
|
|
|
inputs = [ctx.file.defaults, ctx.file.template], |
|
|
|
|
tools = [ctx.executable._escape], |
|
|
|
|
command = """ |
|
|
|
|
DEFAULTS_RAW=$({escape} < {defaults}) |
|
|
|
|
DEFAULTS_RAW=$({escape} {args} < {defaults}) |
|
|
|
|
# Windows requires extra escaping. |
|
|
|
|
DEFAULTS_ESCAPED=$(echo $DEFAULTS_RAW | sed 's/\\\\/\\\\\\\\/g' || |
|
|
|
|
echo $DEFAULTS_RAW | sed 's/\\\\\\\\/\\\\\\\\\\\\\\\\/g') |
|
|
|
@ -72,6 +78,7 @@ def _embed_edition_defaults_impl(ctx): |
|
|
|
|
sed -i.bak \"s|{placeholder}|$DEFAULTS_ESCAPED|g\" {output} |
|
|
|
|
""".format( |
|
|
|
|
escape = ctx.executable._escape.path, |
|
|
|
|
args = args, |
|
|
|
|
defaults = ctx.file.defaults.path, |
|
|
|
|
template = ctx.file.template.path, |
|
|
|
|
output = ctx.outputs.output.path, |
|
|
|
@ -80,7 +87,7 @@ def _embed_edition_defaults_impl(ctx): |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
embed_edition_defaults = rule( |
|
|
|
|
doc = "genrule to embed edition defaults binary data into a template file using octal C-style escaping.", |
|
|
|
|
doc = "genrule to embed edition defaults binary data into a template file.", |
|
|
|
|
attrs = { |
|
|
|
|
"defaults": attr.label( |
|
|
|
|
mandatory = True, |
|
|
|
@ -102,6 +109,11 @@ embed_edition_defaults = rule( |
|
|
|
|
mandatory = True, |
|
|
|
|
doc = "The placeholder to replace with a serialized string in the template", |
|
|
|
|
), |
|
|
|
|
"encoding": attr.string( |
|
|
|
|
default = "octal", |
|
|
|
|
values = ["octal", "base64"], |
|
|
|
|
doc = "The encoding format to use for the binary data (octal or base64)", |
|
|
|
|
), |
|
|
|
|
"_escape": attr.label( |
|
|
|
|
default = "//src/google/protobuf/editions:internal_defaults_escape", |
|
|
|
|
executable = True, |
|
|
|
|