Commit 1b3a0c16 authored by Adam Cozzette's avatar Adam Cozzette

Auto-generate well_known_types_embed.cc

Until now this file was just checked into the repo, but actually it
should be generated from any.js, struct.js, and timestamp.js. This
change updates the build system to make this happen. To make it work I
also had to remove some C++11 features from embed.cc.
parent f39cf88a
...@@ -47,6 +47,7 @@ any_test.pb.* ...@@ -47,6 +47,7 @@ any_test.pb.*
map*unittest.pb.* map*unittest.pb.*
unittest*.pb.* unittest*.pb.*
cpp_test*.pb.* cpp_test*.pb.*
src/google/protobuf/compiler/js/well_known_types_embed.cc
src/google/protobuf/util/**/*.pb.cc src/google/protobuf/util/**/*.pb.cc
src/google/protobuf/util/**/*.pb.h src/google/protobuf/util/**/*.pb.h
...@@ -60,6 +61,7 @@ python/build/ ...@@ -60,6 +61,7 @@ python/build/
python/google/protobuf/compiler/ python/google/protobuf/compiler/
python/google/protobuf/util/ python/google/protobuf/util/
src/js_embed
src/protoc src/protoc
src/unittest_proto_middleman src/unittest_proto_middleman
......
...@@ -94,6 +94,18 @@ set(libprotoc_files ...@@ -94,6 +94,18 @@ set(libprotoc_files
${protobuf_source_dir}/src/google/protobuf/compiler/zip_writer.cc ${protobuf_source_dir}/src/google/protobuf/compiler/zip_writer.cc
) )
set(js_well_known_types_sources,
${protobuf_source_dir}/src/google/protobuf/compiler/js/well_known_types/any.js
${protobuf_source_dir}/src/google/protobuf/compiler/js/well_known_types/struct.js
${protobuf_source_dir}/src/google/protobuf/compiler/js/well_known_types/timestamp.js
)
add_executable(js_embed ${protobuf_source_dir}/src/google/protobuf/compiler/js/embed.cc)
add_custom_command(
OUTPUT ${protobuf_source_dir}/src/google/protobuf/compiler/js/well_known_types_embed.cc
DEPENDS js_embed ${js_well_known_types_sources}
COMMAND js_embed ${js_well_known_types_sources} > ${protobuf_source_dir}/src/google/protobuf/compiler/js/well_known_types_embed.cc
)
add_library(libprotoc ${protobuf_SHARED_OR_STATIC} add_library(libprotoc ${protobuf_SHARED_OR_STATIC}
${libprotoc_files}) ${libprotoc_files})
target_link_libraries(libprotoc libprotobuf) target_link_libraries(libprotoc libprotobuf)
......
...@@ -483,10 +483,20 @@ libprotoc_la_SOURCES = \ ...@@ -483,10 +483,20 @@ libprotoc_la_SOURCES = \
google/protobuf/compiler/csharp/csharp_wrapper_field.cc \ google/protobuf/compiler/csharp/csharp_wrapper_field.cc \
google/protobuf/compiler/csharp/csharp_wrapper_field.h google/protobuf/compiler/csharp/csharp_wrapper_field.h
bin_PROGRAMS = protoc bin_PROGRAMS = protoc js_embed
protoc_LDADD = $(PTHREAD_LIBS) libprotobuf.la libprotoc.la protoc_LDADD = $(PTHREAD_LIBS) libprotobuf.la libprotoc.la
protoc_SOURCES = google/protobuf/compiler/main.cc protoc_SOURCES = google/protobuf/compiler/main.cc
# The special JS code for the well-known types is linked into the compiler via
# well_known_types_embed.cc, which is generated from .js source files.
js_embed_SOURCES = google/protobuf/compiler/js/embed.cc
js_well_known_types_sources = \
google/protobuf/compiler/js/well_known_types/any.js \
google/protobuf/compiler/js/well_known_types/struct.js \
google/protobuf/compiler/js/well_known_types/timestamp.js
google/protobuf/compiler/js/well_known_types_embed.cc: js_embed$(EXEEXT) $(js_well_known_types_sources)
./js_embed$(EXEEXT) $(js_well_known_types_sources) > $@
# Tests ============================================================== # Tests ==============================================================
protoc_inputs = \ protoc_inputs = \
...@@ -661,7 +671,7 @@ protoc_outputs = \ ...@@ -661,7 +671,7 @@ protoc_outputs = \
google/protobuf/util/message_differencer_unittest.pb.cc \ google/protobuf/util/message_differencer_unittest.pb.cc \
google/protobuf/util/message_differencer_unittest.pb.h google/protobuf/util/message_differencer_unittest.pb.h
BUILT_SOURCES = $(protoc_outputs) BUILT_SOURCES = $(protoc_outputs) google/protobuf/compiler/js/well_known_types_embed.cc
if USE_EXTERNAL_PROTOC if USE_EXTERNAL_PROTOC
......
...@@ -48,7 +48,8 @@ static char ToDecimalDigit(int num) { ...@@ -48,7 +48,8 @@ static char ToDecimalDigit(int num) {
static std::string CEscape(const std::string& str) { static std::string CEscape(const std::string& str) {
std::string dest; std::string dest;
for (unsigned char ch : str) { for (int i = 0; i < str.size(); ++i) {
unsigned char ch = str[i];
switch (ch) { switch (ch) {
case '\n': dest += "\\n"; break; case '\n': dest += "\\n"; break;
case '\r': dest += "\\r"; break; case '\r': dest += "\\r"; break;
...@@ -96,18 +97,16 @@ static void AddFile(const char* name, std::basic_ostream<char>* out) { ...@@ -96,18 +97,16 @@ static void AddFile(const char* name, std::basic_ostream<char>* out) {
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
auto& out = std::cout; std::cout << "#include "
"\"google/protobuf/compiler/js/well_known_types_embed.h\"\n";
out << "#include " std::cout << "struct FileToc well_known_types_js[] = {\n";
"\"google/protobuf/compiler/js/well_known_types_embed.h\"\n";
out << "struct FileToc well_known_types_js[] = {\n";
for (int i = 1; i < argc; i++) { for (int i = 1; i < argc; i++) {
AddFile(argv[i], &out); AddFile(argv[i], &std::cout);
} }
out << " {NULL, NULL} // Terminate the list.\n"; std::cout << " {NULL, NULL} // Terminate the list.\n";
out << "};\n"; std::cout << "};\n";
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment