From: Thanh Ha Date: Tue, 24 Jul 2018 00:54:58 +0000 (-0400) Subject: Add cmake-verify job template X-Git-Tag: v0.23.0~4 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=f0dae8046088b145652b9da6a15068b8c99ced6c;p=releng%2Fglobal-jjb.git Add cmake-verify job template CMake verify job template for building CMake based projects. Issue: RELENG-1074 Change-Id: Iccd3bab1d9f17071583a03e84b35bcd729161195 Signed-off-by: Thanh Ha --- diff --git a/docs/index.rst b/docs/index.rst index e275c85e..4c2b447d 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -40,14 +40,10 @@ Job template code is in the `jjb/` directory but documentation is in the `docs/jjb/` directory of this project. .. toctree:: + :glob: :maxdepth: 1 - jjb/lf-ci-jobs - jjb/lf-macros - jjb/lf-maven-jobs - jjb/lf-node-jobs - jjb/lf-python-jobs - jjb/lf-rtd-jobs + jjb/* Indices and tables ================== diff --git a/docs/jjb/lf-c-cpp-jobs.rst b/docs/jjb/lf-c-cpp-jobs.rst new file mode 100644 index 00000000..9e0cf7be --- /dev/null +++ b/docs/jjb/lf-c-cpp-jobs.rst @@ -0,0 +1,53 @@ +########## +C/C++ Jobs +########## + +Job Templates +============= + +CMake Verify +------------ + +Verify job which runs cmake && make && make install to test a project build.. + +:Template Names: + + - {project-name}-cmake-verify-{stream} + - gerrit-cmake-verify + - github-cmake-verify + +:Required parameters: + + :build-node: The node to run build on. + :jenkins-ssh-credential: Credential to use for SSH. + (Configure in defaults.yaml) + +:Optional parameters: + + :branch: Git branch to fetch for the build. (default: master) + :build-days-to-keep: Days to keep build logs in Jenkins. (default: 7) + :build-dir: Directory to build the project in. (default: $WORKSPACE/target) + :build-timeout: Timeout in minutes before aborting build. (default: 60) + :cmake-opts: Parameters to pass to cmake. (default: '') + :git-url: URL clone project from. (default: $GIT_URL/$PROJECT) + :install-prefix: CMAKE_INSTALL_PREFIX to use for install. + (default: $BUILD_DIR/output) + + .. code-block:: bash + :caption: Example + + install-prefix: | + #!/bin/bash + echo "Hello World." + + :make-opts: Parameters to pass to make. (default: '') + :pre-build: Shell script to run before performing build. Useful for + setting up dependencies. (default: '') + :stream: Keyword that to represent a release code-name. + Often the same as the branch. (default: master) + :submodule-recursive: Whether to checkout submodules recursively. + (default: true) + + :gerrit_verify_triggers: Override Gerrit Triggers. + :gerrit_trigger_file_paths: Override file paths which to filter which file + modifications will trigger a build. diff --git a/docs/jjb/lf-macros.rst b/docs/jjb/lf-macros.rst index 419c2c61..8a4fb0c1 100644 --- a/docs/jjb/lf-macros.rst +++ b/docs/jjb/lf-macros.rst @@ -228,6 +228,12 @@ Forcibly removes all of the docker images. Parameters ========== +lf-cmake-parameters +------------------- + +Provides parameters needed by CMake. Should be used by any jobs that need to +call the ``cmake && make && make install`` pattern. + lf-infra-maven-parameters ------------------------- diff --git a/jjb/lf-c-cpp-jobs.yaml b/jjb/lf-c-cpp-jobs.yaml new file mode 100644 index 00000000..a5da02b0 --- /dev/null +++ b/jjb/lf-c-cpp-jobs.yaml @@ -0,0 +1,132 @@ +--- +################ +# CMAKE VERIFY # +################ + +- lf_cmake_verify: &lf_cmake_verify + name: lf-cmake-verify + + ###################### + # Default parameters # + ###################### + + branch: master + build-days-to-keep: 7 + build-dir: '$WORKSPACE/target' + build-timeout: 15 + cmake-opts: '' + git-url: '$GIT_URL/$PROJECT' + install-prefix: '$BUILD_DIR/output' + make-opts: '' + pre-build: '' + stream: master + submodule-recursive: true + + gerrit_verify_triggers: + - patchset-created-event: + exclude-drafts: true + exclude-trivial-rebase: false + exclude-no-code-change: false + - draft-published-event + - comment-added-contains-event: + comment-contains-value: '^Patch Set[ ]+[0-9]+:([ ]+|[\n]+)(recheck|reverify)$' + + gerrit_trigger_file_paths: + - compare-type: REG_EXP + pattern: '.*' + + # github_included_regions MUST match gerrit_trigger_file_paths + github_included_regions: + - '.*' + + ##################### + # Job Configuration # + ##################### + + project-type: freestyle + node: '{build-node}' + + properties: + - lf-infra-properties: + build-days-to-keep: '{build-days-to-keep}' + + parameters: + - lf-infra-parameters: + project: '{project}' + branch: '{branch}' + stream: '{stream}' + lftools-version: '{lftools-version}' + - lf-cmake-parameters: + build-dir: '{build-dir}' + cmake-opts: '{cmake-opts}' + install-prefix: '{install-prefix}' + make-opts: '{make-opts}' + + wrappers: + - lf-infra-wrappers: + build-timeout: '{build-timeout}' + jenkins-ssh-credential: '{jenkins-ssh-credential}' + + builders: + - shell: '{pre-build}' + - shell: !include-raw-escape: ../shell/cmake-build.sh + + publishers: + - lf-infra-publish + +- job-template: + name: '{project-name}-cmake-verify-{stream}' + id: gerrit-cmake-verify + concurrent: true + <<: *lf_cmake_verify + + scm: + - lf-infra-gerrit-scm: + branch: '$GERRIT_BRANCH' + jenkins-ssh-credential: '{jenkins-ssh-credential}' + git-url: '{git-url}' + refspec: '$GERRIT_REFSPEC' + submodule-recursive: '{submodule-recursive}' + choosing-strategy: gerrit + + triggers: + - gerrit: + server-name: '{gerrit-server-name}' + trigger-on: '{obj:gerrit_verify_triggers}' + projects: + - project-compare-type: 'ANT' + project-pattern: '{project}' + branches: + - branch-compare-type: 'ANT' + branch-pattern: '**/{branch}' + file-paths: '{obj:gerrit_trigger_file_paths}' + +- job-template: + name: '{project-name}-cmake-verify-{stream}' + id: github-cmake-verify + concurrent: true + <<: *lf_cmake_verify + + properties: + - lf-infra-properties: + build-days-to-keep: '{build-days-to-keep}' + - github: + url: '{git-url}/{github-org}/{project}' + + scm: + - lf-infra-github-scm: + url: '{git-clone-url}{github-org}/{project}' + refspec: '+refs/pull/*:refs/remotes/origin/pr/*' + branch: '$sha1' + submodule-recursive: '{submodule-recursive}' + choosing-strategy: default + jenkins-ssh-credential: '{jenkins-ssh-credential}' + + triggers: + - github-pull-request: + trigger-phrase: '^(recheck|reverify)$' + only-trigger-phrase: false + status-context: 'CMake Verify' + permit-all: true + github-hooks: true + included-regions: '{obj:github_included_regions}' diff --git a/jjb/lf-macros.yaml b/jjb/lf-macros.yaml index 12671972..801cf97d 100644 --- a/jjb/lf-macros.yaml +++ b/jjb/lf-macros.yaml @@ -252,6 +252,29 @@ # PARAMETERS # ############## +- parameter: + name: lf-cmake-parameters + # Parameters useful in CMake builds. + parameters: + - string: + name: BUILD_DIR + default: '{build-dir}' + description: 'Directory to build the project in.' + - string: + name: CMAKE_OPTS + default: '{cmake-opts}' + description: | + Options to pass to CMAKE. + Example: -DCMAKE_INSTALL_PREFIX=$WORKSPACE/target/output + - string: + name: INSTALL_PREFIX + default: '{install-prefix}' + description: 'Install prefix for C/C++ builds. Example: /usr/local' + - string: + name: MAKE_OPTS + default: '{make-opts}' + description: 'Options to pass to make. Example: -j8' + - parameter: name: lf-infra-maven-parameters parameters: diff --git a/shell/cmake-build.sh b/shell/cmake-build.sh new file mode 100644 index 00000000..a6a41e4c --- /dev/null +++ b/shell/cmake-build.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# SPDX-License-Identifier: EPL-1.0 +############################################################################## +# Copyright (c) 2018 The Linux Foundation and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +############################################################################## +echo "---> cmake-build.sh" + +build_dir="${BUILD_DIR:-$WORKSPACE/target}" +cmake_opts="${CMAKE_OPTS:-}" +make_opts="${MAKE_OPTS:-}" +# Not a misspelling as shellcheck reports. +# shellcheck disable=SC2153 +project="${PROJECT//\//\-}" + +################ +# Script start # +################ + +set -eux -o pipefail + +mkdir -p "$build_dir" +cd "$build_dir" || exit +# $cmake_opts needs to wordsplit to pass options. +# shellcheck disable=SC2086 +cmake -DCMAKE_INSTALL_PREFIX="$INSTALL_PREFIX" $cmake_opts .. +# $make_opts needs to wordsplit to pass options. +# shellcheck disable=SC2086 +make $make_opts +make install + +mkdir -p "$WORKSPACE/dist" +tar -cJvf "$WORKSPACE/dist/$project.tar.xz" -C "$INSTALL_PREFIX" . + +sudo tar -xvf "$WORKSPACE/dist/$project.tar.xz" -C "/usr/local" +sudo ldconfig