blob: 704875099bfe45a9a5d32216225bfc7511ece64d [file] [log] [blame]
Radek Krejcib2258822020-07-14 08:39:30 +02001# generate API/ABI report
2macro(LIBYANG_ABICHECK)
Radek Krejcif54e7bc2020-08-16 10:30:47 +02003 find_program(ABI_DUMPER abi-dumper)
4 find_package_handle_standard_args(abi-dumper DEFAULT_MSG ABI_DUMPER)
5 if(ABI_DUMPER)
6 set(PUBLIC_HEADERS ${headers})
7 string(PREPEND PUBLIC_HEADERS "${CMAKE_SOURCE_DIR}/")
8 string(REPLACE ";" "\n${CMAKE_SOURCE_DIR}/" PUBLIC_HEADERS "${PUBLIC_HEADERS}")
9 file(GENERATE OUTPUT ${CMAKE_BINARY_DIR}/public_headers CONTENT "${PUBLIC_HEADERS}")
10 add_custom_target(abi-dump
11 COMMAND ${ABI_DUMPER} ./libyang${CMAKE_SHARED_LIBRARY_SUFFIX} -o libyang.${LIBYANG_SOVERSION_FULL}.dump
12 -lver ${LIBYANG_SOVERSION_FULL} -public-headers ${CMAKE_BINARY_DIR}/public_headers
13 DEPENDS yang
14 BYPRODUCTS ${CMAKE_BINARY_DIR}/libyang.${LIBYANG_SOVERSION_FULL}.dump
15 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
16 COMMENT Dumping ABI information for abi-check.)
17 endif()
18
19 # check correctness of the SO version according to the API/ABI changes
20 find_program(ABI_CHECKER abi-compliance-checker)
21 find_package_handle_standard_args(abi-compliance-checker DEFAULT_MSG ABI_CHECKER)
22 if(ABI_DUMPER AND ABI_CHECKER)
23 set(ABIBASE_HASH "" CACHE STRING "GIT hash for the commit to compare current ABI to. If not set, base SO version commit is found.")
24 if (NOT ABIBASE_HASH)
25 # check that we have some ABI base version already and get its hash in GIT
26 set(ABIBASE_VERSION "${LIBYANG_MAJOR_VERSION}.0.0")
27 execute_process(COMMAND bash "-c" "git log --pretty=oneline --grep=\"SOVERSION .* ${ABIBASE_VERSION}\$\" | cut -d' ' -f1"
28 OUTPUT_VARIABLE ABIBASE_HASH)
29 else()
30 string(SUBSTRING ${ABIBASE_HASH} 0 8 ABIBASE_HASH_SHORT)
31 set(ABIBASE_VERSION "git-${ABIBASE_HASH_SHORT}")
Radek Krejcifba9c622020-10-30 08:28:54 +010032 endif()
Radek Krejcif54e7bc2020-08-16 10:30:47 +020033 if(ABIBASE_HASH)
34 # we have the ABI base version, so generate script for abi-check target
35 string(REPLACE "\n" "" ABIBASE_HASH ${ABIBASE_HASH})
36 file(GENERATE OUTPUT ${CMAKE_BINARY_DIR}/abibase.sh CONTENT "#!/bin/sh
Radek Krejcib2258822020-07-14 08:39:30 +020037if [ ! -d abibase ]; then mkdir abibase; fi
38cd abibase
39if [ ! -f build/libyang.*.dump ]; then
40 if [ -d .git ] && [ \"${ABIBASE_HASH}\" != \"`git log --pretty=oneline | cut -d' ' -f1`\" ]; then rm -rf .* 2> /dev/null; fi
41 if [ ! -d .git ]; then
42 git init
43 git remote add origin https://github.com/CESNET/libyang
44 git fetch origin --depth 1 ${ABIBASE_HASH}
45 git reset --hard FETCH_HEAD
46 fi
47 if [ ! -d build ]; then mkdir build; fi
48 cd build
49 cmake -DCMAKE_BUILD_TYPE=ABICheck ..
50 make abi-dump
51fi
52")
Radek Krejcif54e7bc2020-08-16 10:30:47 +020053 # abi-check target itself using abi-compliance-checker
54 add_custom_target(abi-check
55 COMMAND bash ./abibase.sh
56 COMMAND ${ABI_CHECKER} -l libyang${CMAKE_SHARED_LIBRARY_SUFFIX} -old abibase/build/libyang.*.dump
57 -new ./libyang.${LIBYANG_SOVERSION_FULL}.dump -s
58 DEPENDS yang abi-dump
59 BYPRODUCTS ${CMAKE_BINARY_DIR}/compat_reports/libyang${CMAKE_SHARED_LIBRARY_SUFFIX}/*_to_${LIBYANG_SOVERSION_FULL}/compat_report.html
60 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
61 COMMENT Checking ABI compatibility with the ${ABIBASE_VERSION} version.)
62 else()
63 add_custom_target(abi-check
64 COMMENT Nothing to check - missing base SOVERSION commit for ${ABIBASE_VERSION} version.)
65 endif()
66 endif()
Radek Krejcib2258822020-07-14 08:39:30 +020067endmacro()