From: Vladislav Vaintroub Date: January 22 2011 2:51pm Subject: RE: bzr commit into mysql-5.5-bugteam branch (joerg:3209) Bug#42969 List-Archive: http://lists.mysql.com/commits/129377 Message-Id: <003c01cbba43$e3a38230$aaea8690$@montyprogram.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_003D_01CBBA4C.456CA520" ------=_NextPart_000_003D_01CBBA4C.456CA520 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi Joerg,=20 now that I tried you patch, some more comments. I also built a patch = based on yours, with couple of things changed/fixed. So, the comments: 1) You execute VERSION_BIN twice, at cmake time and at build time . At = cmake time you execute it via inclusion of INCLUDE(version_files.cmake), at build time via cmake -P = version_files.cmake Unfortunately, at cmake time this leads to VERSION_bin in source = directory. This is best avoided, out-of-source builds treat source directory as read-only (at least they should try to be clean. I also = think that build time is not the correct time to run those scripts. I think the install/package time is the best time, but more on = this below. 2) on Windows, EXECUTE_PROCESS(COMMAND "date" "/T" OUTPUT_VARIABLE TMP_DATE) Will not always lead to a good result. You want to run the cmd.exe = bultin, however if there is a date.exe in the PATH (like in my case , from C:\Gnuwin32\bin), date.exe will be taken You can force cmd.exe builtin adding cmd /c to the command, there is no = need for quotes. EXECUTE_PROCESS(COMMAND cmd /c date /T OUTPUT_VARIABLE TMP_DATE) 3) Executing script at *package/install* time. I believe this is what is = appropriate in this case, not cmake time neither build time (there is no benefit from doing it during cmake or make, the goal is = having those files in package or after "make install") .=20 CMake can do that run scripts at install time with INSTALL(CODE ) The code snippet in question lands in = ${CMAKE_CURRENT_BINARY_DIR}/cmake_install.cmake, and you can inspect it = for correctness (the cmake_install.cmake is something that runs on "make install" or also = during the packaging phase).=20 4) CMAKE_HOST_SYSTEM variable you mention seem to be crosscompiling = related. CMAKE_SYSTEM_NAME, CMAKE_SYSTEM_VERSION and CMAKE_SYSTEM_PROCESSOR is = what is used everywhere else (e.g in the same top-level CMakeLists.txt) Also , CMake 2.6.0 is really old now, the online documentation reflects = the latest patch version (for 2.6, it would be 2.6.4 ( May 2009), and not 2.6.0 (May 2008)) I allowed myself to modify your patch (see attachment), the changes are = related to a) avoid writing to CMAKE_SOURCE_DIR. I made VERSION_SRC to always = write to ${CMAKE_BINARY_DIR}/VERSION_src b) avoid doing extra stuff during cmake or build stage. Moved generation = of VERSION_xxx to packaging/install/make_dist stage c) fixed Windows date mentioned above I did not fix the CMAKE_HOST_SYSTEM though Have a look, perhaps you would find it useful. Vlad > -----Original Message----- > From: Joerg Bruehe [mailto:joerg.bruehe@stripped] > Sent: Samstag, 22. Januar 2011 12:08 > To: Vladislav Vaintroub > Cc: commits@stripped > Subject: Re: bzr commit into mysql-5.5-bugteam branch (joerg:3209) = Bug#42969 >=20 > Hi Vlad, >=20 >=20 > thank you very much for looking at my patch and commenting. >=20 > Vladislav Vaintroub wrote: > > Hi Joerg, > > > >> -----Original Message----- > >> From: Joerg Bruehe [mailto:joerg@stripped] > >> Sent: Freitag, 21. Januar 2011 21:40 > >> To: commits@stripped > >> Subject: bzr commit into mysql-5.5-bugteam branch (joerg:3209) = Bug#42969 > > > > > >> +ADD_CUSTOM_TARGET(VERSION_BIN ALL > >> + COMMAND ${CMAKE_COMMAND} -P = ${CMAKE_BINARY_DIR}/version_files.cmake > >> + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} > >> +) > > > > A problem with ADD_CUSTOM_TARGET when it is used like this is that = it is always rebuilt (there are no inputs and not outputs , so it > > is always considered out-of-date). However there is a way to make it = work more like classic make utility with input and output, > > where rebuild is done only if input changes. >=20 > Yes, I am aware of it being rebuilt every time. While that is = considered > waste of cycles in a typical compilation, I in fact favor it here: >=20 > - Creating that file should be little effort, so it should not = increase > the build time in any noticeable way. >=20 > - If we extend the rule for "VERSION_bin" by looking at further files, > we would need to extend the dependencies in your approach. As = written > above, this has proved to be difficult. >=20 > - The brute force approach "do it always" ensures that even manual > interventions which change any of the prerequisite files (like > "flags.cmake") will be reflected in "VERSION_bin". >=20 > - "VERSION_bin" also contains a timestamp, IMO that should be that of > the (last) "make" run. >=20 > > > > How about something like: > > > > ADD_CUSTOM_COMMAND( > > OUTPUT ${CMAKE_BINARY_DIR}/VERSION_bin > > COMMAND ${CMAKE_COMMAND} -P = ${CMAKE_BINARY_DIR}/version_files.cmake > > DEPENDS ${CMAKE_BINARY_DIR}/CMakeCache.txt > > ) > > > > ADD_CUSTOM_TARGET(VERSION_BIN ALL > > DEPENDS ${CMAKE_BINARY_DIR}/VERSION_bin) > > > > Disclaimer: I have not tried that with your patch :) just took the = technique from the Cmake FAQ ( > > http://www.cmake.org/Wiki/CMake_FAQ , section "How do I generate an = executable, then use the executable to generate a file? " > ) and > > applied to your example (your example is simpler, because you do not = have to generate an executable). I assumed you generate > the > > VERSION_bin from CMakeCache.txt and there are no other dependencies = , at least it seems so to me. >=20 > Well, the other dependency is "sql/CMakeFiles/sql.dir/flags.make", and = I > wouldn't be surprised if we in the future add information which must = be > collected from other files. >=20 > Sadly, I have found the cmake documentation to disagree from the = acctual > behavior: > While "http://www.cmake.org/cmake/help/cmake2.6docs.html" mentions > several interesting "CMAKE_{HOST_}SYSTEM*" variables, they were not > provided in my tests (cmake 2.6.0, Debian "stable"). >=20 > Also, I had trouble with rules that used files (like "flags.make" and > "CMakeCache.txt") which were created only at the end of the cmake = phase. > That is also the reason why several of my new actions are guarded by = an > "IF(EXISTS ...)". > Maybe this can be solved by explicitly adding information these files > will be generated, but all in all cmake seems to do some existence and > dependency checks which I had expected in the make phase only. >=20 > Because of this, I'm reluctant to do more complicated cmake = constructs, > and rather favor a "keep it simple" approach. I know it isn't elegant. >=20 >=20 > However, I very much appreciate your comments and thoughts! >=20 > Regards, > J=F6rg >=20 > -- > Joerg Bruehe, MySQL Build Team, joerg.bruehe@stripped > (+49 30) 417 01 487 > ORACLE Deutschland B.V. & Co. KG, Komturstrasse 18a, D-12099 = Berlin > Geschaeftsfuehrer: Juergen Kunz, Marcel v.d. Molen, Alexander v.d. Ven > Amtsgericht Muenchen: HRA 95603 ------=_NextPart_000_003D_01CBBA4C.456CA520 Content-Type: text/plain; name="diff.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="diff.txt" =3D=3D=3D modified file 'CMakeLists.txt'=0A= --- CMakeLists.txt 2010-12-15 10:30:09 +0000=0A= +++ CMakeLists.txt 2011-01-22 14:25:10 +0000=0A= @@ -1,4 +1,4 @@=0A= -# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights = reserved.=0A= +# Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights = reserved.=0A= # =0A= # This program is free software; you can redistribute it and/or modify=0A= # it under the terms of the GNU General Public License as published by=0A= @@ -317,6 +317,19 @@=0A= ${CMAKE_BINARY_DIR}/include/mysql_version.h )=0A= CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/sql/sql_builtin.cc.in=0A= ${CMAKE_BINARY_DIR}/sql/sql_builtin.cc)=0A= +CONFIGURE_FILE(=0A= + ${CMAKE_SOURCE_DIR}/cmake/version_files.cmake.in = ${CMAKE_BINARY_DIR}/version_files.cmake @ONLY)=0A= +INSTALL(CODE=0A= + "=0A= + EXECUTE_PROCESS( =0A= + COMMAND \"${CMAKE_COMMAND}\" -P = \"${CMAKE_BINARY_DIR}/version_files.cmake\" =0A= + WORKING_DIRECTORY \"${CMAKE_BINARY_DIR}\")=0A= + FILE(INSTALL DESTINATION \"\${CMAKE_INSTALL_PREFIX}/.\" TYPE FILE = FILES=0A= + \"${CMAKE_BINARY_DIR}/VERSION_src\"=0A= + \"${CMAKE_BINARY_DIR}/VERSION_bin\"=0A= + )=0A= + "=0A= +)=0A= =0A= # Packaging=0A= IF(WIN32)=0A= @@ -331,6 +344,7 @@=0A= SET(CPACK_MONOLITHIC_INSTALL 1 CACHE INTERNAL "")=0A= =0A= INCLUDE(CPack)=0A= +=0A= IF(UNIX)=0A= INSTALL(FILES Docs/mysql.info DESTINATION ${INSTALL_INFODIR} OPTIONAL = COMPONENT Info)=0A= ENDIF()=0A= =0A= =3D=3D=3D modified file 'cmake/make_dist.cmake.in'=0A= --- cmake/make_dist.cmake.in 2010-11-20 14:47:50 +0000=0A= +++ cmake/make_dist.cmake.in 2011-01-22 14:19:37 +0000=0A= @@ -1,4 +1,4 @@=0A= -# Copyright (C) 2009 Sun Microsystems, Inc=0A= +# Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights = reserved.=0A= # =0A= # This program is free software; you can redistribute it and/or modify=0A= # it under the terms of the GNU General Public License as published by=0A= @@ -106,6 +106,12 @@=0A= EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E copy_directory = "${MYSQL_DOCS_LOCATION}" "${PACKAGE_DIR}")=0A= ENDIF()=0A= =0A= +# Ensure there is a "VERSION_src" file.=0A= +INCLUDE(${CMAKE_BINARY_DIR}/version_files.cmake)=0A= + CONFIGURE_FILE(${CMAKE_BINARY_DIR}/VERSION_src=0A= + ${PACKAGE_DIR}/VERSION_src COPYONLY)=0A= +ENDIF()=0A= +=0A= # In case we used CPack, it could have copied some=0A= # extra files that are not usable on different machines.=0A= FILE(REMOVE ${PACKAGE_DIR}/CMakeCache.txt)=0A= =0A= =3D=3D=3D added file 'cmake/version_files.cmake.in'=0A= --- cmake/version_files.cmake.in 1970-01-01 00:00:00 +0000=0A= +++ cmake/version_files.cmake.in 2011-01-22 14:05:40 +0000=0A= @@ -0,0 +1,113 @@=0A= +# Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights = reserved.=0A= +# =0A= +# This program is free software; you can redistribute it and/or modify=0A= +# it under the terms of the GNU General Public License as published by=0A= +# the Free Software Foundation; version 2 of the License.=0A= +#=0A= +# This program is distributed in the hope that it will be useful,=0A= +# but WITHOUT ANY WARRANTY; without even the implied warranty of=0A= +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the=0A= +# GNU General Public License for more details.=0A= +#=0A= +# You should have received a copy of the GNU General Public License=0A= +# along with this program; if not, write to the Free Software=0A= +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 = USA =0A= +=0A= +=0A= +# Handle/create the "VERSION_*" files describing a MySQL (server) = binary.=0A= +# This is part of the fix for bug#42969.=0A= +=0A= +SET(VERSION "@VERSION@")=0A= +SET(CMAKE_SOURCE_DIR "@CMAKE_SOURCE_DIR@")=0A= +SET(CMAKE_BINARY_DIR "@CMAKE_BINARY_DIR@")=0A= +SET(CPACK_SOURCE_PACKAGE_FILE_NAME "@CPACK_SOURCE_PACKAGE_FILE_NAME@")=0A= +SET(BZR_EXECUTABLE "@BZR_EXECUTABLE@")=0A= +SET(PACKAGE_DIR ${CMAKE_BINARY_DIR}/${CPACK_SOURCE_PACKAGE_FILE_NAME})=0A= + =0A= + =0A= +# This may be used during "make dist".=0A= +# So this is the moment to start a "VERSION_src" file with information = about the source (only).=0A= +# We use the "VERSION" contents and try to add "bzr version-info".=0A= +#=0A= +# It will also be used during build, if that is done without a = preceding "make dist"=0A= +# (typically, by developers directly in their tree).=0A= + =0A= +MACRO(CREATE_VERSION_SRC)=0A= + IF(EXISTS ${CMAKE_SOURCE_DIR}/.bzr)=0A= + # We have a working "bzr" and sources are in a BZR repository: = Always update.=0A= + EXECUTE_PROCESS(=0A= + COMMAND ${BZR_EXECUTABLE} version-info ${CMAKE_SOURCE_DIR}=0A= + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}=0A= + OUTPUT_FILE "VERSION_src"=0A= + RESULT_VARIABLE RESULT=0A= + )=0A= + # For better readability ...=0A= + FILE(APPEND "${CMAKE_BINARY_DIR}/VERSION_src" "\nMySQL source = ${VERSION}\n")=0A= + ELSEIF(NOT EXISTS ${CMAKE_BINARY_DIR}/VERSION_src)=0A= + # The following is a fall-back if there should be no BZR available.=0A= + FILE(WRITE "${CMAKE_BINARY_DIR}/VERSION_src" "\nMySQL source = ${VERSION}\n")=0A= + ENDIF()=0A= +ENDMACRO(CREATE_VERSION_SRC)=0A= +=0A= +=0A= +# This is for the "real" build, must be run again with each cmake run=0A= +# to make sure we report the current flags (not those of some previous = run).=0A= +=0A= +MACRO(CREATE_VERSION_BIN)=0A= + SET(VERSION_BIN "VERSION_bin")=0A= +=0A= + FILE(WRITE ${VERSION_BIN} "=3D=3D=3D=3D=3D Information about the = build process: =3D=3D=3D=3D=3D\n")=0A= + IF (WIN32)=0A= + EXECUTE_PROCESS(COMMAND cmd /c date /T OUTPUT_VARIABLE TMP_DATE)=0A= + ELSEIF(UNIX)=0A= + EXECUTE_PROCESS(COMMAND "date" "+%Y-%m-%d %H:%M:%S" OUTPUT_VARIABLE = TMP_DATE OUTPUT_STRIP_TRAILING_WHITESPACE)=0A= + ELSE()=0A= + SET(TMP_DATE "No date command known")=0A= + ENDIF()=0A= + SITE_NAME(HOSTNAME)=0A= + FILE(APPEND ${VERSION_BIN} "Build was run at: ${TMP_DATE} on host = '${HOSTNAME}'\n\n")=0A= +=0A= + # According to the cmake docs, this variable should always be set.=0A= + # However, it is empty in my local tests, cmake 2.6.0 on Linux = (Debian stable, Jan 2011).=0A= + # Include this code, so we will profit if a build environment does = provide that info.=0A= + IF(${CMAKE_HOST_SYSTEM})=0A= + IF(${CMAKE_CROSSCOMPILING})=0A= + FILE(APPEND ${VERSION_BIN} "Build was done for ${CMAKE_SYSTEM} = using ${CMAKE_SYSTEM_PROCESSOR}\n")=0A= + ENDIF()=0A= + FILE(APPEND ${VERSION_BIN} "Build was done on ${CMAKE_HOST_SYSTEM} = using ${CMAKE_HOST_SYSTEM_PROCESSOR}\n\n")=0A= + ENDIF()=0A= +=0A= + FILE(APPEND ${VERSION_BIN} "=3D=3D=3D=3D=3D Compiler flags used (from = the 'sql/' subdirectory): =3D=3D=3D=3D=3D\n")=0A= + IF(EXISTS sql/CMakeFiles/sql.dir/flags.make)=0A= + # current dir =3D=3D ${CMAKE_BINARY_DIR}, see the call in top = "CMakeLists.txt"=0A= + FILE(STRINGS sql/CMakeFiles/sql.dir/flags.make COMPILE_FLAGS REGEX = "^# compile|^C_|^CXX_")=0A= + STRING(REPLACE "# compile" "\n# compile" COMPILE_FLAGS_1 = ${COMPILE_FLAGS})=0A= + STRING(REPLACE "C_" "\nC_" COMPILE_FLAGS_2 = ${COMPILE_FLAGS_1})=0A= + STRING(REPLACE "CXX_" "\nCXX_" COMPILE_FLAGS_LINES = ${COMPILE_FLAGS_2})=0A= + # The below line did not work in tests using cmake 2.6.0, the = matter should be checked again with newer versions.=0A= + # STRING(REGEX REPLACE "(^# compile|^C_|^CXX_)" "\n\\1" = COMPILE_FLAGS_LINES ${COMPILE_FLAGS})=0A= + FILE(APPEND ${VERSION_BIN} ${COMPILE_FLAGS_LINES} "\n\n")=0A= + ELSE()=0A= + FILE(APPEND ${VERSION_BIN} "File = 'sql/CMakeFiles/sql.dir/flags.make' is not yet found.\n\n")=0A= + ENDIF()=0A= +=0A= + FILE(APPEND ${VERSION_BIN} "=3D=3D=3D=3D=3D Feature flags used: = =3D=3D=3D=3D=3D\n")=0A= + IF(EXISTS ${CMAKE_BINARY_DIR}/CMakeCache.txt)=0A= + # The intention is to do the equivalent of "grep '^WITH' = CMakeCache.txt".=0A= + # Note that "FILE(STRINGS ...)" will simply ignore carriage return = (CR) characters,=0A= + # so the variable will have all those lines joined to one.=0A= + # To get readable output, "STRING(REPLACE ...)" is used, making it = multi-line again.=0A= + FILE(STRINGS ${CMAKE_BINARY_DIR}/CMakeCache.txt FEATURE_FLAGS REGEX = "^WITH")=0A= + STRING(REPLACE "WITH" "\nWITH" FEATURE_FLAGS_LINES ${FEATURE_FLAGS})=0A= + FILE(APPEND ${VERSION_BIN} ${FEATURE_FLAGS_LINES} "\n\n")=0A= + ELSE()=0A= + FILE(APPEND ${VERSION_BIN} "File 'CMakeCache.txt' is not yet = found.\n\n")=0A= + ENDIF()=0A= +=0A= + FILE(APPEND ${VERSION_BIN} "=3D=3D=3D=3D=3D EOF =3D=3D=3D=3D=3D\n")=0A= +=0A= +ENDMACRO(CREATE_VERSION_BIN)=0A= +=0A= +CREATE_VERSION_BIN()=0A= +CREATE_VERSION_SRC()=0A= +=0A= =0A= =3D=3D=3D modified file 'support-files/mysql.spec.sh'=0A= --- support-files/mysql.spec.sh 2010-12-29 00:26:31 +0000=0A= +++ support-files/mysql.spec.sh 2011-01-22 12:41:02 +0000=0A= @@ -1,4 +1,4 @@=0A= -# Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights = reserved.=0A= +# Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights = reserved.=0A= #=0A= # This program is free software; you can redistribute it and/or modify=0A= # it under the terms of the GNU General Public License as published by=0A= @@ -907,6 +907,8 @@=0A= %if %{defined license_files_server}=0A= %doc %{license_files_server}=0A= %endif=0A= +%doc %{src_dir}/VERSION_src=0A= +%doc release/VERSION_bin=0A= %doc %{src_dir}/Docs/ChangeLog=0A= %doc release/support-files/my-*.cnf=0A= =0A= @@ -1085,6 +1087,10 @@=0A= # merging BK trees)=0A= = #########################################################################= #####=0A= %changelog=0A= +* Fri Jan 21 2011 Joerg Bruehe =0A= +=0A= +- Add the new "manifest" files: "VERSION_src" and "VERSION_bin".=0A= +=0A= * Tue Nov 23 2010 Jonathan Perkin =0A= =0A= - EXCEPTIONS-CLIENT has been deleted, remove it from here too=0A= =0A= ------=_NextPart_000_003D_01CBBA4C.456CA520--