Default cmake config to newest plugin format

Also update code to use convert_mapping_to_xml helper.

Change-Id: Ie41c21dae7cd7367c2b24d9c1b5b0132572e784f
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
This commit is contained in:
Thanh Ha 2017-06-27 22:56:33 -04:00
parent 8cfe815e88
commit fea089bbd6
No known key found for this signature in database
GPG Key ID: B0CB27E00DA095AA
3 changed files with 46 additions and 72 deletions

View File

@ -37,6 +37,7 @@ Example::
""" """
import logging import logging
import sys
import xml.etree.ElementTree as XML import xml.etree.ElementTree as XML
from jenkins_jobs.errors import is_sequence from jenkins_jobs.errors import is_sequence
@ -2623,67 +2624,57 @@ def cmake(registry, xml_parent, data):
""" """
BUILD_TYPES = ['Debug', 'Release', 'RelWithDebInfo', 'MinSizeRel'] BUILD_TYPES = ['Debug', 'Release', 'RelWithDebInfo', 'MinSizeRel']
cmake = XML.SubElement(xml_parent, 'hudson.plugins.cmake.CmakeBuilder') cmake = XML.SubElement(xml_parent, 'hudson.plugins.cmake.CmakeBuilder')
source_dir = XML.SubElement(cmake, 'sourceDir') mapping = [
try: ('source-dir', 'sourceDir', None), # Required parameter
source_dir.text = data['source-dir'] ('generator', 'generator', "Unix Makefiles"),
except KeyError: ('clean-build-dir', 'cleanBuild', False),
raise MissingAttributeError('source-dir') ]
helpers.convert_mapping_to_xml(cmake, data, mapping, fail_required=True)
XML.SubElement(cmake, 'generator').text = str( info = registry.get_plugin_info("CMake plugin")
data.get('generator', "Unix Makefiles")) # Note: Assume latest version of plugin is preferred config format
version = pkg_resources.parse_version(
info.get("version", str(sys.maxsize)))
XML.SubElement(cmake, 'cleanBuild').text = str(
data.get('clean-build-dir', False)).lower()
plugin_info = registry.get_plugin_info("CMake plugin")
version = pkg_resources.parse_version(plugin_info.get("version", "1.0"))
# Version 2.x breaks compatibility. So parse the input data differently
# based on it:
if version >= pkg_resources.parse_version("2.0"): if version >= pkg_resources.parse_version("2.0"):
if data.get('preload-script'): mapping_20 = [
XML.SubElement(cmake, 'preloadScript').text = str( ('preload-script', 'preloadScript', None), # Optional parameter
data.get('preload-script', '')) ('working-dir', 'workingDir', ''),
('build-type', 'buildType', 'Debug'),
XML.SubElement(cmake, 'workingDir').text = str( ('installation-name', 'installationName', 'InSearchPath'),
data.get('working-dir', '')) ('other-arguments', 'toolArgs', ''),
]
XML.SubElement(cmake, 'buildType').text = str( helpers.convert_mapping_to_xml(
data.get('build-type', 'Debug')) cmake, data, mapping_20, fail_required=False)
XML.SubElement(cmake, 'installationName').text = str(
data.get('installation-name', 'InSearchPath'))
XML.SubElement(cmake, 'toolArgs').text = str(
data.get('other-arguments', ''))
tool_steps = XML.SubElement(cmake, 'toolSteps') tool_steps = XML.SubElement(cmake, 'toolSteps')
for step_data in data.get('build-tool-invocations', []): for step_data in data.get('build-tool-invocations', []):
tagname = 'hudson.plugins.cmake.BuildToolStep' step = XML.SubElement(
step = XML.SubElement(tool_steps, tagname) tool_steps, 'hudson.plugins.cmake.BuildToolStep')
step_mapping = [
XML.SubElement(step, 'withCmake').text = str( ('use-cmake', 'withCmake', False),
step_data.get('use-cmake', False)).lower() ('arguments', 'args', ''),
('environment-variables', 'vars', ''),
XML.SubElement(step, 'args').text = str( ]
step_data.get('arguments', '')) helpers.convert_mapping_to_xml(
step, step_data, step_mapping, fail_required=True)
XML.SubElement(step, 'vars').text = str(
step_data.get('environment-variables', ''))
else: else:
XML.SubElement(cmake, 'preloadScript').text = str( mapping_10 = [
data.get('preload-script', '')) ('preload-script', 'preloadScript', ''),
('build-dir', 'buildDir', ''),
build_dir = XML.SubElement(cmake, 'buildDir') ('install-dir', 'installDir', ''),
build_dir.text = data.get('build-dir', '') ('make-command', 'makeCommand', 'make'),
('install-command', 'installCommand', 'make install'),
install_dir = XML.SubElement(cmake, 'installDir') ('other-arguments', 'cmakeArgs', ''),
install_dir.text = data.get('install-dir', '') ('custom-cmake-path', 'projectCmakePath', ''),
('clean-install-dir', 'cleanInstallDir', False),
]
helpers.convert_mapping_to_xml(
cmake, data, mapping_10, fail_required=True)
# The options buildType and otherBuildType work together on the CMake # The options buildType and otherBuildType work together on the CMake
# plugin: # plugin:
@ -2697,31 +2688,14 @@ def cmake(registry, xml_parent, data):
# option, so this was done to simplify it for the JJB user. # option, so this was done to simplify it for the JJB user.
build_type = XML.SubElement(cmake, 'buildType') build_type = XML.SubElement(cmake, 'buildType')
build_type.text = data.get('build-type', BUILD_TYPES[0]) build_type.text = data.get('build-type', BUILD_TYPES[0])
other_build_type = XML.SubElement(cmake, 'otherBuildType') other_build_type = XML.SubElement(cmake, 'otherBuildType')
if(build_type.text not in BUILD_TYPES): if build_type.text not in BUILD_TYPES:
other_build_type.text = build_type.text other_build_type.text = build_type.text
build_type.text = BUILD_TYPES[0] build_type.text = BUILD_TYPES[0]
else: else:
other_build_type.text = '' other_build_type.text = ''
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')
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_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 # The plugin generates this tag, but there doesn't seem to be anything
# that can be configurable by it. Let's keep it to maintain # that can be configurable by it. Let's keep it to maintain
# compatibility: # compatibility:

View File

@ -8,13 +8,13 @@
<preloadScript/> <preloadScript/>
<buildDir>path/to/build</buildDir> <buildDir>path/to/build</buildDir>
<installDir>path/to/install</installDir> <installDir>path/to/install</installDir>
<buildType>Debug</buildType>
<otherBuildType/>
<makeCommand>make</makeCommand> <makeCommand>make</makeCommand>
<installCommand>make install</installCommand> <installCommand>make install</installCommand>
<cmakeArgs/> <cmakeArgs/>
<projectCmakePath/> <projectCmakePath/>
<cleanInstallDir>false</cleanInstallDir> <cleanInstallDir>false</cleanInstallDir>
<buildType>Debug</buildType>
<otherBuildType/>
<builderImpl/> <builderImpl/>
</hudson.plugins.cmake.CmakeBuilder> </hudson.plugins.cmake.CmakeBuilder>
</builders> </builders>

View File

@ -8,13 +8,13 @@
<preloadScript>path/to/source/cmake.preload</preloadScript> <preloadScript>path/to/source/cmake.preload</preloadScript>
<buildDir>path/to/build</buildDir> <buildDir>path/to/build</buildDir>
<installDir>path/to/install</installDir> <installDir>path/to/install</installDir>
<buildType>Debug</buildType>
<otherBuildType>CustomReleaseType</otherBuildType>
<makeCommand>/usr/bin/make</makeCommand> <makeCommand>/usr/bin/make</makeCommand>
<installCommand>make new-install</installCommand> <installCommand>make new-install</installCommand>
<cmakeArgs>-DCMAKE_FIND_ROOT_PATH=&quot;path/to/something/else&quot;</cmakeArgs> <cmakeArgs>-DCMAKE_FIND_ROOT_PATH=&quot;path/to/something/else&quot;</cmakeArgs>
<projectCmakePath>/usr/bin/cmake</projectCmakePath> <projectCmakePath>/usr/bin/cmake</projectCmakePath>
<cleanInstallDir>true</cleanInstallDir> <cleanInstallDir>true</cleanInstallDir>
<buildType>Debug</buildType>
<otherBuildType>CustomReleaseType</otherBuildType>
<builderImpl/> <builderImpl/>
</hudson.plugins.cmake.CmakeBuilder> </hudson.plugins.cmake.CmakeBuilder>
</builders> </builders>