Commit fb15862b authored by Adam Cozzette's avatar Adam Cozzette Committed by GitHub

Merge pull request #2517 from acozzette/js-embed

Auto-generate well_known_types_embed.cc
parents f39cf88a 98d89d42
......@@ -47,6 +47,7 @@ any_test.pb.*
map*unittest.pb.*
unittest*.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.h
......@@ -60,6 +61,7 @@ python/build/
python/google/protobuf/compiler/
python/google/protobuf/util/
src/js_embed
src/protoc
src/unittest_proto_middleman
......
......@@ -94,6 +94,18 @@ set(libprotoc_files
${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}
${libprotoc_files})
target_link_libraries(libprotoc libprotobuf)
......
......@@ -214,4 +214,5 @@ target_link_libraries(lite-arena-test libprotobuf-lite gmock_main)
add_custom_target(check
COMMAND tests
DEPENDS tests test_plugin
WORKING_DIRECTORY ${protobuf_source_dir})
......@@ -483,10 +483,20 @@ libprotoc_la_SOURCES = \
google/protobuf/compiler/csharp/csharp_wrapper_field.cc \
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_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 ==============================================================
protoc_inputs = \
......@@ -661,7 +671,7 @@ protoc_outputs = \
google/protobuf/util/message_differencer_unittest.pb.cc \
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
......
......@@ -48,7 +48,8 @@ static char ToDecimalDigit(int num) {
static std::string CEscape(const std::string& str) {
std::string dest;
for (unsigned char ch : str) {
for (int i = 0; i < str.size(); ++i) {
unsigned char ch = str[i];
switch (ch) {
case '\n': dest += "\\n"; break;
case '\r': dest += "\\r"; break;
......@@ -96,18 +97,16 @@ static void AddFile(const char* name, std::basic_ostream<char>* out) {
}
int main(int argc, char *argv[]) {
auto& out = std::cout;
out << "#include "
"\"google/protobuf/compiler/js/well_known_types_embed.h\"\n";
out << "struct FileToc well_known_types_js[] = {\n";
std::cout << "#include "
"\"google/protobuf/compiler/js/well_known_types_embed.h\"\n";
std::cout << "struct FileToc well_known_types_js[] = {\n";
for (int i = 1; i < argc; i++) {
AddFile(argv[i], &out);
AddFile(argv[i], &std::cout);
}
out << " {NULL, NULL} // Terminate the list.\n";
out << "};\n";
std::cout << " {NULL, NULL} // Terminate the list.\n";
std::cout << "};\n";
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