From 7cb821e1667396641b61d03f8a2ab919f830c1cf Mon Sep 17 00:00:00 2001 From: Lucas Dutra Nunes Date: Thu, 13 Nov 2014 11:07:17 -0200 Subject: [PATCH] builders: add cmakebuilder plugin support The cmakebuilder plugin is used to configure CMake builds to Jenkins, being able to set several directories and variables related to CMake. All the possible configurations for the plugin can be set with this builder. Also included on this change are the documentation and two test cases, one for common usage types and another more complete. More information about the plugin can be found at: https://wiki.jenkins-ci.org/display/JENKINS/cmakebuilder+Plugin Change-Id: I3f62515d7dc2d3b6e5726ebe06c53e72de5cde90 Signed-off-by: Lucas Dutra Nunes --- jenkins_jobs/modules/builders.py | 128 ++++++++++++++++++++ setup.cfg | 1 + tests/builders/fixtures/cmake-common.xml | 21 ++++ tests/builders/fixtures/cmake-common.yaml | 8 ++ tests/builders/fixtures/cmake-complete.xml | 21 ++++ tests/builders/fixtures/cmake-complete.yaml | 14 +++ 6 files changed, 193 insertions(+) create mode 100644 tests/builders/fixtures/cmake-common.xml create mode 100644 tests/builders/fixtures/cmake-common.yaml create mode 100644 tests/builders/fixtures/cmake-complete.xml create mode 100644 tests/builders/fixtures/cmake-complete.yaml diff --git a/jenkins_jobs/modules/builders.py b/jenkins_jobs/modules/builders.py index 3d3deb079..d3586abf8 100644 --- a/jenkins_jobs/modules/builders.py +++ b/jenkins_jobs/modules/builders.py @@ -1497,3 +1497,131 @@ def managed_script(parser, xml_parent, data): args = XML.SubElement(ms, 'buildStepArgs') for arg in data.get('args', []): XML.SubElement(args, 'string').text = arg + + +def cmake(parser, xml_parent, data): + """yaml: cmake + Execute a CMake target. Requires the Hudson `cmakebuilder Plugin. + `_ + + :arg str source-dir: the source code directory relative to the workspace + directory. (required) + :arg str build-dir: The directory where the project will be built in. + Relative to the workspace directory. (optional) + :arg list install-dir: The directory where the project will be installed + in, relative to the workspace directory. (optional) + :arg list build-type: Sets the "build type" option. A custom type different + than the default ones specified on the CMake plugin can also be set, + which will be automatically used in the "Other Build Type" option of + the plugin. (default: Debug) + + :type Default types present in the CMake plugin: + * **Debug** + * **Release** + * **RelWithDebInfo** + * **MinSizeRel** + + :arg list generator: The makefile generator (default: "Unix Makefiles"). + + :type Possible generators: + * **Borland Makefiles** + * **CodeBlocks - MinGW Makefiles** + * **CodeBlocks - Unix Makefiles** + * **Eclipse CDT4 - MinGW Makefiles** + * **Eclipse CDT4 - NMake Makefiles** + * **Eclipse CDT4 - Unix Makefiles** + * **MSYS Makefiles** + * **MinGW Makefiles** + * **NMake Makefiles** + * **Unix Makefiles** + * **Visual Studio 6** + * **Visual Studio 7 .NET 2003** + * **Visual Studio 8 2005** + * **Visual Studio 8 2005 Win64** + * **Visual Studio 9 2008** + * **Visual Studio 9 2008 Win64** + * **Watcom WMake** + + :arg str make-command: The make command (default: "make"). + :arg str install-command: The install command (default: "make install"). + :arg str preload-script: Path to a CMake preload script file. (optional) + :arg str other-arguments: Other arguments to be added to the CMake + call. (optional) + :arg str custom-cmake-path: Path to cmake executable. (optional) + :arg bool clean-build-dir: If true, delete the build directory before each + build (default: false). + :arg bool clean-install-dir: If true, delete the install dir before each + build (default: false). + + Example: + + .. literalinclude:: ../../tests/builders/fixtures/cmake-common.yaml + :language: yaml + """ + + BUILD_TYPES = ['Debug', 'Release', 'RelWithDebInfo', 'MinSizeRel'] + + cmake = XML.SubElement(xml_parent, 'hudson.plugins.cmake.CmakeBuilder') + + source_dir = XML.SubElement(cmake, 'sourceDir') + try: + source_dir.text = data['source-dir'] + except KeyError: + raise JenkinsJobsException("'source-dir' must be set for CMake " + "builder") + + build_dir = XML.SubElement(cmake, 'buildDir') + build_dir.text = data.get('build-dir', '') + + install_dir = XML.SubElement(cmake, 'installDir') + install_dir.text = data.get('install-dir', '') + + # The options buildType and otherBuildType work together on the CMake + # plugin: + # * If the passed value is one of the predefined values, set buildType to + # it and otherBuildType to blank; + # * Otherwise, set otherBuildType to the value, and buildType to + # "Debug". The CMake plugin will ignore the buildType option. + # + # It is strange and confusing that the plugin author chose to do something + # like that instead of simply passing a string "buildType" option, so this + # was done to simplify it for the JJB user. + build_type = XML.SubElement(cmake, 'buildType') + build_type.text = data.get('build-type', BUILD_TYPES[0]) + + other_build_type = XML.SubElement(cmake, 'otherBuildType') + + if(build_type.text not in BUILD_TYPES): + other_build_type.text = build_type.text + build_type.text = BUILD_TYPES[0] + else: + other_build_type.text = '' + + generator = XML.SubElement(cmake, 'generator') + generator.text = data.get('generator', "Unix Makefiles") + + make_command = XML.SubElement(cmake, 'makeCommand') + make_command.text = data.get('make-command', 'make') + + install_command = XML.SubElement(cmake, 'installCommand') + install_command.text = data.get('install-command', 'make install') + + preload_script = XML.SubElement(cmake, 'preloadScript') + preload_script.text = data.get('preload-script', '') + + other_cmake_args = XML.SubElement(cmake, 'cmakeArgs') + other_cmake_args.text = data.get('other-arguments', '') + + custom_cmake_path = XML.SubElement(cmake, 'projectCmakePath') + custom_cmake_path.text = data.get('custom-cmake-path', '') + + clean_build_dir = XML.SubElement(cmake, 'cleanBuild') + clean_build_dir.text = str(data.get('clean-build-dir', False)).lower() + + clean_install_dir = XML.SubElement(cmake, 'cleanInstallDir') + clean_install_dir.text = str(data.get('clean-install-dir', + False)).lower() + + # The plugin generates this tag, but there doesn't seem to be anything + # that can be configurable by it. Let's keep it to mantain compatibility: + XML.SubElement(cmake, 'builderImpl') diff --git a/setup.cfg b/setup.cfg index 34e5409f0..3d7ad958e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -46,6 +46,7 @@ jenkins_jobs.builders = batch=jenkins_jobs.modules.builders:batch builders-from=jenkins_jobs.modules.builders:builders_from change-assembly-version=jenkins_jobs.modules.builders:change_assembly_version + cmake=jenkins_jobs.modules.builders:cmake conditional-step=jenkins_jobs.modules.builders:conditional_step copyartifact=jenkins_jobs.modules.builders:copyartifact critical-block-start=jenkins_jobs.modules.builders:critical_block_start diff --git a/tests/builders/fixtures/cmake-common.xml b/tests/builders/fixtures/cmake-common.xml new file mode 100644 index 000000000..002ff263d --- /dev/null +++ b/tests/builders/fixtures/cmake-common.xml @@ -0,0 +1,21 @@ + + + + + path/to/source + path/to/build + path/to/install + Debug + + Unix Makefiles + make + make install + + + + false + false + + + + diff --git a/tests/builders/fixtures/cmake-common.yaml b/tests/builders/fixtures/cmake-common.yaml new file mode 100644 index 000000000..61bf1e002 --- /dev/null +++ b/tests/builders/fixtures/cmake-common.yaml @@ -0,0 +1,8 @@ +builders: + - cmake: + source-dir: 'path/to/source' + build-dir: 'path/to/build' + install-dir: 'path/to/install' + build-type: 'Debug' + clean-build-dir: false + clean-install-dir: false diff --git a/tests/builders/fixtures/cmake-complete.xml b/tests/builders/fixtures/cmake-complete.xml new file mode 100644 index 000000000..554c11c37 --- /dev/null +++ b/tests/builders/fixtures/cmake-complete.xml @@ -0,0 +1,21 @@ + + + + + path/to/source + path/to/build + path/to/install + Debug + CustomReleaseType + NMake Makefiles + /usr/bin/make + make new-install + path/to/source/cmake.preload + -DCMAKE_FIND_ROOT_PATH="path/to/something/else" + /usr/bin/cmake + true + true + + + + diff --git a/tests/builders/fixtures/cmake-complete.yaml b/tests/builders/fixtures/cmake-complete.yaml new file mode 100644 index 000000000..d57336cc2 --- /dev/null +++ b/tests/builders/fixtures/cmake-complete.yaml @@ -0,0 +1,14 @@ +builders: + - cmake: + source-dir: 'path/to/source' + build-dir: 'path/to/build' + install-dir: 'path/to/install' + build-type: 'CustomReleaseType' + generator: 'NMake Makefiles' + make-command: '/usr/bin/make' + install-command: 'make new-install' + preload-script: 'path/to/source/cmake.preload' + other-arguments: '-DCMAKE_FIND_ROOT_PATH="path/to/something/else"' + custom-cmake-path: '/usr/bin/cmake' + clean-build-dir: true + clean-install-dir: true