forked from tensorflow/tensorflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support a separate namespace for the protobuf library (tensorflow#3741)
* Added protobuf renaming script * Post-process protobuf generated source files to use new namespace * Removed backup files * Updated protoc scripts for version renaming * Added more disclaimers to rename_protobuf
- Loading branch information
1 parent
f0cff57
commit 5b6dbfe
Showing
5 changed files
with
173 additions
and
16 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
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,89 @@ | ||
#!/bin/bash | ||
|
||
# Copyright 2015 The TensorFlow Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ============================================================================== | ||
|
||
# This script modifies the downloaded protobuf library and the TensorFlow source | ||
# to put all protobuf-related symbols into the google::protobuf3 namespace | ||
# instead of the default google::protobuf. This is necessary to work around | ||
# linking issues for applications that use protobuf v2 already, and want to | ||
# adopt TensorFlow, since otherwise the two libraries have duplicate function | ||
# symbols that clash. It also renames all the include paths to google/protobuf3 | ||
# throughout the protobuf and TensorFlow code. | ||
# This is a massive hack, and if possible it's recommended that you switch your | ||
# whole application to protobuf v3 so there's no mismatch with TensorFlow. There | ||
# are also no guarantees that this will continue to work with future versions of | ||
# protobuf or TensorFlow, or that it's a bulletproof solution for every | ||
# application. | ||
# | ||
# To use this script, run the following sequence: | ||
# tensorflow/contrib/makefile/download_dependencies.sh | ||
# tensorflow/contrib/makefile/rename_protobuf.sh | ||
# | ||
# You can then build the source as normal. For example on iOS: | ||
# tensorflow/contrib/makefile/compile_ios_protobuf.sh | ||
# tensorflow/contrib/makefile/compile_ios_tensorflow.sh | ||
# | ||
# Note that this script modifies the source code in-place, so once it's been run | ||
# it's no longer suitable for further manual modifications, since the difference | ||
# with the top of tree will already be large. | ||
|
||
mv tensorflow/contrib/makefile/downloads/protobuf/src/google/protobuf \ | ||
tensorflow/contrib/makefile/downloads/protobuf//src/google/protobuf3 | ||
|
||
# Rename protobuf #includes to use protobuf3. | ||
find . \ | ||
-type f \ | ||
\( -name "*.cc" -or -name "*.h" \) \ | ||
-exec sed -i '' \ | ||
's%#include \([<"]\)google/protobuf/%#include \1google/protobuf3/%' {} \; | ||
find . \ | ||
-type f \ | ||
-name "*.proto" \ | ||
-exec sed -i '' \ | ||
's%import \(.*\)\([<"]\)google/protobuf/%import \1\2google/protobuf3/%' {} \; | ||
|
||
# Rename the namespace mentions. | ||
find . \ | ||
-type f \ | ||
\( -name "*.cc" -or -name "*.h" \) \ | ||
-exec sed -i '' \ | ||
's%namespace protobuf\([^3]\)%namespace protobuf3\1%' {} \; | ||
find . \ | ||
-type f \ | ||
\( -name "*.cc" -or -name "*.h" \) \ | ||
-exec sed -i '' \ | ||
's%protobuf::%protobuf3::%g' {} \; | ||
sed -i '' 's%::google::protobuf;%google::protobuf3;%' \ | ||
tensorflow/core/platform/default/protobuf.h | ||
|
||
# Fix up a couple of special build scripts that look for particular files. | ||
sed -i '' 's%src/google/protobuf/message.cc%src/google/protobuf3/message.cc%' \ | ||
tensorflow/contrib/makefile/downloads/protobuf/configure.ac | ||
sed -i '' 's%src/google/protobuf/stubs/common.h%src/google/protobuf3/stubs/common.h%' \ | ||
tensorflow/contrib/makefile/downloads/protobuf/autogen.sh | ||
|
||
# Update the locations within the protobuf makefile. | ||
sed -i '' 's%google/protobuf/%google/protobuf3/%g' \ | ||
tensorflow/contrib/makefile/downloads/protobuf/src/Makefile.am | ||
|
||
# Make sure protoc can find the new google/protobuf3 paths by putting them at | ||
# the root directory. | ||
cp -r tensorflow/contrib/makefile/downloads/protobuf/src/google . | ||
|
||
# Update the protobuf commands used in the makefile. | ||
sed -i '' 's%$(PROTOC) $(PROTOCFLAGS) $< --cpp_out $(PROTOGENDIR)%tensorflow/contrib/makefile/rename_protoc.sh $(PROTOC) $(PROTOCFLAGS) $< --cpp_out $(PROTOGENDIR)%' tensorflow/contrib/makefile/Makefile | ||
sed -i '' 's%$(PROTOC) $(PROTOCFLAGS) $< --cpp_out $(HOST_GENDIR)%tensorflow/contrib/makefile/rename_protoc.sh $(PROTOC) $(PROTOCFLAGS) $< --cpp_out $(HOST_GENDIR)%' tensorflow/contrib/makefile/Makefile | ||
sed -i '' 's%$(PROTO_TEXT) \\%tensorflow/contrib/makefile/rename_prototext.sh $(PROTO_TEXT) \\%' tensorflow/contrib/makefile/Makefile |
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,34 @@ | ||
#!/bin/bash -e -x | ||
|
||
# Copyright 2015 The TensorFlow Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ============================================================================== | ||
|
||
PROTO_C_COMMAND=$1 | ||
shift | ||
${PROTO_C_COMMAND} $* | ||
|
||
# Assumes that the order is always <some flags> *.protofile --cpp_out dir | ||
PROTO_LAST_THREE_ARGS=(${@: -3}) | ||
PROTO_FILE=${PROTO_LAST_THREE_ARGS[0]} | ||
CC_FILE=${PROTO_FILE%.proto}.pb.cc | ||
H_FILE=${PROTO_FILE%.proto}.pb.h | ||
GEN_DIR=${PROTO_LAST_THREE_ARGS[2]} | ||
GEN_CC=${GEN_DIR}/${CC_FILE} | ||
GEN_H=${GEN_DIR}/${H_FILE} | ||
|
||
sed -i '' 's%protobuf::%protobuf3::%g' ${GEN_CC} | ||
sed -i '' 's%protobuf::%protobuf3::%g' ${GEN_H} | ||
sed -i '' 's%google_2fprotobuf3_2f%google_2fprotobuf_2f%g' ${GEN_CC} | ||
sed -i '' 's%google_2fprotobuf3_2f%google_2fprotobuf_2f%g' ${GEN_H} |
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,34 @@ | ||
#!/bin/bash -e -x | ||
|
||
# Copyright 2015 The TensorFlow Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ============================================================================== | ||
|
||
PROTO_TEXT_COMMAND=$1 | ||
shift | ||
${PROTO_TEXT_COMMAND} $* | ||
|
||
# Assumes a fixed order for the arguments. | ||
PROTO_LAST_FOUR_ARGS=(${@: -4}) | ||
PROTO_FILE=${PROTO_LAST_FOUR_ARGS[3]} | ||
CC_FILE=${PROTO_FILE%.proto}.pb_text.cc | ||
H_FILE=${PROTO_FILE%.proto}.pb_text.h | ||
GEN_DIR=${PROTO_LAST_FOUR_ARGS[0]} | ||
GEN_CC=${GEN_DIR}/${CC_FILE#tensorflow/core} | ||
GEN_H=${GEN_DIR}/${H_FILE#tensorflow/core} | ||
|
||
sed -i '' 's%protobuf::%protobuf3::%g' ${GEN_CC} | ||
sed -i '' 's%protobuf::%protobuf3::%g' ${GEN_H} | ||
sed -i '' 's%google_2fprotobuf3_2f%google_2fprotobuf_2f%g' ${GEN_CC} | ||
sed -i '' 's%google_2fprotobuf3_2f%google_2fprotobuf_2f%g' ${GEN_H} |