Skip to content

Commit

Permalink
Merge pull request #398 from arogge/dev/arogge/bareos-19.2/apply-format
Browse files Browse the repository at this point in the history
apply cmake-format and black (python reformatter) to all sources (backport to 19.2)
  • Loading branch information
arogge committed Jan 21, 2020
2 parents 05ad851 + fcdc2ad commit 61c09da
Show file tree
Hide file tree
Showing 69 changed files with 2,725 additions and 2,158 deletions.
58 changes: 24 additions & 34 deletions .cmake-format.py
@@ -1,4 +1,3 @@

# --------------------------
# General Formatting Options
# --------------------------
Expand Down Expand Up @@ -30,7 +29,7 @@
# to this reference: `prefix`: the start of the statement, `prefix-indent`: the
# start of the statement, plus one indentation level, `child`: align to the
# column of the arguments
dangle_align = 'prefix'
dangle_align = "prefix"

min_prefix_chars = 4

Expand All @@ -44,39 +43,30 @@
max_lines_hwrap = 2

# What style line endings to use in the output.
line_ending = 'unix'
line_ending = "unix"

# Format command names consistently as 'lower' or 'upper' case
command_case = 'canonical'
command_case = "canonical"

# Format keywords consistently as 'lower' or 'upper' case
keyword_case = 'unchanged'
keyword_case = "unchanged"

# Specify structure for custom cmake functions
additional_commands = {
"bareos_add_test": {
"pargs": 1,
"flags": [
"SKIP_GTEST",
""
],
"kwargs": {
"ADDITIONAL_SOURCES": "*",
"LINK_LIBRARIES": "*",
"COMPILE_DEFINITIONS": "*"
}
},
"bareos_install_sql_files_to_dbconfig_common": {
"pargs": 0,
"flags": [
"",
""
],
"kwargs": {
"BAREOS_DB_NAME": "*",
"DEBIAN_DB_NAME": "*"
}
}
"bareos_add_test": {
"pargs": 1,
"flags": ["SKIP_GTEST", ""],
"kwargs": {
"ADDITIONAL_SOURCES": "*",
"LINK_LIBRARIES": "*",
"COMPILE_DEFINITIONS": "*",
},
},
"bareos_install_sql_files_to_dbconfig_common": {
"pargs": 0,
"flags": ["", ""],
"kwargs": {"BAREOS_DB_NAME": "*", "DEBIAN_DB_NAME": "*"},
},
}

# A list of command names which should always be wrapped
Expand Down Expand Up @@ -108,10 +98,10 @@
# Comment Formatting Options
# --------------------------
# What character to use for bulleted lists
bullet_char = '*'
bullet_char = "*"

# What character to use as punctuation after numerals in an enumerated list
enum_char = '.'
enum_char = "."

# enable comment markup parsing and reflow
enable_markup = True
Expand All @@ -127,11 +117,11 @@

# Regular expression to match preformat fences in comments
# default=r'^\s*([`~]{3}[`~]*)(.*)$'
fence_pattern = '^\\s*([`~]{3}[`~]*)(.*)$'
fence_pattern = "^\\s*([`~]{3}[`~]*)(.*)$"

# Regular expression to match rulers in comments
# default=r'^\s*[^\w\s]{3}.*[^\w\s]{3}$'
ruler_pattern = '^\\s*[^\\w\\s]{3}.*[^\\w\\s]{3}$'
ruler_pattern = "^\\s*[^\\w\\s]{3}.*[^\\w\\s]{3}$"

# If true, then insert a space between the first hash char and remaining hash
# chars in a hash ruler, and normalize it's length to fill the column
Expand All @@ -145,8 +135,8 @@
emit_byteorder_mark = False

# Specify the encoding of the input file. Defaults to utf-8.
input_encoding = 'utf-8'
input_encoding = "utf-8"

# Specify the encoding of the output file. Defaults to utf-8. Note that cmake
# only claims to support utf-8 so be careful when using anything else
output_encoding = 'utf-8'
output_encoding = "utf-8"
54 changes: 41 additions & 13 deletions cmake/BareosVersionFromGit.cmake
Expand Up @@ -19,7 +19,11 @@

if(Git_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} log -1 --pretty=format:%ct
COMMAND
${GIT_EXECUTABLE}
log
-1
--pretty=format:%ct
RESULT_VARIABLE GIT_COMMIT_TIMESTAMP_RESULT
OUTPUT_VARIABLE GIT_COMMIT_TIMESTAMP
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
Expand All @@ -29,16 +33,28 @@ endif()

if(GIT_COMMIT_TIMESTAMP_RESULT EQUAL 0)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags --exact-match --match "Release/*"
--dirty=.dirty
COMMAND
${GIT_EXECUTABLE}
describe
--tags
--exact-match
--match
"Release/*"
--dirty=.dirty
RESULT_VARIABLE GIT_DESCRIBE_RELEASE_RESULT
OUTPUT_VARIABLE GIT_DESCRIBE_OUTPUT
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT GIT_DESCRIBE_RELEASE_RESULT EQUAL 0)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags --match "WIP/*" --dirty=.dirty
COMMAND
${GIT_EXECUTABLE}
describe
--tags
--match
"WIP/*"
--dirty=.dirty
RESULT_VARIABLE GIT_DESCRIBE_WIP_RESULT
OUTPUT_VARIABLE GIT_DESCRIBE_OUTPUT
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
Expand All @@ -48,26 +64,38 @@ if(GIT_COMMIT_TIMESTAMP_RESULT EQUAL 0)
endif()

if(NOT GIT_DESCRIBE_OUTPUT STREQUAL "")
set(GIT_DESCRIBE_REGEX_LONG
"^([^/]+)/([^-]+)-(([^-]+)?)-?([0-9]+)-g([0-9a-f]+(.dirty)?)[ \n]*"
set(
GIT_DESCRIBE_REGEX_LONG
"^([^/]+)/([^-]+)-(([^-]+)?)-?([0-9]+)-g([0-9a-f]+(.dirty)?)[ \n]*"
)
set(GIT_DESCRIBE_REPLACE_LONG "\\2~\\3\\5.\\6")
set(GIT_DESCRIBE_REGEX_SHORT "^([^/]+)/([0-9.]+)((-[^-]+)?)((.dirty)?)[ \n]*")
set(GIT_DESCRIBE_REPLACE_SHORT "\\2\\3\\5")

string(REGEX MATCH "${GIT_DESCRIBE_REGEX_LONG}" GIT_DESCRIBE_REGEX_LONG_MATCH
"${GIT_DESCRIBE_OUTPUT}"
string(
REGEX
MATCH
"${GIT_DESCRIBE_REGEX_LONG}"
GIT_DESCRIBE_REGEX_LONG_MATCH
"${GIT_DESCRIBE_OUTPUT}"
)
if(GIT_DESCRIBE_REGEX_LONG_MATCH STREQUAL "")
string(
REGEX
REPLACE "${GIT_DESCRIBE_REGEX_SHORT}" "${GIT_DESCRIBE_REPLACE_SHORT}"
GIT_DESCRIBE_VERSION "${GIT_DESCRIBE_OUTPUT}"
REPLACE
"${GIT_DESCRIBE_REGEX_SHORT}"
"${GIT_DESCRIBE_REPLACE_SHORT}"
GIT_DESCRIBE_VERSION
"${GIT_DESCRIBE_OUTPUT}"
)
else()
string(REGEX
REPLACE "${GIT_DESCRIBE_REGEX_LONG}" "${GIT_DESCRIBE_REPLACE_LONG}"
GIT_DESCRIBE_VERSION "${GIT_DESCRIBE_OUTPUT}"
string(
REGEX
REPLACE
"${GIT_DESCRIBE_REGEX_LONG}"
"${GIT_DESCRIBE_REPLACE_LONG}"
GIT_DESCRIBE_VERSION
"${GIT_DESCRIBE_OUTPUT}"
)
endif()
endif()
10 changes: 4 additions & 6 deletions core/cmake/BareosCheckFunctions.cmake
Expand Up @@ -34,14 +34,12 @@ check_function_exists(extattr_get_file HAVE_EXTATTR_GET_FILE)
check_function_exists(extattr_get_link HAVE_EXTATTR_GET_LINK)
check_function_exists(extattr_list_file HAVE_EXTATTR_LIST_FILE)
check_function_exists(extattr_list_link HAVE_EXTATTR_LIST_LINK)
check_function_exists(
extattr_namespace_to_string HAVE_EXTATTR_NAMESPACE_TO_STRING
)
check_function_exists(extattr_namespace_to_string
HAVE_EXTATTR_NAMESPACE_TO_STRING)
check_function_exists(extattr_set_file HAVE_EXTATTR_SET_FILE)
check_function_exists(extattr_set_link HAVE_EXTATTR_SET_LINK)
check_function_exists(
extattr_string_to_namespace HAVE_EXTATTR_STRING_TO_NAMESPACE
)
check_function_exists(extattr_string_to_namespace
HAVE_EXTATTR_STRING_TO_NAMESPACE)
check_function_exists(fchownat HAVE_FCHOWNAT)
check_function_exists(fdatasync HAVE_FDATASYNC)
check_function_exists(fseeko HAVE_FSEEKO)
Expand Down
10 changes: 4 additions & 6 deletions core/cmake/BareosCheckIncludes.cmake
Expand Up @@ -103,9 +103,8 @@ check_include_files(api/glfs.h HAVE_API_GLFS_H)
check_include_files(cephfs/libcephfs.h HAVE_CEPHFS_LIBCEPHFS_H)
check_include_files("sys/stat.h;cephfs/ceph_statx.h" HAVE_CEPHFS_CEPH_STATX_H)
check_include_files(rados/librados.h HAVE_RADOS_LIBRADOS_H)
check_include_files(
radosstriper/libradosstriper.h HAVE_RADOSSTRIPER_LIBRADOSSTRIPER_H
)
check_include_files(radosstriper/libradosstriper.h
HAVE_RADOSSTRIPER_LIBRADOSSTRIPER_H)

# CHECK_INCLUDE_FILES(glusterfs/glusterfs.h HAVE_GLUSTERFS_GLUSTERFS_H)
check_include_files(glusterfs/api/glfs.h HAVE_GLUSTERFS_API_GLFS_H)
Expand All @@ -131,9 +130,8 @@ check_include_files(sys/dir.h HAVE_SYS_DIR_H)
check_include_files(termcap.h HAVE_TERMCAP_H)
check_include_files(term.h HAVE_TERM_H)

check_include_files(
"sys/types.h;sys/scsi/impl/uscsi.h" HAVE_SYS_SCSI_IMPL_USCSI_H
)
check_include_files("sys/types.h;sys/scsi/impl/uscsi.h"
HAVE_SYS_SCSI_IMPL_USCSI_H)
check_include_files("stdio.h;camlib.h" HAVE_CAMLIB_H)
check_include_files(cam/scsi/scsi_message.h HAVE_CAM_SCSI_SCSI_MESSAGE_H)
check_include_files(dev/scsipi/scsipi_all.h HAVE_DEV_SCSIPI_SCSIPI_ALL_H)
Expand Down
22 changes: 18 additions & 4 deletions core/cmake/BareosCheckStructHasMembers.cmake
Expand Up @@ -20,19 +20,33 @@
include(CheckStructHasMember)

check_struct_has_member(
"struct stat" st_blksize sys/stat.h HAVE_STRUCT_STAT_ST_BLKSIZE
"struct stat"
st_blksize
sys/stat.h
HAVE_STRUCT_STAT_ST_BLKSIZE
)
set(HAVE_ST_BLKSIZE ${HAVE_STRUCT_STAT_ST_BLKSIZE})

check_struct_has_member(
"struct stat" st_blocks sys/stat.h HAVE_STRUCT_STAT_ST_BLOCKS
"struct stat"
st_blocks
sys/stat.h
HAVE_STRUCT_STAT_ST_BLOCKS
)
set(HAVE_ST_BLOCKS ${HAVE_STRUCT_STAT_ST_BLOCKS})

check_struct_has_member(
"struct stat" st_rdev sys/stat.h HAVE_STRUCT_STAT_ST_RDEV
"struct stat"
st_rdev
sys/stat.h
HAVE_STRUCT_STAT_ST_RDEV
)
set(HAVE_ST_RDEV ${HAVE_STRUCT_STAT_ST_RDEV})

check_struct_has_member("struct tm" tm_zone time.h HAVE_STRUCT_TM_TM_ZONE)
check_struct_has_member(
"struct tm"
tm_zone
time.h
HAVE_STRUCT_TM_TM_ZONE
)
set(HAVE_TM_ZONE ${HAVE_STRUCT_TM_TM_ZONE})
17 changes: 6 additions & 11 deletions core/cmake/BareosCheckSymbols.cmake
Expand Up @@ -39,28 +39,23 @@ check_symbol_exists(va_copy stdarg.h HAVE_VA_COPY)

cmake_push_check_state()
set(CMAKE_REQUIRED_LIBRARIES ${RADOS_LIBRARIES})
check_symbol_exists(
rados_ioctx_set_namespace rados/librados.h HAVE_RADOS_NAMESPACES
)
check_symbol_exists(
rados_nobjects_list_open rados/librados.h HAVE_RADOS_NOBJECTS_LIST
)
check_symbol_exists(rados_ioctx_set_namespace rados/librados.h
HAVE_RADOS_NAMESPACES)
check_symbol_exists(rados_nobjects_list_open rados/librados.h
HAVE_RADOS_NOBJECTS_LIST)
cmake_pop_check_state()

if(HAVE_GLUSTERFS_API_GLFS_H)
cmake_push_check_state()
set(CMAKE_REQUIRED_LIBRARIES ${GFAPI_LIBRARIES})
check_cxx_source_compiles(
"
check_cxx_source_compiles("
#include <glusterfs/api/glfs.h>
int main(void)
{
/* new glfs_ftruncate() passes two additional args */
return glfs_ftruncate(NULL, 0, NULL, NULL);
}
"
GLFS_FTRUNCATE_HAS_FOUR_ARGS
)
" GLFS_FTRUNCATE_HAS_FOUR_ARGS)

endif()
cmake_pop_check_state()
9 changes: 8 additions & 1 deletion core/cmake/BareosConfigureFile.cmake
Expand Up @@ -23,7 +23,14 @@

file(GLOB_RECURSE IN_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.in")
foreach(in_file ${IN_FILES})
string(REGEX REPLACE ".in\$" "" file ${in_file})
string(
REGEX
REPLACE
".in\$"
""
file
${in_file}
)
message(STATUS "creating file ${file}")
configure_file(${in_file} ${file} @ONLY)
endforeach()
42 changes: 31 additions & 11 deletions core/cmake/BareosExtractVersionInfo.cmake
Expand Up @@ -41,7 +41,13 @@ else()
message(STATUS "Using version information from ${BareosVersionFile}")
endif()

string(REGEX MATCH [0-9.a-zA-Z~]+ BAREOS_FULL_VERSION ${VERSION_STRING})
string(
REGEX
MATCH
[0-9.a-zA-Z~]+
BAREOS_FULL_VERSION
${VERSION_STRING}
)

if(BAREOS_FULL_VERSION STREQUAL "")
message(FATAL_ERROR "BAREOS_FULL_VERSION is not set")
Expand All @@ -50,17 +56,24 @@ endif()
# set BAREOS_FULL_VERSION in parent scope if there is a parent scope
get_directory_property(hasParent PARENT_DIRECTORY)
if(hasParent)
set(BAREOS_FULL_VERSION
${BAREOS_FULL_VERSION}
PARENT_SCOPE
)
set(BAREOS_FULL_VERSION ${BAREOS_FULL_VERSION} PARENT_SCOPE)
endif()

string(REGEX MATCH [0-9]+.[0-9]+.[0-9]+ BAREOS_NUMERIC_VERSION
${VERSION_STRING}
string(
REGEX
MATCH
[0-9]+.[0-9]+.[0-9]+
BAREOS_NUMERIC_VERSION
${VERSION_STRING}
)

string(REPLACE "." ";" VERSION_LIST ${BAREOS_NUMERIC_VERSION})
string(
REPLACE
"."
";"
VERSION_LIST
${BAREOS_NUMERIC_VERSION}
)
list(GET VERSION_LIST 0 BAREOS_VERSION_MAJOR)
list(GET VERSION_LIST 1 BAREOS_VERSION_MINOR)
list(GET VERSION_LIST 2 BAREOS_VERSION_PATCH)
Expand All @@ -79,7 +92,14 @@ else()
endif()

# extract db version from cats.h
file(STRINGS ${CMAKE_CURRENT_LIST_DIR}/../src/cats/cats.h DB_VERSION_STRING
REGEX .*BDB_VERSION.*
file(
STRINGS ${CMAKE_CURRENT_LIST_DIR}/../src/cats/cats.h DB_VERSION_STRING
REGEX .*BDB_VERSION.*
)
string(
REGEX
MATCH
[0-9]+
BDB_VERSION
${DB_VERSION_STRING}
)
string(REGEX MATCH [0-9]+ BDB_VERSION ${DB_VERSION_STRING})

0 comments on commit 61c09da

Please sign in to comment.