#!/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. # Prepare clang-tidy docker image. global TAG := "mesos-tidy-$[date +%s]-$RANDOM" # TODO(vinod): Instead of building Docker images on the fly host the # images on DockerHub and use them. docker build --no-cache=true -t $TAG mesos-tidy/ # 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. global 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. global CONFIGURE_FLAGS := $(CONFIGURE_FLAGS:-'--enable-optimize') global MESOS_DIRECTORY := $[cd "$[dirname $0]/.." && pwd] # Check for unstaged or uncommitted changes. if ! $[git diff-index --quiet HEAD --] { echo 'Please commit or stash any changes before running `mesos-tidy`.' exit 1 } # Execute the container. docker run \ --rm \ -v "$(MESOS_DIRECTORY)":/SRC \ -e CHECKS="$(CHECKS)" \ -e CONFIGURE_FLAGS="$(CONFIGURE_FLAGS)" \ $TAG || exit 1 # Set a trap to delete the image on exit. trap "docker rmi $TAG" EXIT (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:TAG) op: Equal rhs: {(mesos-tidy-) (CommandSubPart command_list: (CommandList children: [(C {(date)} {(Lit_Other "+") (Lit_Other "%") (s)})] ) left_token: spids: [52 58] ) (-) ($ VSub_Name "$RANDOM") } spids: [50] ) ] spids: [50] ) (C {(docker)} {(build)} {(--no-cache) (Lit_Other "=") (true)} {(-t)} {($ VSub_Name "$TAG")} {(mesos-tidy/)} ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:CHECKS) op: Equal rhs: { (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(SQ <"-*,mesos-*">)}) spids: [93 99] ) } spids: [92] ) ] spids: [92] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:CONFIGURE_FLAGS) op: Equal rhs: { (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(SQ <--enable-optimize>)}) spids: [109 115] ) } spids: [108] ) ] spids: [108] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:MESOS_DIRECTORY) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (AndOr children: [ (C {(cd)} { (DQ (CommandSubPart command_list: (CommandList children: [(C {(dirname)} {(DQ ($ VSub_Number "$0"))})] ) left_token: spids: [123 129] ) (/..) ) } ) (C {(pwd)}) ] op_id: Op_DAmp ) ] ) left_token: spids: [119 136] ) } spids: [118] ) ] spids: [118] ) (If arms: [ (if_arm cond: [ (Sentence child: (Pipeline children: [ (C { (CommandSubPart command_list: (CommandList children: [(C {(git)} {(diff-index)} {(--quiet)} {(HEAD)} {(--)})] ) left_token: spids: [146 156] ) } ) ] negated: True ) terminator: ) ] action: [ (C {(echo)} {(SQ <"Please commit or stash any changes before running `mesos-tidy`.">)}) (C {(exit)} {(1)}) ] spids: [-1 159] ) ] spids: [-1 173] ) (AndOr children: [ (C {(docker)} {(run)} {(--rm)} {(-v)} {(DQ (${ VSub_Name MESOS_DIRECTORY)) (Lit_Other ":") (/SRC)} {(-e)} {(Lit_VarLike "CHECKS=") (DQ (${ VSub_Name CHECKS))} {(-e)} {(Lit_VarLike "CONFIGURE_FLAGS=") (DQ (${ VSub_Name CONFIGURE_FLAGS))} {($ VSub_Name "$TAG")} ) (C {(exit)} {(1)}) ] op_id: Op_DPipe ) (C {(trap)} {(DQ ("docker rmi ") ($ VSub_Name "$TAG"))} {(EXIT)}) ] )