2021-09-11 02:32:15 +00:00
|
|
|
#!/bin/bash -u
|
2015-05-31 09:28:34 +00:00
|
|
|
|
|
|
|
# This script copies source file lists from src/Makefile.am to cmake files.
|
|
|
|
|
|
|
|
get_variable_value() {
|
2015-06-18 00:37:58 +00:00
|
|
|
local FILENAME=$1
|
|
|
|
local VARNAME=$2
|
2015-05-31 09:28:34 +00:00
|
|
|
awk "
|
|
|
|
BEGIN { start = 0; }
|
|
|
|
/^$VARNAME =/ { start = 1; }
|
|
|
|
{ if (start) { print \$0; } }
|
|
|
|
/\\\\\$/ { next; }
|
|
|
|
{ start = 0; }
|
|
|
|
" $FILENAME \
|
|
|
|
| sed "s/^$VARNAME =//" \
|
|
|
|
| sed "s/[ \\]//g" \
|
|
|
|
| grep -v "^\\$" \
|
|
|
|
| grep -v "^$" \
|
|
|
|
| LC_ALL=C sort | uniq
|
|
|
|
}
|
|
|
|
|
2015-06-18 00:37:58 +00:00
|
|
|
get_header_files() {
|
|
|
|
get_variable_value $@ | grep '\.h$'
|
|
|
|
}
|
|
|
|
|
2015-05-31 09:28:34 +00:00
|
|
|
get_source_files() {
|
2018-03-26 19:59:28 +00:00
|
|
|
get_variable_value $@ | grep "cc$\|inc$"
|
2015-05-31 09:28:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get_proto_files() {
|
|
|
|
get_variable_value $@ | grep "pb.cc$" | sed "s/pb.cc/proto/"
|
|
|
|
}
|
|
|
|
|
|
|
|
sort_files() {
|
|
|
|
for FILE in $@; do
|
|
|
|
echo $FILE
|
2015-06-06 00:59:09 +00:00
|
|
|
done | LC_ALL=C sort | uniq
|
2015-05-31 09:28:34 +00:00
|
|
|
}
|
|
|
|
|
2015-06-17 20:31:26 +00:00
|
|
|
MAKEFILE=src/Makefile.am
|
2015-05-31 09:28:34 +00:00
|
|
|
|
|
|
|
[ -f "$MAKEFILE" ] || {
|
|
|
|
echo "Cannot find: $MAKEFILE"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
# Extract file lists from src/Makefile.am
|
|
|
|
GZHEADERS=$(get_variable_value $MAKEFILE GZHEADERS)
|
2021-09-11 02:32:15 +00:00
|
|
|
LIBPROTOBUF_HEADERS=$(get_variable_value $MAKEFILE nobase_include_HEADERS | grep -v /compiler/)
|
|
|
|
LIBPROTOBUF_HEADERS=$(sort_files $GZHEADERS $LIBPROTOBUF_HEADERS)
|
2015-05-31 09:28:34 +00:00
|
|
|
LIBPROTOBUF_LITE_SOURCES=$(get_source_files $MAKEFILE libprotobuf_lite_la_SOURCES)
|
|
|
|
LIBPROTOBUF_SOURCES=$(get_source_files $MAKEFILE libprotobuf_la_SOURCES)
|
|
|
|
LIBPROTOC_SOURCES=$(get_source_files $MAKEFILE libprotoc_la_SOURCES)
|
2021-09-11 02:32:15 +00:00
|
|
|
LIBPROTOC_HEADERS=$(get_variable_value $MAKEFILE nobase_include_HEADERS | grep /compiler/)
|
2015-05-31 09:28:34 +00:00
|
|
|
LITE_PROTOS=$(get_proto_files $MAKEFILE protoc_lite_outputs)
|
|
|
|
PROTOS=$(get_proto_files $MAKEFILE protoc_outputs)
|
2015-06-18 00:37:58 +00:00
|
|
|
WKT_PROTOS=$(get_variable_value $MAKEFILE nobase_dist_proto_DATA)
|
2015-05-31 09:28:34 +00:00
|
|
|
COMMON_TEST_SOURCES=$(get_source_files $MAKEFILE COMMON_TEST_SOURCES)
|
2015-08-24 00:50:38 +00:00
|
|
|
COMMON_LITE_TEST_SOURCES=$(get_source_files $MAKEFILE COMMON_LITE_TEST_SOURCES)
|
2015-05-31 09:28:34 +00:00
|
|
|
TEST_SOURCES=$(get_source_files $MAKEFILE protobuf_test_SOURCES)
|
2019-07-20 10:49:03 +00:00
|
|
|
NON_MSVC_TEST_SOURCES=$(get_source_files $MAKEFILE NON_MSVC_TEST_SOURCES)
|
2015-05-31 09:28:34 +00:00
|
|
|
LITE_TEST_SOURCES=$(get_source_files $MAKEFILE protobuf_lite_test_SOURCES)
|
2015-08-24 00:50:38 +00:00
|
|
|
LITE_ARENA_TEST_SOURCES=$(get_source_files $MAKEFILE protobuf_lite_arena_test_SOURCES)
|
2015-06-18 23:45:27 +00:00
|
|
|
TEST_PLUGIN_SOURCES=$(get_source_files $MAKEFILE test_plugin_SOURCES)
|
2015-05-31 09:28:34 +00:00
|
|
|
|
2015-06-18 00:37:58 +00:00
|
|
|
################################################################################
|
|
|
|
# Update cmake files.
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
CMAKE_DIR=cmake
|
|
|
|
EXTRACT_INCLUDES_BAT=cmake/extract_includes.bat.in
|
|
|
|
[ -d "$CMAKE_DIR" ] || {
|
|
|
|
echo "Cannot find: $CMAKE_DIR"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
[ -f "$EXTRACT_INCLUDES_BAT" ] || {
|
|
|
|
echo "Cannot find: $EXTRACT_INCLUDES_BAT"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
set_cmake_value() {
|
|
|
|
local FILENAME=$1
|
|
|
|
local VARNAME=$2
|
|
|
|
local PREFIX=$3
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
awk -v values="$*" -v prefix="$PREFIX" "
|
|
|
|
BEGIN { start = 0; }
|
|
|
|
/^set\\($VARNAME/ {
|
|
|
|
start = 1;
|
|
|
|
print \$0;
|
|
|
|
len = split(values, vlist, \" \");
|
|
|
|
for (i = 1; i <= len; ++i) {
|
2021-09-11 02:32:15 +00:00
|
|
|
printf(\" \");
|
|
|
|
if (vlist[i] !~ /^\\\$/) {
|
|
|
|
printf(\"%s\", prefix);
|
|
|
|
}
|
|
|
|
printf(\"%s\\n\", vlist[i]);
|
2015-06-18 00:37:58 +00:00
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
start && /^\\)/ {
|
|
|
|
start = 0;
|
|
|
|
}
|
|
|
|
!start {
|
|
|
|
print \$0;
|
|
|
|
}
|
|
|
|
" $FILENAME > /tmp/$$
|
|
|
|
cp /tmp/$$ $FILENAME
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-31 09:28:34 +00:00
|
|
|
# Replace file lists in cmake files.
|
2022-03-08 00:00:00 +00:00
|
|
|
CMAKE_PREFIX="\${protobuf_SOURCE_DIR}/src/"
|
2015-06-18 00:37:58 +00:00
|
|
|
set_cmake_value $CMAKE_DIR/libprotobuf-lite.cmake libprotobuf_lite_files $CMAKE_PREFIX $LIBPROTOBUF_LITE_SOURCES
|
|
|
|
set_cmake_value $CMAKE_DIR/libprotobuf.cmake libprotobuf_files $CMAKE_PREFIX $LIBPROTOBUF_SOURCES
|
|
|
|
set_cmake_value $CMAKE_DIR/libprotoc.cmake libprotoc_files $CMAKE_PREFIX $LIBPROTOC_SOURCES
|
2018-03-26 19:59:28 +00:00
|
|
|
set_cmake_value $CMAKE_DIR/libprotoc.cmake libprotoc_headers $CMAKE_PREFIX $LIBPROTOC_HEADERS
|
2015-06-18 00:37:58 +00:00
|
|
|
set_cmake_value $CMAKE_DIR/tests.cmake lite_test_protos "" $LITE_PROTOS
|
2022-03-11 00:40:07 +00:00
|
|
|
set_cmake_value $CMAKE_DIR/tests.cmake tests_protos "" $PROTOS
|
2021-09-11 02:32:15 +00:00
|
|
|
set_cmake_value $CMAKE_DIR/tests.cmake common_test_files $CMAKE_PREFIX '${common_lite_test_files}' $COMMON_TEST_SOURCES
|
2015-08-24 00:50:38 +00:00
|
|
|
set_cmake_value $CMAKE_DIR/tests.cmake common_lite_test_files $CMAKE_PREFIX $COMMON_LITE_TEST_SOURCES
|
2015-06-18 00:37:58 +00:00
|
|
|
set_cmake_value $CMAKE_DIR/tests.cmake tests_files $CMAKE_PREFIX $TEST_SOURCES
|
2019-07-20 10:49:03 +00:00
|
|
|
set_cmake_value $CMAKE_DIR/tests.cmake non_msvc_tests_files $CMAKE_PREFIX $NON_MSVC_TEST_SOURCES
|
2015-06-18 00:37:58 +00:00
|
|
|
set_cmake_value $CMAKE_DIR/tests.cmake lite_test_files $CMAKE_PREFIX $LITE_TEST_SOURCES
|
2015-08-24 00:50:38 +00:00
|
|
|
set_cmake_value $CMAKE_DIR/tests.cmake lite_arena_test_files $CMAKE_PREFIX $LITE_ARENA_TEST_SOURCES
|
2015-05-31 09:28:34 +00:00
|
|
|
|
|
|
|
# Generate extract_includes.bat
|
2015-06-06 00:59:09 +00:00
|
|
|
echo "mkdir include" > $EXTRACT_INCLUDES_BAT
|
2021-09-11 02:32:15 +00:00
|
|
|
for INCLUDE in $LIBPROTOBUF_HEADERS $LIBPROTOC_HEADERS $WKT_PROTOS; do
|
2018-04-25 06:21:17 +00:00
|
|
|
INCLUDE_DIR=$(dirname "$INCLUDE")
|
|
|
|
while [ ! "$INCLUDE_DIR" = "." ]; do
|
|
|
|
echo "mkdir include\\${INCLUDE_DIR//\//\\}"
|
|
|
|
INCLUDE_DIR=$(dirname "$INCLUDE_DIR")
|
2018-04-20 11:52:02 +00:00
|
|
|
done
|
|
|
|
done | sort | uniq >> $EXTRACT_INCLUDES_BAT
|
2021-09-11 02:32:15 +00:00
|
|
|
for INCLUDE in $(sort_files $LIBPROTOBUF_HEADERS $LIBPROTOC_HEADERS) $WKT_PROTOS; do
|
2018-04-25 06:21:17 +00:00
|
|
|
WINPATH=${INCLUDE//\//\\}
|
2018-04-20 11:52:02 +00:00
|
|
|
echo "copy \"\${PROTOBUF_SOURCE_WIN32_PATH}\\..\\src\\$WINPATH\" include\\$WINPATH" >> $EXTRACT_INCLUDES_BAT
|
|
|
|
done
|
2015-06-18 00:37:58 +00:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Update bazel BUILD files.
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
set_bazel_value() {
|
|
|
|
local FILENAME=$1
|
|
|
|
local VARNAME=$2
|
|
|
|
local PREFIX=$3
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
awk -v values="$*" -v prefix="$PREFIX" "
|
|
|
|
BEGIN { start = 0; }
|
|
|
|
/# AUTOGEN\\($VARNAME\\)/ {
|
|
|
|
start = 1;
|
|
|
|
print \$0;
|
|
|
|
# replace \$0 with indent.
|
|
|
|
sub(/#.*/, \"\", \$0)
|
|
|
|
len = split(values, vlist, \" \");
|
|
|
|
for (i = 1; i <= len; ++i) {
|
|
|
|
printf(\"%s\\\"%s%s\\\",\n\", \$0, prefix, vlist[i]);
|
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
start && /\]/ {
|
|
|
|
start = 0
|
|
|
|
}
|
|
|
|
!start {
|
|
|
|
print \$0;
|
|
|
|
}
|
|
|
|
" $FILENAME > /tmp/$$
|
|
|
|
cp /tmp/$$ $FILENAME
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-21 18:18:45 +00:00
|
|
|
BAZEL_BUILD=./BUILD
|
2015-06-18 00:37:58 +00:00
|
|
|
BAZEL_PREFIX="src/"
|
2015-08-21 18:18:45 +00:00
|
|
|
if [ -f "$BAZEL_BUILD" ]; then
|
|
|
|
set_bazel_value $BAZEL_BUILD protobuf_lite_srcs $BAZEL_PREFIX $LIBPROTOBUF_LITE_SOURCES
|
|
|
|
set_bazel_value $BAZEL_BUILD protobuf_srcs $BAZEL_PREFIX $LIBPROTOBUF_SOURCES
|
|
|
|
set_bazel_value $BAZEL_BUILD protoc_lib_srcs $BAZEL_PREFIX $LIBPROTOC_SOURCES
|
|
|
|
set_bazel_value $BAZEL_BUILD lite_test_protos "" $LITE_PROTOS
|
|
|
|
set_bazel_value $BAZEL_BUILD well_known_protos "" $WKT_PROTOS
|
|
|
|
set_bazel_value $BAZEL_BUILD test_protos "" $PROTOS
|
2021-09-11 02:32:15 +00:00
|
|
|
set_bazel_value $BAZEL_BUILD common_test_srcs $BAZEL_PREFIX $COMMON_LITE_TEST_SOURCES $COMMON_TEST_SOURCES
|
2015-08-21 18:18:45 +00:00
|
|
|
set_bazel_value $BAZEL_BUILD test_srcs $BAZEL_PREFIX $TEST_SOURCES
|
2019-07-20 10:49:03 +00:00
|
|
|
set_bazel_value $BAZEL_BUILD non_msvc_test_srcs $BAZEL_PREFIX $NON_MSVC_TEST_SOURCES
|
2015-08-21 18:18:45 +00:00
|
|
|
set_bazel_value $BAZEL_BUILD test_plugin_srcs $BAZEL_PREFIX $TEST_PLUGIN_SOURCES
|
|
|
|
else
|
|
|
|
echo "Skipped BUILD file update."
|
|
|
|
fi
|
2015-06-18 23:45:27 +00:00
|
|
|
|