Feng Xiao | 4333edb | 2015-05-31 02:28:34 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | # This script copies source file lists from src/Makefile.am to cmake files. |
| 4 | |
| 5 | get_variable_value() { |
Jisi Liu | d19604f | 2015-06-17 17:37:58 -0700 | [diff] [blame] | 6 | local FILENAME=$1 |
| 7 | local VARNAME=$2 |
Feng Xiao | 4333edb | 2015-05-31 02:28:34 -0700 | [diff] [blame] | 8 | awk " |
| 9 | BEGIN { start = 0; } |
| 10 | /^$VARNAME =/ { start = 1; } |
| 11 | { if (start) { print \$0; } } |
| 12 | /\\\\\$/ { next; } |
| 13 | { start = 0; } |
| 14 | " $FILENAME \ |
| 15 | | sed "s/^$VARNAME =//" \ |
| 16 | | sed "s/[ \\]//g" \ |
| 17 | | grep -v "^\\$" \ |
| 18 | | grep -v "^$" \ |
| 19 | | LC_ALL=C sort | uniq |
| 20 | } |
| 21 | |
Jisi Liu | d19604f | 2015-06-17 17:37:58 -0700 | [diff] [blame] | 22 | get_header_files() { |
| 23 | get_variable_value $@ | grep '\.h$' |
| 24 | } |
| 25 | |
Feng Xiao | 4333edb | 2015-05-31 02:28:34 -0700 | [diff] [blame] | 26 | get_source_files() { |
| 27 | get_variable_value $@ | grep "cc$" |
| 28 | } |
| 29 | |
Bo Yang | ff7bdad | 2015-08-23 10:45:14 -0700 | [diff] [blame] | 30 | get_proto_files_blacklisted() { |
| 31 | get_proto_files $@ | sed '/^google\/protobuf\/unittest_enormous_descriptor.proto$/d' |
| 32 | } |
| 33 | |
Feng Xiao | 4333edb | 2015-05-31 02:28:34 -0700 | [diff] [blame] | 34 | get_proto_files() { |
| 35 | get_variable_value $@ | grep "pb.cc$" | sed "s/pb.cc/proto/" |
| 36 | } |
| 37 | |
Jisi Liu | d19604f | 2015-06-17 17:37:58 -0700 | [diff] [blame] | 38 | sort_files() { |
| 39 | for FILE in $@; do |
| 40 | echo $FILE |
| 41 | done | LC_ALL=C sort | uniq |
| 42 | } |
| 43 | |
| 44 | MAKEFILE=src/Makefile.am |
| 45 | |
| 46 | [ -f "$MAKEFILE" ] || { |
| 47 | echo "Cannot find: $MAKEFILE" |
| 48 | exit 1 |
| 49 | } |
| 50 | |
| 51 | # Extract file lists from src/Makefile.am |
| 52 | GZHEADERS=$(get_variable_value $MAKEFILE GZHEADERS) |
| 53 | HEADERS=$(get_variable_value $MAKEFILE nobase_include_HEADERS) |
| 54 | PUBLIC_HEADERS=$(sort_files $GZHEADERS $HEADERS) |
| 55 | LIBPROTOBUF_LITE_SOURCES=$(get_source_files $MAKEFILE libprotobuf_lite_la_SOURCES) |
| 56 | LIBPROTOBUF_SOURCES=$(get_source_files $MAKEFILE libprotobuf_la_SOURCES) |
| 57 | LIBPROTOC_SOURCES=$(get_source_files $MAKEFILE libprotoc_la_SOURCES) |
| 58 | LITE_PROTOS=$(get_proto_files $MAKEFILE protoc_lite_outputs) |
Jisi Liu | d19604f | 2015-06-17 17:37:58 -0700 | [diff] [blame] | 59 | PROTOS=$(get_proto_files $MAKEFILE protoc_outputs) |
Bo Yang | ff7bdad | 2015-08-23 10:45:14 -0700 | [diff] [blame] | 60 | PROTOS_BLACKLISTED=$(get_proto_files_blacklisted $MAKEFILE protoc_outputs) |
Jisi Liu | d19604f | 2015-06-17 17:37:58 -0700 | [diff] [blame] | 61 | WKT_PROTOS=$(get_variable_value $MAKEFILE nobase_dist_proto_DATA) |
| 62 | COMMON_TEST_SOURCES=$(get_source_files $MAKEFILE COMMON_TEST_SOURCES) |
Feng Xiao | b17ec3c | 2015-08-23 17:50:38 -0700 | [diff] [blame] | 63 | COMMON_LITE_TEST_SOURCES=$(get_source_files $MAKEFILE COMMON_LITE_TEST_SOURCES) |
Jisi Liu | d19604f | 2015-06-17 17:37:58 -0700 | [diff] [blame] | 64 | TEST_SOURCES=$(get_source_files $MAKEFILE protobuf_test_SOURCES) |
| 65 | LITE_TEST_SOURCES=$(get_source_files $MAKEFILE protobuf_lite_test_SOURCES) |
Feng Xiao | b17ec3c | 2015-08-23 17:50:38 -0700 | [diff] [blame] | 66 | LITE_ARENA_TEST_SOURCES=$(get_source_files $MAKEFILE protobuf_lite_arena_test_SOURCES) |
Jisi Liu | 7a0c431 | 2015-06-18 16:45:27 -0700 | [diff] [blame] | 67 | TEST_PLUGIN_SOURCES=$(get_source_files $MAKEFILE test_plugin_SOURCES) |
Jisi Liu | d19604f | 2015-06-17 17:37:58 -0700 | [diff] [blame] | 68 | |
| 69 | ################################################################################ |
| 70 | # Update cmake files. |
| 71 | ################################################################################ |
| 72 | |
| 73 | CMAKE_DIR=cmake |
| 74 | EXTRACT_INCLUDES_BAT=cmake/extract_includes.bat.in |
| 75 | [ -d "$CMAKE_DIR" ] || { |
| 76 | echo "Cannot find: $CMAKE_DIR" |
| 77 | exit 1 |
| 78 | } |
| 79 | |
| 80 | [ -f "$EXTRACT_INCLUDES_BAT" ] || { |
| 81 | echo "Cannot find: $EXTRACT_INCLUDES_BAT" |
| 82 | exit 1 |
| 83 | } |
| 84 | |
| 85 | set_cmake_value() { |
| 86 | local FILENAME=$1 |
| 87 | local VARNAME=$2 |
| 88 | local PREFIX=$3 |
Feng Xiao | 4333edb | 2015-05-31 02:28:34 -0700 | [diff] [blame] | 89 | shift |
| 90 | shift |
| 91 | shift |
| 92 | awk -v values="$*" -v prefix="$PREFIX" " |
| 93 | BEGIN { start = 0; } |
| 94 | /^set\\($VARNAME/ { |
| 95 | start = 1; |
| 96 | print \$0; |
Feng Xiao | dffd542 | 2015-06-05 17:59:09 -0700 | [diff] [blame] | 97 | len = split(values, vlist, \" \"); |
| 98 | for (i = 1; i <= len; ++i) { |
Feng Xiao | 4333edb | 2015-05-31 02:28:34 -0700 | [diff] [blame] | 99 | printf(\" %s%s\\n\", prefix, vlist[i]); |
| 100 | } |
| 101 | next; |
| 102 | } |
| 103 | start && /^\\)/ { |
| 104 | start = 0; |
| 105 | } |
| 106 | !start { |
| 107 | print \$0; |
| 108 | } |
| 109 | " $FILENAME > /tmp/$$ |
| 110 | cp /tmp/$$ $FILENAME |
| 111 | } |
| 112 | |
Feng Xiao | 4333edb | 2015-05-31 02:28:34 -0700 | [diff] [blame] | 113 | |
| 114 | # Replace file lists in cmake files. |
Jisi Liu | d19604f | 2015-06-17 17:37:58 -0700 | [diff] [blame] | 115 | CMAKE_PREFIX="\${protobuf_source_dir}/src/" |
| 116 | set_cmake_value $CMAKE_DIR/libprotobuf-lite.cmake libprotobuf_lite_files $CMAKE_PREFIX $LIBPROTOBUF_LITE_SOURCES |
| 117 | set_cmake_value $CMAKE_DIR/libprotobuf.cmake libprotobuf_files $CMAKE_PREFIX $LIBPROTOBUF_SOURCES |
| 118 | set_cmake_value $CMAKE_DIR/libprotoc.cmake libprotoc_files $CMAKE_PREFIX $LIBPROTOC_SOURCES |
| 119 | set_cmake_value $CMAKE_DIR/tests.cmake lite_test_protos "" $LITE_PROTOS |
Bo Yang | ff7bdad | 2015-08-23 10:45:14 -0700 | [diff] [blame] | 120 | set_cmake_value $CMAKE_DIR/tests.cmake tests_protos "" $PROTOS_BLACKLISTED |
Jisi Liu | d19604f | 2015-06-17 17:37:58 -0700 | [diff] [blame] | 121 | set_cmake_value $CMAKE_DIR/tests.cmake common_test_files $CMAKE_PREFIX $COMMON_TEST_SOURCES |
Feng Xiao | b17ec3c | 2015-08-23 17:50:38 -0700 | [diff] [blame] | 122 | set_cmake_value $CMAKE_DIR/tests.cmake common_lite_test_files $CMAKE_PREFIX $COMMON_LITE_TEST_SOURCES |
Jisi Liu | d19604f | 2015-06-17 17:37:58 -0700 | [diff] [blame] | 123 | set_cmake_value $CMAKE_DIR/tests.cmake tests_files $CMAKE_PREFIX $TEST_SOURCES |
| 124 | set_cmake_value $CMAKE_DIR/tests.cmake lite_test_files $CMAKE_PREFIX $LITE_TEST_SOURCES |
Feng Xiao | b17ec3c | 2015-08-23 17:50:38 -0700 | [diff] [blame] | 125 | set_cmake_value $CMAKE_DIR/tests.cmake lite_arena_test_files $CMAKE_PREFIX $LITE_ARENA_TEST_SOURCES |
Feng Xiao | 4333edb | 2015-05-31 02:28:34 -0700 | [diff] [blame] | 126 | |
| 127 | # Generate extract_includes.bat |
Feng Xiao | dffd542 | 2015-06-05 17:59:09 -0700 | [diff] [blame] | 128 | echo "mkdir include" > $EXTRACT_INCLUDES_BAT |
| 129 | for HEADER in $PUBLIC_HEADERS; do |
| 130 | HEADER_DIR=$(dirname $HEADER) |
| 131 | while [ ! "$HEADER_DIR" = "." ]; do |
| 132 | echo $HEADER_DIR | sed "s/\\//\\\\/g" |
| 133 | HEADER_DIR=$(dirname $HEADER_DIR) |
| 134 | done |
| 135 | done | sort | uniq | sed "s/^/mkdir include\\\\/" >> $EXTRACT_INCLUDES_BAT |
| 136 | for HEADER in $PUBLIC_HEADERS; do |
| 137 | WINPATH=$(echo $HEADER | sed 's;/;\\;g') |
| 138 | echo "copy \${PROTOBUF_SOURCE_WIN32_PATH}\\..\\src\\$WINPATH include\\$WINPATH" >> $EXTRACT_INCLUDES_BAT |
Feng Xiao | 4333edb | 2015-05-31 02:28:34 -0700 | [diff] [blame] | 139 | done |
Jisi Liu | d19604f | 2015-06-17 17:37:58 -0700 | [diff] [blame] | 140 | |
| 141 | ################################################################################ |
| 142 | # Update bazel BUILD files. |
| 143 | ################################################################################ |
| 144 | |
Jisi Liu | d19604f | 2015-06-17 17:37:58 -0700 | [diff] [blame] | 145 | set_bazel_value() { |
| 146 | local FILENAME=$1 |
| 147 | local VARNAME=$2 |
| 148 | local PREFIX=$3 |
| 149 | shift |
| 150 | shift |
| 151 | shift |
| 152 | awk -v values="$*" -v prefix="$PREFIX" " |
| 153 | BEGIN { start = 0; } |
| 154 | /# AUTOGEN\\($VARNAME\\)/ { |
| 155 | start = 1; |
| 156 | print \$0; |
| 157 | # replace \$0 with indent. |
| 158 | sub(/#.*/, \"\", \$0) |
| 159 | len = split(values, vlist, \" \"); |
| 160 | for (i = 1; i <= len; ++i) { |
| 161 | printf(\"%s\\\"%s%s\\\",\n\", \$0, prefix, vlist[i]); |
| 162 | } |
| 163 | next; |
| 164 | } |
| 165 | start && /\]/ { |
| 166 | start = 0 |
| 167 | } |
| 168 | !start { |
| 169 | print \$0; |
| 170 | } |
| 171 | " $FILENAME > /tmp/$$ |
| 172 | cp /tmp/$$ $FILENAME |
| 173 | } |
| 174 | |
| 175 | |
Jisi Liu | b0f6611 | 2015-08-21 11:18:45 -0700 | [diff] [blame] | 176 | BAZEL_BUILD=./BUILD |
Jisi Liu | d19604f | 2015-06-17 17:37:58 -0700 | [diff] [blame] | 177 | BAZEL_PREFIX="src/" |
Jisi Liu | b0f6611 | 2015-08-21 11:18:45 -0700 | [diff] [blame] | 178 | if [ -f "$BAZEL_BUILD" ]; then |
| 179 | set_bazel_value $BAZEL_BUILD protobuf_lite_srcs $BAZEL_PREFIX $LIBPROTOBUF_LITE_SOURCES |
| 180 | set_bazel_value $BAZEL_BUILD protobuf_srcs $BAZEL_PREFIX $LIBPROTOBUF_SOURCES |
| 181 | set_bazel_value $BAZEL_BUILD protoc_lib_srcs $BAZEL_PREFIX $LIBPROTOC_SOURCES |
| 182 | set_bazel_value $BAZEL_BUILD lite_test_protos "" $LITE_PROTOS |
| 183 | set_bazel_value $BAZEL_BUILD well_known_protos "" $WKT_PROTOS |
| 184 | set_bazel_value $BAZEL_BUILD test_protos "" $PROTOS |
| 185 | set_bazel_value $BAZEL_BUILD common_test_srcs $BAZEL_PREFIX $COMMON_TEST_SOURCES |
| 186 | set_bazel_value $BAZEL_BUILD test_srcs $BAZEL_PREFIX $TEST_SOURCES |
| 187 | set_bazel_value $BAZEL_BUILD test_plugin_srcs $BAZEL_PREFIX $TEST_PLUGIN_SOURCES |
| 188 | else |
| 189 | echo "Skipped BUILD file update." |
| 190 | fi |
Jisi Liu | 7a0c431 | 2015-06-18 16:45:27 -0700 | [diff] [blame] | 191 | |