You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by mp...@apache.org on 2016/09/02 06:50:38 UTC

mesos git commit: Added tooling to execute Mesos-specific clang-tidy checks.

Repository: mesos
Updated Branches:
  refs/heads/master f5ce58a16 -> e90752d40


Added tooling to execute Mesos-specific clang-tidy checks.

This commit adds tooling to both build and execute Mesos-specific
clang-tidy checks. We use a docker container for the execution, and
also provide a script to further streamline the tooling.

Review: https://reviews.apache.org/r/51525/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/e90752d4
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/e90752d4
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/e90752d4

Branch: refs/heads/master
Commit: e90752d408713a1746eeee30d8b80dff194707a4
Parents: f5ce58a
Author: Benjamin Bannier <be...@mesosphere.io>
Authored: Thu Sep 1 20:43:11 2016 +0200
Committer: Michael Park <mp...@apache.org>
Committed: Fri Sep 2 08:49:34 2016 +0200

----------------------------------------------------------------------
 support/mesos-tidy.sh            | 42 +++++++++++++++++
 support/mesos-tidy/Dockerfile    | 86 +++++++++++++++++++++++++++++++++++
 support/mesos-tidy/README.md     | 49 ++++++++++++++++++++
 support/mesos-tidy/entrypoint.sh | 50 ++++++++++++++++++++
 4 files changed, 227 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/e90752d4/support/mesos-tidy.sh
----------------------------------------------------------------------
diff --git a/support/mesos-tidy.sh b/support/mesos-tidy.sh
new file mode 100755
index 0000000..16d4363
--- /dev/null
+++ b/support/mesos-tidy.sh
@@ -0,0 +1,42 @@
+#!/bin/bash
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+
+#     http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Configure how checks are run. These variables can be overriden by setting the
+# respective environment variables before invoking this script.
+# TODO(bbannier): Enable more upstream checks by default, e.g., from the Google set.
+CHECKS=${CHECKS:-'-*,mesos-*'}
+
+# By default perform an optimized build since it appears to finish
+# slightly faster. Note that this has no effect on the static analysis.
+CONFIGURE_FLAGS=${CONFIGURE_FLAGS:-'--enable-optimize'}
+
+MESOS_DIRECTORY=$(cd "$(dirname "$0")/.." && pwd)
+
+# Check for unstaged or uncommitted changes.
+if ! $(git diff-index --quiet HEAD --); then
+  echo "Please commit or stash any changes before running `mesos-tidy`."
+  exit 1
+fi
+
+# Execute the container.
+docker run \
+  --rm \
+  -v "${MESOS_DIRECTORY}":/SRC \
+  -e CHECKS="${CHECKS}" \
+  -e CONFIGURE_FLAGS="${CONFIGURE_FLAGS}" \
+  mesosphere/mesos-tidy || exit 1

http://git-wip-us.apache.org/repos/asf/mesos/blob/e90752d4/support/mesos-tidy/Dockerfile
----------------------------------------------------------------------
diff --git a/support/mesos-tidy/Dockerfile b/support/mesos-tidy/Dockerfile
new file mode 100644
index 0000000..8ef1834
--- /dev/null
+++ b/support/mesos-tidy/Dockerfile
@@ -0,0 +1,86 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+
+#     http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+FROM ubuntu:trusty
+MAINTAINER The Apache Mesos Developers <de...@mesos.apache.org>
+
+WORKDIR /tmp/build
+
+# Build Mesos-flavored `clang-tidy`.
+RUN apt-get update
+RUN apt-get install -qy --no-install-recommends \
+  build-essential \
+  ca-certificates \
+  cmake \
+  git \
+  python-dev && \
+  apt-get clean
+
+RUN \
+  git clone --depth 1 -b release_38 http://llvm.org/git/llvm /tmp/llvm && \
+  git clone --depth 1 -b release_38 http://llvm.org/git/clang /tmp/llvm/tools/clang && \
+  git clone --depth 1 -b mesos_38 http://github.com/mesos/clang-tools-extra.git /tmp/llvm/tools/clang/tools/extra && \
+  \
+  cmake /tmp/llvm -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/opt/ && \
+  make -j $(nproc) install && \
+  \
+  cd / && \
+  rm -rf /tmp/llvm && \
+  rm -rf /tmp/build
+
+# Install Bear.
+RUN apt-get install -qy \
+  curl && \
+  apt-get clean
+
+RUN \
+  curl -k -O https://codeload.github.com/rizsotto/Bear/tar.gz/2.2.0 && \
+  tar xzf 2.2.0 && \
+  rm 2.2.0 && \
+  cd Bear-2.2.0/ && \
+  cmake . -DCMAKE_INSTALL_PREFIX=/opt && \
+  make -j $(nproc) install && \
+  \
+  cd / && \
+  rm -rf Bear-2.2.0
+
+ENV PATH /opt/bin:$PATH
+
+# Install Mesos dependencies
+RUN apt-get install -qy \
+  autoconf \
+  jq \
+  libapr1-dev \
+  libcurl4-nss-dev \
+  libev-dev \
+  libevent-dev \
+  libsasl2-dev \
+  libsasl2-modules \
+  libsvn-dev \
+  libtool \
+  maven \
+  openjdk-7-jdk \
+  zlib1g-dev && \
+  apt-get clean
+
+# Install parallel for clang-tidy invocation.
+RUN apt-get install -qy \
+  parallel
+
+# Wire up the script which performs the actual work.
+WORKDIR /BUILD
+ADD ["entrypoint.sh", "entrypoint.sh"]
+CMD exec ./entrypoint.sh

http://git-wip-us.apache.org/repos/asf/mesos/blob/e90752d4/support/mesos-tidy/README.md
----------------------------------------------------------------------
diff --git a/support/mesos-tidy/README.md b/support/mesos-tidy/README.md
new file mode 100644
index 0000000..e285632
--- /dev/null
+++ b/support/mesos-tidy/README.md
@@ -0,0 +1,49 @@
+clang-tidy docker image for Mesos
+=================================
+
+This directory contains tooling to build a docker image to run
+clang-tidy checks over a Mesos repository. It uses a [version of
+clang-tidy](https://github.com/mesos/clang-tools-extra/tree/mesos_38)
+augmented with Mesos-specific checks.
+
+*IMPORTANT*: This directory is for maintainers of `mesos-tidy` checks.
+Users should reach for `support/mesos-tidy.sh`.
+
+
+Building the docker image
+-------------------------
+
+Building the image involves compiling a Mesos-flavored version of
+`clang-tidy`, installing Mesos dependencies, and installation of tools
+to drive check invocations.
+
+The image can be built with
+
+    $ docker build -t mesos-tidy .
+
+A pre-built image is available via Docker Hub as `mesosphere/mesos-tidy`.
+
+
+Running checks
+--------------
+
+To run checks over a Mesos checkout invoke
+
+    $ docker run \
+        -v <MESOS_CHECKOUT>:/SRC \
+        [-e CHECKS=<CHECKS>] \
+        [-e CONFIGURE_FLAGS=<CONFIGURE_FLAGS>] \
+        --rm \
+        mesos-tidy
+
+Here `MESOS_CHECKOUT` points to a git checkout of the Mesos source
+tree.
+
+Additional configure parameters can be passed to the `./configure`
+invocation of Mesos via `CONFIGURE_FLAGS`. By default, `./configure`
+will be invoked without arguments.
+
+Optionally, the set of checks to perform can be specified in a
+clang-tidy check regex via `CHECKS`.
+
+Results from 3rdparty external dependencies are filtered from the result set.

http://git-wip-us.apache.org/repos/asf/mesos/blob/e90752d4/support/mesos-tidy/entrypoint.sh
----------------------------------------------------------------------
diff --git a/support/mesos-tidy/entrypoint.sh b/support/mesos-tidy/entrypoint.sh
new file mode 100755
index 0000000..78198d9
--- /dev/null
+++ b/support/mesos-tidy/entrypoint.sh
@@ -0,0 +1,50 @@
+#!/bin/bash
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+
+#     http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+SRCDIR=/tmp/SRC
+
+# Prepare sources
+git clone --depth 1 file:///SRC ${SRCDIR} || exit 1
+(cd ${SRCDIR} && ./bootstrap) || exit 1
+
+# Configure sources
+${SRCDIR}/configure "${CONFIGURE_FLAGS}" || exit 1
+
+# Build sources
+bear make -j $(nproc) tests || exit 1
+
+# TODO(bbannier): Use a less restrictive `grep` pattern and `header-filter`
+# once MESOS-6115 is fixed.
+cat compile_commands.json \
+  | jq '.[].file' \
+  | sed 's/"//g' \
+  | sed 's/^\ //g' \
+  | grep "^${SRCDIR}/.*\.cpp$" \
+  | parallel -j $(nproc) clang-tidy -p "${PWD}" \
+      -extra-arg=-Wno-unknown-warning-option \
+      -extra-arg=-Wno-unused-command-line-argument \
+      -header-filter="^${SRCDIR}/.*\.hpp$" -checks="${CHECKS}" \
+  1> clang-tidy.log 2> /dev/null
+
+# Propagate any errors.
+if test -s clang-tidy.log; then
+  cat clang-tidy.log
+  exit 1
+else
+  echo "No mesos-tidy violations found."
+fi