1# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. 2# 3# This program is free software; you can redistribute it and/or modify 4# it under the terms of the GNU General Public License as published by 5# the Free Software Foundation; version 2 of the License. 6# 7# This program is distributed in the hope that it will be useful, 8# but WITHOUT ANY WARRANTY; without even the implied warranty of 9# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10# GNU General Public License for more details. 11# 12# You should have received a copy of the GNU General Public License 13# along with this program; if not, write to the Free Software 14# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA 15 16# 17# Rules for checking that the abi/api has not changed. 18# 19# The following steps are followed in the do_abi_check rule below 20# 21# 1) Generate preprocessor output for the files that need to 22# be tested for abi/api changes. use -nostdinc to prevent 23# generation of preprocessor output for system headers. This 24# results in messages in stderr saying that these headers 25# were not found. Redirect the stderr output to /dev/null 26# to prevent seeing these messages. 27# 2) sed the output to 28# 2.1) remove blank lines and lines that begin with "# " 29# 2.2) When gcc -E is run on the Mac OS and solaris sparc platforms it 30# introduces a line of output that shows up as a difference between 31# the .pp and .out files. Remove these OS specific preprocessor text 32# inserted by the preprocessor. 33# 3) diff the generated file and the canons (.pp files already in 34# the repository). 35# 4) delete the .out file that is generated. 36# 37# If the diff fails, the generated file is not removed. This will 38# be useful for analysis of ABI differences (e.g. using a visual 39# diff tool). 40# 41# A ABI change that causes a build to fail will always be accompanied 42# by new canons (.out files). The .out files that are not removed will 43# be replaced as the new .pp files. 44# 45# e.g. If include/mysql/plugin.h has an ABI change then this rule would 46# leave a <build directory>/abi_check.out file. 47# 48# A developer with a justified API change will then do a 49# mv <build directory>/abi_check.out include/mysql/plugin.pp 50# to replace the old canons with the new ones. 51# 52 53SET(abi_check_out ${BINARY_DIR}/abi_check.out) 54 55FOREACH(file ${ABI_HEADERS}) 56 GET_FILENAME_COMPONENT(header_basename ${file} NAME) 57 SET(tmpfile ${BINARY_DIR}/${header_basename}.pp.tmp) 58 59 EXECUTE_PROCESS( 60 COMMAND ${COMPILER} 61 -E -nostdinc -DMYSQL_ABI_CHECK -D__cplusplus 62 -I${SOURCE_DIR}/include 63 -I${BINARY_DIR}/include -I${SOURCE_DIR}/include/mysql -I${SOURCE_DIR}/sql 64 ${file} 65 ERROR_QUIET OUTPUT_FILE ${tmpfile}) 66 EXECUTE_PROCESS( 67 COMMAND sed -e "/^# /d" 68 -e "/^[ ]*$/d" 69 -e "/^#pragma GCC set_debug_pwd/d" 70 -e "/^#ident/d" 71 RESULT_VARIABLE result OUTPUT_FILE ${abi_check_out} INPUT_FILE ${tmpfile}) 72 IF(NOT ${result} EQUAL 0) 73 MESSAGE(FATAL_ERROR "sed returned error ${result}") 74 ENDIF() 75 FILE(REMOVE ${tmpfile}) 76 EXECUTE_PROCESS( 77 COMMAND diff -w ${file}.pp ${abi_check_out} RESULT_VARIABLE result) 78 IF(result MATCHES "No such file or directory") 79 MESSAGE("Command 'diff' not found. ABI check for ${file} skipped.") 80 ELSEIF(NOT result EQUAL 0) 81 IF(ABI_UPDATE) 82 EXECUTE_PROCESS(COMMAND mv -v ${abi_check_out} ${file}.pp) 83 ELSE(ABI_UPDATE) 84 MESSAGE(FATAL_ERROR 85 "ABI check found difference between ${file}.pp and ${abi_check_out}") 86 ENDIF(ABI_UPDATE) 87 ENDIF() 88 FILE(REMOVE ${abi_check_out}) 89ENDFOREACH() 90