通过修改命名空间绕过pb冲突

背景

在实际工作当中,很多服务框架本身会依赖pb,但是和tf的pb会发生冲突[通常是因为pb比较老或者版本有冲突导致],所以本文介绍如何通过修改名空间的方式来绕过pb冲突。

修改名空间&编译pb

修改名空间的脚本rename_namespace.sh

grep -rl "\<google\>" ./protobuf | grep -v Binary | xargs sed -i "s/\<google\>/new_namespace/g"
grep -rl "protobuf_google_2fprotobuf_2f" ./protobuf | grep -v Binary | xargs sed -i "s/protobuf_google_2fprotobuf_2f/protobuf_new_namespace_2fprotobuf_2f/g"
sed -i "s/m\/new_namespace/m\/google/g" ./protobuf/autogen.sh

mv protobuf/python/google protobuf/python/new_namespace
mv protobuf/python/compatibility_tests/v2.5.0/tests/google protobuf/python/compatibility_tests/v2.5.0/tests/new_namespace
mv protobuf/python/compatibility_tests/v2.5.0/protos/python/google protobuf/python/compatibility_tests/v2.5.0/protos/python/new_namespace
mv protobuf/python/compatibility_tests/v2.5.0/protos/src/proto/google protobuf/python/compatibility_tests/v2.5.0/protos/src/proto/new_namespace
mv protobuf/src/google protobuf/src/new_namespace
mv protobuf/ruby/src/main/java/google protobuf/ruby/src/main/java/new_namespace
mv protobuf/ruby/src/main/java/com/google protobuf/ruby/src/main/java/com/new_namespace
mv protobuf/ruby/lib/google protobuf/ruby/lib/new_namespace                                      
mv protobuf/ruby/ext/google protobuf/ruby/ext/new_namespace
mv protobuf/javanano/src/test/java/com/google protobuf/javanano/src/test/java/com/new_namespace
mv protobuf/javanano/src/main/java/com/google protobuf/javanano/src/main/java/com/new_namespace
mv protobuf/csharp/compatibility_tests/v3.0.0/protos/src/google protobuf/csharp/compatibility_tests/v3.0.0/protos/src/new_namespace
mv protobuf/php/ext/google protobuf/php/ext/new_namespace
mv protobuf/objectivec/google protobuf/objectivec/new_namespace
mv protobuf/java/util/src/test/proto/com/google protobuf/java/util/src/test/proto/com/new_namespace
mv protobuf/java/util/src/test/java/com/google protobuf/java/util/src/test/java/com/new_namespace
mv protobuf/java/util/src/main/java/com/google protobuf/java/util/src/main/java/com/new_namespace
mv protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/new_namespace
mv protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/new_namespace
mv protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/com/google protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/com/new_namespace
mv protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/new_namespace
mv protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/com/google protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/com/new_namespace
mv protobuf/java/core/src/test/proto/com/google protobuf/java/core/src/test/proto/com/new_namespace
mv protobuf/java/core/src/test/java/com/google protobuf/java/core/src/test/java/com/new_namespace
mv protobuf/java/core/src/main/java/com/google protobuf/java/core/src/main/java/com/new_namespace

修改tensorflow里面的命名空间

grep -rl "\<google\>" ./tensorflow/core | grep -v Binary | xargs sed -i "s/\<google\>/new_namespace/g"
grep -rl "\<google\>" ./tensorflow/contrib/decision_trees | grep -v Binary | xargs sed -i "s/\<google\>/new_namespace/g"
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容