mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-16 10:33:27 +08:00
Add pgindent target to format C source
The C source files can now be formatted with pgindent using a new CMake build target. The location of pgindent and dependencies are auto-discovered by CMake or can be overridden on the command line.
This commit is contained in:
parent
a4e1e32d02
commit
69d7d5800c
@ -29,19 +29,45 @@ message(STATUS "Build type is ${CMAKE_BUILD_TYPE}")
|
||||
|
||||
# Search paths for Postgres binaries
|
||||
if (WIN32)
|
||||
set(POSTGRES_PATHS
|
||||
find_path(PG_PATH
|
||||
bin/postgres
|
||||
HINTS
|
||||
"C:/PostgreSQL"
|
||||
"C:/PostgreSQL/pg96/bin")
|
||||
"C:/Program Files/PostgreSQL"
|
||||
PATH_SUFFIXES
|
||||
bin
|
||||
10/bin
|
||||
96/bin
|
||||
pg96/bin
|
||||
DOC
|
||||
"The path to a PostgreSQL installation")
|
||||
endif (WIN32)
|
||||
|
||||
if (UNIX)
|
||||
set(POSTGRES_PATHS
|
||||
"/usr/local/pgsql/bin")
|
||||
find_path(PG_PATH
|
||||
bin/postgres
|
||||
HINTS
|
||||
$ENV{HOME}
|
||||
/opt/local/pgsql
|
||||
/usr/local/pgsql
|
||||
/usr/lib/postgresql
|
||||
PATH_SUFFIXES
|
||||
bin
|
||||
10/bin
|
||||
9.6/bin
|
||||
96/bin
|
||||
pg96/bin
|
||||
DOC
|
||||
"The path to a PostgreSQL installation")
|
||||
endif (UNIX)
|
||||
|
||||
find_program(PG_CONFIG pg_config
|
||||
PATHS ${POSTGRES_PATHS}
|
||||
DOC "The path to the pg_config of the PostgreSQL version to compile against"
|
||||
HINTS
|
||||
${PG_PATH}
|
||||
PATH_SUFFIXES
|
||||
bin
|
||||
DOC
|
||||
"The path to the pg_config of the PostgreSQL version to compile against"
|
||||
REQUIRED)
|
||||
|
||||
if (NOT PG_CONFIG)
|
||||
@ -122,13 +148,33 @@ execute_process(
|
||||
OUTPUT_VARIABLE PG_LIBS
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
|
||||
add_subdirectory(sql)
|
||||
add_subdirectory(src)
|
||||
find_path(PG_SOURCE_DIR
|
||||
src/include/pg_config.h.in
|
||||
HINTS
|
||||
$ENV{HOME}
|
||||
$ENV{HOME}/projects
|
||||
$ENV{HOME}/Projects
|
||||
$ENV{HOME}/development
|
||||
$ENV{HOME}/Development
|
||||
PATH_SUFFIXES
|
||||
postgres
|
||||
postgresql
|
||||
pgsql
|
||||
DOC
|
||||
"The path to the PostgreSQL source tree")
|
||||
|
||||
if (PG_SOURCE_DIR)
|
||||
message(STATUS "Found PostgreSQL source in ${PG_SOURCE_DIR}")
|
||||
endif (PG_SOURCE_DIR)
|
||||
|
||||
if (UNIX)
|
||||
add_subdirectory(test)
|
||||
add_subdirectory(scripts)
|
||||
endif (UNIX)
|
||||
|
||||
add_subdirectory(sql)
|
||||
add_subdirectory(src)
|
||||
|
||||
set(EXT_CONTROL_FILE ${PROJECT_NAME}.control)
|
||||
configure_file(${EXT_CONTROL_FILE}.in ${EXT_CONTROL_FILE})
|
||||
|
||||
|
14
scripts/CMakeLists.txt
Normal file
14
scripts/CMakeLists.txt
Normal file
@ -0,0 +1,14 @@
|
||||
if (APPLE)
|
||||
# We strictly need gobjdump on macs, because objdump is usually
|
||||
# llvm's incompatible objdump
|
||||
find_program(OBJDUMP NAMES gobjdump PATHS /usr/local/bin /opt/local/bin)
|
||||
else ()
|
||||
find_program(OBJDUMP NAMES gobjdump objdump)
|
||||
endif (APPLE)
|
||||
|
||||
if (OBJDUMP)
|
||||
message(STATUS "Using objdump ${OBJDUMP}")
|
||||
configure_file(generate_typedefs.sh.in generate_typedefs.sh @ONLY)
|
||||
else ()
|
||||
message(STATUS "Install objdump or gobjdump to be able to run pgindent")
|
||||
endif (OBJDUMP)
|
@ -31,7 +31,7 @@ else
|
||||
fi
|
||||
|
||||
# Build and install the extension with debug symbols and assertions
|
||||
docker exec -u root -it ${BUILD_CONTAINER_NAME} /bin/bash -c "cp -a /src/{src,sql,test,version.config,CMakeLists.txt,timescaledb.control.in} /build/ && cd build/debug && cmake -DCMAKE_BUILD_TYPE=Debug .. && make && make install && echo \"shared_preload_libraries = 'timescaledb'\" >> /usr/local/share/postgresql/postgresql.conf.sample && cd / && rm -rf /build"
|
||||
docker exec -u root -it ${BUILD_CONTAINER_NAME} /bin/bash -c "cp -a /src/{src,sql,test,scripts,version.config,CMakeLists.txt,timescaledb.control.in} /build/ && cd build/debug && cmake -DCMAKE_BUILD_TYPE=Debug .. && make && make install && echo \"shared_preload_libraries = 'timescaledb'\" >> /usr/local/share/postgresql/postgresql.conf.sample && cd / && rm -rf /build"
|
||||
|
||||
docker commit -a $USER -m "TimescaleDB development image" ${BUILD_CONTAINER_NAME} ${IMAGE_NAME}:${TAG_NAME}
|
||||
|
||||
|
@ -1,18 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
OBJDUMP=${OBJDUMP:-gobjdump}
|
||||
|
||||
case "$OSTYPE" in
|
||||
linux*) OBJDUMP=objdump ;;
|
||||
darwin*) ;;
|
||||
bsd*) ;;
|
||||
*) ;;
|
||||
esac
|
||||
|
||||
${OBJDUMP} -W src/*.o |egrep -A3 DW_TAG_typedef |perl -e 'while (<>) { chomp; @flds = split;next unless (1 < @flds);\
|
||||
next if $flds[0] ne "DW_AT_name" && $flds[1] ne "DW_AT_name";\
|
||||
next if $flds[-1] =~ /^DW_FORM_str/;\
|
||||
print $flds[-1],"\n"; }' |sort |uniq > typedef.list.local
|
||||
wget -q -O - "http://www.pgbuildfarm.org/cgi-bin/typedefs.pl?branch=HEAD" |\
|
||||
cat - typedef.list.local | sort | uniq > typedef.list
|
||||
rm typedef.list.local
|
16
scripts/generate_typedefs.sh.in
Executable file
16
scripts/generate_typedefs.sh.in
Executable file
@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
|
||||
TMPDIR=${TMPDIR:-$(mktemp -d 2>/dev/null || mktemp -d -t 'timescaledb_typedef')}
|
||||
|
||||
trap cleanup EXIT
|
||||
|
||||
cleanup() {
|
||||
rm -rf ${TMPDIR}
|
||||
}
|
||||
|
||||
@OBJDUMP@ -W @CMAKE_BINARY_DIR@/src/CMakeFiles/timescaledb.dir/*.o |egrep -A3 DW_TAG_typedef |perl -e 'while (<>) { chomp; @flds = split;next unless (1 < @flds);\
|
||||
next if $flds[0] ne "DW_AT_name" && $flds[1] ne "DW_AT_name";\
|
||||
next if $flds[-1] =~ /^DW_FORM_str/;\
|
||||
print $flds[-1],"\n"; }' |sort |uniq > ${TMPDIR}/typedefs.list.local
|
||||
wget -q -O - "http://www.pgbuildfarm.org/cgi-bin/typedefs.pl?branch=HEAD" |\
|
||||
cat - ${TMPDIR}/typedefs.list.local | sort | uniq
|
@ -114,6 +114,27 @@ add_custom_command(
|
||||
COMMENT "Generating gitcommit.h"
|
||||
VERBATIM)
|
||||
|
||||
find_program(PGINDENT pgindent
|
||||
HINTS ${PG_SOURCE_DIR}
|
||||
PATH_SUFFIXES src/tools/pgindent
|
||||
DOC "Format C code according to PostgreSQL standards")
|
||||
|
||||
if (PGINDENT)
|
||||
message(STATUS "Using pgindent ${PGINDENT}")
|
||||
else ()
|
||||
message(STATUS "Install pgindent to be able to format C code: https://github.com/postgres/postgres/tree/master/src/tools/pgindent")
|
||||
endif (PGINDENT)
|
||||
|
||||
# Configuration for running pgindent
|
||||
if (OBJDUMP AND PGINDENT)
|
||||
add_custom_command(OUTPUT typedefs.list
|
||||
DEPENDS ${PROJECT_NAME}
|
||||
COMMAND sh ${CMAKE_BINARY_DIR}/scripts/generate_typedefs.sh > typedefs.list)
|
||||
add_custom_target(pgindent
|
||||
COMMAND ${PGINDENT} -typedefs typedefs.list -code-base ${CMAKE_SOURCE_DIR}/src
|
||||
DEPENDS typedefs.list)
|
||||
endif (OBJDUMP AND PGINDENT)
|
||||
|
||||
add_library(${PROJECT_NAME} MODULE ${SOURCES} ${HEADERS} ${GITCOMMIT_H})
|
||||
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||
|
@ -1,6 +1,6 @@
|
||||
# Testing support
|
||||
find_program(PG_REGRESS pg_regress
|
||||
PATHS
|
||||
HINTS
|
||||
"${PG_PKGLIBDIR}/pgxs/src/test/regress/"
|
||||
REQUIRED)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user