diff --git a/jenkins_jobs/modules/builders.py b/jenkins_jobs/modules/builders.py index 2d61c811c..b54d35479 100644 --- a/jenkins_jobs/modules/builders.py +++ b/jenkins_jobs/modules/builders.py @@ -2546,6 +2546,69 @@ def github_notifier(parser, xml_parent, data): 'com.cloudbees.jenkins.GitHubSetCommitStatusBuilder') +def scan_build(parser, xml_parent, data): + """yaml: scan-build + This plugin allows you configure a build step that will execute the Clang + scan-build static analysis tool against an XCode project. + + The scan-build report has to be generated in the directory + ``${WORKSPACE}/clangScanBuildReports`` for the publisher to find it. + + Requires the Jenkins :jenkins-wiki:`Clang Scan-Build Plugin + `. + + :arg str target: Provide the exact name of the XCode target you wish to + have compiled and analyzed (required) + :arg str target-sdk: Set the simulator version of a currently installed SDK + (default iphonesimulator) + :arg str config: Provide the XCode config you wish to execute scan-build + against (default Debug) + :arg str clang-install-name: Name of clang static analyzer to use (default + '') + :arg str xcode-sub-path: Path of XCode project relative to the workspace + (default '') + :arg str workspace: Name of workspace (default '') + :arg str scheme: Name of scheme (default '') + :arg str scan-build-args: Additional arguments to clang scan-build + (default --use-analyzer Xcode) + :arg str xcode-build-args: Additional arguments to XCode (default + -derivedDataPath $WORKSPACE/build) + :arg str report-folder: Folder where generated reports are located + (>=1.7) (default clangScanBuildReports) + + Full Example: + + .. literalinclude:: /../../tests/builders/fixtures/scan-build-full.yaml + :language: yaml + + Minimal Example: + + .. literalinclude:: + /../../tests/builders/fixtures/scan-build-minimal.yaml + :language: yaml + """ + p = XML.SubElement( + xml_parent, + 'jenkins.plugins.clangscanbuild.ClangScanBuildBuilder') + p.set('plugin', 'clang-scanbuild') + + mappings = [ + ('target', 'target', None), + ('target-sdk', 'targetSdk', 'iphonesimulator'), + ('config', 'config', 'Debug'), + ('clang-install-name', 'clangInstallationName', ''), + ('xcode-sub-path', 'xcodeProjectSubPath', 'myProj/subfolder'), + ('workspace', 'workspace', ''), + ('scheme', 'scheme', ''), + ('scan-build-args', 'scanbuildargs', '--use-analyzer Xcode'), + ('xcode-build-args', + 'xcodebuildargs', + '-derivedDataPath $WORKSPACE/build'), + ('report-folder', 'outputFolderName', 'clangScanBuildReports'), + ] + convert_mapping_to_xml(p, data, mappings, fail_required=True) + + def ssh_builder(parser, xml_parent, data): """yaml: ssh-builder Executes command on remote host diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index 1a583bfa2..2e71e5dc3 100644 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -4665,31 +4665,33 @@ def scan_build(parser, xml_parent, data): exceeds a threshold (default false) :arg int threshold: Threshold for marking builds as unstable (default 0) :arg string exclude-paths: Comma separated paths to exclude from reports - (default '') + (>=1.5) (default '') :arg string report-folder: Folder where generated reports are located - (default 'clangScanBuildReports') + (>=1.7) (default 'clangScanBuildReports') - Example: + Full Example: - .. literalinclude:: /../../tests/publishers/fixtures/scan-build001.yaml + .. literalinclude:: /../../tests/publishers/fixtures/scan-build-full.yaml + :language: yaml + + Minimal Example: + + .. literalinclude:: + /../../tests/publishers/fixtures/scan-build-minimal.yaml :language: yaml """ - threshold = str(data.get('threshold', 0)) - if not threshold.isdigit(): - raise JenkinsJobsException("Invalid value '%s' for threshold. " - "Numeric value expected." % threshold) - p = XML.SubElement( xml_parent, 'jenkins.plugins.clangscanbuild.publisher.ClangScanBuildPublisher') + p.set('plugin', 'clang-scanbuild') - XML.SubElement(p, 'markBuildUnstableWhenThresholdIsExceeded').text = \ - str(data.get('mark-unstable', False)).lower() - XML.SubElement(p, 'bugThreshold').text = threshold - XML.SubElement(p, 'clangexcludedpaths').text = str( - data.get('exclude-paths', '')) - XML.SubElement(p, 'reportFolderName').text = str( - data.get('report-folder', 'clangScanBuildReports')) + mappings = [ + ('mark-unstable', 'markBuildUnstableWhenThresholdIsExceeded', False), + ('threshold', 'bugThreshold', 0), + ('exclude-paths', 'clangexcludedpaths', ''), + ('report-folder', 'reportFolderName', 'clangScanBuildReports'), + ] + helpers.convert_mapping_to_xml(p, data, mappings, fail_required=True) def dry(parser, xml_parent, data): diff --git a/tests/builders/fixtures/scan-build-full.xml b/tests/builders/fixtures/scan-build-full.xml new file mode 100644 index 000000000..244a50f6c --- /dev/null +++ b/tests/builders/fixtures/scan-build-full.xml @@ -0,0 +1,17 @@ + + + + + path/to/target + iphonesimulator + Debug + Analyzer + myProj/subfolder + workspace + SchemeName + --use-analyzer Xcode + -derivedDataPath $WORKSPACE/build + clangScanBuildReports + + + diff --git a/tests/builders/fixtures/scan-build-full.yaml b/tests/builders/fixtures/scan-build-full.yaml new file mode 100644 index 000000000..3889fd58f --- /dev/null +++ b/tests/builders/fixtures/scan-build-full.yaml @@ -0,0 +1,12 @@ +builders: + - scan-build: + target: path/to/target + target-sdk: iphonesimulator + config: Debug + clang-install-name: Analyzer + xcode-sub-path: myProj/subfolder + workspace: workspace + scheme: SchemeName + scan-build-args: --use-analyzer Xcode + xcode-build-args: -derivedDataPath $WORKSPACE/build + report-folder: clangScanBuildReports diff --git a/tests/builders/fixtures/scan-build-minimal.xml b/tests/builders/fixtures/scan-build-minimal.xml new file mode 100644 index 000000000..87ab245a7 --- /dev/null +++ b/tests/builders/fixtures/scan-build-minimal.xml @@ -0,0 +1,17 @@ + + + + + path/to/target + iphonesimulator + Debug + + myProj/subfolder + + + --use-analyzer Xcode + -derivedDataPath $WORKSPACE/build + clangScanBuildReports + + + diff --git a/tests/builders/fixtures/scan-build-minimal.yaml b/tests/builders/fixtures/scan-build-minimal.yaml new file mode 100644 index 000000000..a7da720bd --- /dev/null +++ b/tests/builders/fixtures/scan-build-minimal.yaml @@ -0,0 +1,3 @@ +builders: + - scan-build: + target: path/to/target diff --git a/tests/publishers/fixtures/scan-build-full.xml b/tests/publishers/fixtures/scan-build-full.xml new file mode 100644 index 000000000..e6806e9a0 --- /dev/null +++ b/tests/publishers/fixtures/scan-build-full.xml @@ -0,0 +1,11 @@ + + + + + true + 50 + external-lib + scan-build-report + + + diff --git a/tests/publishers/fixtures/scan-build-full.yaml b/tests/publishers/fixtures/scan-build-full.yaml new file mode 100644 index 000000000..884e6c65c --- /dev/null +++ b/tests/publishers/fixtures/scan-build-full.yaml @@ -0,0 +1,6 @@ +publishers: + - scan-build: + mark-unstable: true + threshold: 50 + exclude-paths: external-lib + report-folder: scan-build-report diff --git a/tests/publishers/fixtures/scan-build002.xml b/tests/publishers/fixtures/scan-build-minimal.xml similarity index 93% rename from tests/publishers/fixtures/scan-build002.xml rename to tests/publishers/fixtures/scan-build-minimal.xml index efd1d8c52..161cb5ee5 100644 --- a/tests/publishers/fixtures/scan-build002.xml +++ b/tests/publishers/fixtures/scan-build-minimal.xml @@ -1,7 +1,7 @@ - + false 0 diff --git a/tests/publishers/fixtures/scan-build002.yaml b/tests/publishers/fixtures/scan-build-minimal.yaml similarity index 100% rename from tests/publishers/fixtures/scan-build002.yaml rename to tests/publishers/fixtures/scan-build-minimal.yaml diff --git a/tests/publishers/fixtures/scan-build001.xml b/tests/publishers/fixtures/scan-build001.xml index 261c50150..d1c9964bb 100644 --- a/tests/publishers/fixtures/scan-build001.xml +++ b/tests/publishers/fixtures/scan-build001.xml @@ -1,7 +1,7 @@ - + true 0 external-lib