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

Auto-generate well_known_types_embed.cc #2517

Merged
merged 2 commits into from
Dec 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -60,6 +61,7 @@ python/build/
python/google/protobuf/compiler/
python/google/protobuf/util/

src/js_embed
src/protoc
src/unittest_proto_middleman

Expand Down
12 changes: 12 additions & 0 deletions cmake/libprotoc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions cmake/tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,5 @@ target_link_libraries(lite-arena-test libprotobuf-lite gmock_main)

add_custom_target(check
COMMAND tests
DEPENDS tests test_plugin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends on yourself? I think test_plugin there will be enough.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering about that actually. Adding tests as a dependency did not seem to be empirically necessary to make the tests pass, but it seems like it ought to be there. If we leave it out, is CMake smart enough to determine that it should be a dependency since it appears as part of COMMAND?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought a little more and probably agree with your decision.
I added this command as an alias for compatibility with similar check for autotools project, but I forgot to specify dependencies.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, thanks. I'll just leave in the tests dependency then; if it turns out to be unnecessary then it won't cause any harm anyway.

WORKING_DIRECTORY ${protobuf_source_dir})
14 changes: 12 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 = \
Expand Down Expand Up @@ -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

Expand Down
17 changes: 8 additions & 9 deletions src/google/protobuf/compiler/js/embed.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Loading