|
|
(8 intermediate revisions by 4 users not shown) |
Line 1: |
Line 1: |
| = Indroduction =
| | {{CMake/Template/Moved}} |
| [[Image:Buildmanagement.svg|right|Overview]]
| |
| In a normal CTest installation you have a central repository for your sourcecode. Each client has a special configuration to know how to get the source, build and test it. After finishing the results will be sent to central CDash. This configuration has to set up at each of the clients. If you create a new branch in your repository and want to get it build by all clients you must change the configuration at each of the clients.
| |
|
| |
|
| This solution adds the possibility to manage this in a central place (at the BuildMaster). | | This page has moved [https://gitlab.kitware.com/cmake/community/wikis/doc/ctest/Buildserver here]. |
| | |
| == How it works ==
| |
| Each BuildSlave asks the BuildMaster for a list of buildnames. Then the BuildSlave downloads a CTestScript.cmake for each buildname and executes it.
| |
| | |
| == Requirements ==
| |
| * CMake/CTest
| |
| * wget
| |
| * webserver with PHP support
| |
| | |
| = Installation =
| |
| | |
| == Buildmaster ==
| |
| Change into your document root directory of your webserver and create a direcotry "CDash", if it does not exesit already.
| |
| Save the following content as generateCTestScript.php in the CDash direcotory:
| |
| @$site = $_GET["site"];
| |
| @$build_name = $_GET["buildname"];
| |
|
| |
| // Checks
| |
| if(!isset($site))
| |
| {
| |
| echo "Not a valid site!";
| |
| return;
| |
| }
| |
|
| |
| // THIS CONFIGURATION SHOULD COME FROM THE DATABASE
| |
| $config_from_database = array(
| |
| "BUILDSERVER1" => array(
| |
| "Test1" => array(
| |
| "@CTS_CMAKE_GENERATOR@" => "Unix Makefiles")),
| |
| "BUILDSERVER2" => array(
| |
| "Test1" => array(
| |
| "@CTS_CMAKE_GENERATOR@" => "Unix Makefiles")),
| |
| "BUILDSERVER3" => array(
| |
| "Test1" => array(
| |
| "@CTS_CMAKE_GENERATOR@" => "NMake Makefiles"),
| |
| "Test2" => array(
| |
| "@CTS_CMAKE_GENERATOR@" => "NMake Makefiles",
| |
| "@CTS_REPOSITORY_URL@" => "http://VERSIONCONTROL/svn/test2/trunk"),
| |
| "Test3" => array(
| |
| "@CTS_CMAKE_GENERATOR@" => "NMake Makefiles",
| |
| "@CTS_REPOSITORY_URL@" => "http://VERSIONCONTROL/svn/test3/branches/next_release")),
| |
| "BUILDSERVER4" => array(
| |
| "Test1" => array(
| |
| "@CTS_CMAKE_GENERATOR@" => "NMake Makefiles")));
| |
|
| |
|
| |
| // no build given, so Generate overviewlist
| |
| if(!isset($build_name))
| |
| {
| |
| $list = array_keys($config_from_database[$site]);
| |
|
| |
| header('Content-Type: text/plain');
| |
| echo implode("\n", $list);
| |
| return;
| |
| }
| |
|
| |
| // DEFAULT SETTINGS
| |
| $script_parameter = array(
| |
| "@CTS_SITE@" => $site,
| |
| "@CTS_PROJECT_NAME@" => "Test",
| |
| "@CTS_BUILD_NAME@" => $build_name,
| |
| "@CTS_NIGHTLY_START_TIME@" => "22:00:00 UTC",
| |
| "@CTS_CMAKE_GENERATOR@" => "Unix Makefiles",
| |
| "@CTS_BUILD_CONFIGURATION@" => "Release",
| |
| "@CTS_CTEST_MODEL@" => "Continuous",
| |
| "@CTS_BUILD_OPTIONS@" => "-DEXAMPLE_OPTION=1",
| |
| "@CTS_REPOSITORY_URL@" => "http://VERSIONCONTROL/svn/test1");
| |
|
| |
| // template.txt SHOULD ALSO COME FROM THE DATABASE
| |
| $ctestscript = strtr(strtr(implode(file("template.txt")), $config_from_database[$site][$build_name]), $script_parameter);
| |
|
| |
| header('Vary: User-Agent');
| |
| if(ob_get_contents())
| |
| echo "Some data has already been output";
| |
| if(isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'],'MSIE'))
| |
| header('Content-Type: application/force-download');
| |
| else
| |
| header('Content-Type: application/octet-stream');
| |
| if(headers_sent())
| |
| echo "Some data has already been output to browser";
| |
|
| |
| header("Content-Disposition: attachment; filename=\"CTestScript.cmake\"");
| |
| header("Content-Transfer-Encoding: binary");
| |
| header("Content-Length: ".strlen($ctestscript));
| |
| echo $ctestscript;
| |
|
| |
| ?>
| |
| The following is an example for the template.txt, which also does a upload of a generated NSIS setup:
| |
| SET(CTEST_SITE "@CTS_SITE@")
| |
| SET(CTEST_PROJECT_NAME "@CTS_PROJECT_NAME@")
| |
| SET(CTEST_BUILD_NAME "@CTS_BUILD_NAME@")
| |
| SET(CTEST_NIGHTLY_START_TIME "@CTS_NIGHTLY_START_TIME@")
| |
| SET(CTEST_CMAKE_GENERATOR "@CTS_CMAKE_GENERATOR@")
| |
| SET(CTEST_BUILD_CONFIGURATION "@CTS_BUILD_CONFIGURATION@")
| |
| SET(MODEL "@CTS_CTEST_MODEL@")
| |
|
| |
| SET(BUILD_OPTIONS "@CTS_BUILD_OPTIONS@")
| |
| SET(REPOSITORY_URL "@CTS_REPOSITORY_URL@")
| |
|
| |
|
| |
| FIND_PACKAGE(Subversion)
| |
|
| |
| SET(CTEST_SOURCE_DIRECTORY "${CTEST_SCRIPT_DIRECTORY}/source")
| |
| SET(CTEST_BINARY_DIRECTORY "${CTEST_SCRIPT_DIRECTORY}/build")
| |
|
| |
| SET(CTEST_UPDATE_COMMAND ${Subversion_SVN_EXECUTABLE})
| |
|
| |
| IF(NOT DEFINED CTEST_DROP_METHOD)
| |
| SET(CTEST_DROP_METHOD "http")
| |
| ENDIF(NOT DEFINED CTEST_DROP_METHOD)
| |
|
| |
| IF(CTEST_DROP_METHOD STREQUAL "http")
| |
| SET(CTEST_DROP_SITE "BUILDMASTER")
| |
| SET(CTEST_DROP_LOCATION "/CDash/submit.php?project=${CTEST_PROJECT_NAME}")
| |
| SET(CTEST_DROP_BUILD_LOCATION "/CDash/uploadbuild.php?project=${CTEST_PROJECT_NAME}")
| |
| SET(CTEST_TRIGGER_SITE "")
| |
| ENDIF(CTEST_DROP_METHOD STREQUAL "http")
| |
|
| |
|
| |
| STRING(COMPARE NOTEQUAL "${MODEL}" "Continuous" SUBMIT_ALWAYS)
| |
| SET(NEED_REPOSITORY_CHECKOUT 1)
| |
|
| |
| IF(EXISTS "${CTEST_SOURCE_DIRECTORY}")
| |
| Subversion_WC_INFO("${CTEST_SOURCE_DIRECTORY}" REPOSITORY)
| |
|
| |
| STRING(COMPARE NOTEQUAL "${REPOSITORY_URL}" "${REPOSITORY_WC_URL}" NEED_REPOSITORY_CHECKOUT)
| |
|
| |
| IF(${NEED_REPOSITORY_CHECKOUT})
| |
| FILE(REMOVE_RECURSE "${CTEST_SOURCE_DIRECTORY}")
| |
| ENDIF(${NEED_REPOSITORY_CHECKOUT})
| |
| ELSE(EXISTS "${CTEST_SOURCE_DIRECTORY}")
| |
| SET(NEED_REPOSITORY_CHECKOUT 1)
| |
| ENDIF(EXISTS "${CTEST_SOURCE_DIRECTORY}")
| |
|
| |
| IF(${NEED_REPOSITORY_CHECKOUT})
| |
| SET(CTEST_CHECKOUT_COMMAND "${CTEST_UPDATE_COMMAND} co ${REPOSITORY_URL} \"${CTEST_SOURCE_DIRECTORY}\" -r HEAD")
| |
| ELSE(${NEED_REPOSITORY_CHECKOUT})
| |
| SET(CTEST_CHECKOUT_COMMAND "${CTEST_UPDATE_COMMAND} update")
| |
| ENDIF(${NEED_REPOSITORY_CHECKOUT})
| |
|
| |
|
| |
| SET(CTEST_CONFIGURE_COMMAND "${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=${CTEST_BUILD_CONFIGURATION} ${BUILD_OPTIONS} \"-G${CTEST_CMAKE_GENERATOR}\" \"${CTEST_SOURCE_DIRECTORY}\"")
| |
|
| |
| CTEST_START(${MODEL})
| |
|
| |
| IF(${CTEST_SCRIPT_ARG} MATCHES ${MODEL})
| |
| CTEST_UPDATE(SOURCE "${CTEST_SOURCE_DIRECTORY}" RETURN_VALUE NUMBER_FILES)
| |
|
| |
| IF(${SUBMIT_ALWAYS} OR ${NEED_REPOSITORY_CHECKOUT} OR ${NUMBER_FILES} GREATER 0)
| |
| CTEST_CONFIGURE(BUILD "${CTEST_BINARY_DIRECTORY}")
| |
| CTEST_BUILD(BUILD "${CTEST_BINARY_DIRECTORY}")
| |
| CTEST_TEST(BUILD "${CTEST_BINARY_DIRECTORY}")
| |
| CTEST_SUBMIT()
| |
|
| |
| EXECUTE_PROCESS(COMMAND "cpack" WORKING_DIRECTORY ${CTEST_BINARY_DIRECTORY} RESULT_VARIABLE cpackResult OUTPUT_VARIABLE cpackLog ERROR_VARIABLE cpackLog)
| |
| FILE(WRITE ${CTEST_BINARY_DIRECTORY}/Testing/cpack.log "${cpackLog}")
| |
| FILE(GLOB EXE_FILES RELATIVE "${CTEST_BINARY_DIRECTORY}" "build/*.exe")
| |
| FOREACH(_currentArg ${EXE_FILES})
| |
| EXECUTE_PROCESS(COMMAND wget "${CTEST_DROP_METHOD}://${CTEST_DROP_SITE}${CTEST_DROP_BUILD_LOCATION}&fn=${_currentArg}" "--post-file=${CTEST_BINARY_DIRECTORY}/${_currentArg}" "-o${CTEST_BINARY_DIRECTORY}/Testing/upload.log" "-q")
| |
| FILE(REMOVE "${CTEST_BINARY_DIRECTORY}/${_currentArg}")
| |
| ENDFOREACH(_currentArg)
| |
| ENDIF(${SUBMIT_ALWAYS} OR ${NEED_REPOSITORY_CHECKOUT} OR ${NUMBER_FILES} GREATER 0)
| |
| ENDIF(${CTEST_SCRIPT_ARG} MATCHES ${MODEL})
| |
| | |
| == Linux BuildSlave ==
| |
| Create a a directory "/var/builds" and save the following shell script as make.sh in this directory
| |
| cd /var/builds
| |
| site=BUILDSLAVE1
| |
|
| |
| wget http://BUILDMASTER/CDash/generateCTestScript.php?site=$site\&buildtype=$1 -O list.txt -q
| |
|
| |
| for d in $(ls -d */); do
| |
| SKIP_DELETE=0
| |
|
| |
| for p in $(cat list.txt); do
| |
| if [ $p = ${d%%/} ]; then
| |
| SKIP_DELETE=1
| |
| fi
| |
| done
| |
|
| |
| if [ $SKIP_DELETE = 0 ]; then
| |
| rm -r ${d%%/}
| |
| fi
| |
| done
| |
|
| |
| for p in $(cat list.txt); do
| |
| if [ ! -d $p ]; then
| |
| mkdir $p
| |
| fi
| |
|
| |
| cd $p
| |
| wget http://BUILDMASTER/CDash/generateCTestScript.php?site=$site\&buildname=$p -O CTestScript.cmake -q
| |
| ctest -S CTestScript.cmake,$1
| |
| cd ..
| |
| done
| |
|
| |
| rm list.txt
| |
| Finaly you have to create a cron job (see [[CMake_Scripting_Of_CTest|CTest Scripting]]) for each buildtype (Nightly, Continuous), which will execute this shell script:
| |
| * For a nightly build create a job to execute "/var/builds/make.sh Nightly" at your CTEST_NIGHTLY_START_TIME.
| |
| * To setup a continuous build create a job, which will execute "/var/builds/make.sh Continuous" every minute.
| |
| | |
| == Windows BuildSlave ==
| |
| Create a a directory "C:\builds" and save the following batch script as make.bat in this directory
| |
| @echo off
| |
| set site=BUILDSLAVE3
| |
|
| |
| call "C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\vcvars32.bat"
| |
|
| |
| if not exist %1 mkdir %1
| |
| pushd %1
| |
|
| |
| wget http://BUILDMASTER/CDash/generateCTestScript.php?site=%site%^&buildtype=%1 -O list.txt -q
| |
|
| |
| for /D %%d in (*) do (
| |
| if exist skip_delete.flag del skip_delete.flag
| |
| for /f %%p in (list.txt) do (
| |
| if %%p == %%d echo 0 > skip_delete.flag
| |
| )
| |
|
| |
| if not exist skip_delete.flag rmdir /S /Q %%d
| |
| )
| |
|
| |
| if exist skip_delete.flag del skip_delete.flag
| |
|
| |
| for /f %%p in (list.txt) do (
| |
| if not exist %%p mkdir %%p
| |
|
| |
| if not exist %%p.lock (
| |
| echo 0 > %%p.lock
| |
|
| |
| pushd %%p
| |
| wget http://BUILDMASTER/CDash/generateCTestScript.php?site=%site%^&buildname=%%p -O CTestScript.cmake -q
| |
| ctest -S CTestScript.cmake,%1
| |
| popd
| |
|
| |
| del %%p.lock
| |
| )
| |
| )
| |
|
| |
| del list.txt
| |
| popd
| |
| Finaly you have to create a sheduled task (see [[CMake_Scripting_Of_CTest|CTest Scripting]]) for each buildtype (Nightly, Continuous), which will execute this batch file:
| |
| * For a nightly build create a task to execute "C:\builds\make.bat Nightly" at your CTEST_NIGHTLY_START_TIME.
| |
| * To setup a continuous build create a task, which will execute "C:\builds\make.bat Continuous" every minute.
| |