From 0334615e51feeeb40f9f9b7f5c391deef3445341 Mon Sep 17 00:00:00 2001 From: Mike Aizatsky Date: Wed, 19 Oct 2016 15:07:24 -0700 Subject: [PATCH] [infra] determining source code revisions --- infra/base-images/base-libfuzzer/Dockerfile | 4 +- infra/base-images/base-libfuzzer/compile | 1 + infra/base-images/base-libfuzzer/revisions | 45 +++++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100755 infra/base-images/base-libfuzzer/revisions diff --git a/infra/base-images/base-libfuzzer/Dockerfile b/infra/base-images/base-libfuzzer/Dockerfile index 18c3e2e3d..7b63e2d7e 100644 --- a/infra/base-images/base-libfuzzer/Dockerfile +++ b/infra/base-images/base-libfuzzer/Dockerfile @@ -16,7 +16,7 @@ FROM ossfuzz/base-clang MAINTAINER mike.aizatsky@gmail.com -RUN apt-get install -y libc6-dev libtool git subversion +RUN apt-get install -y libc6-dev libtool git subversion jq RUN mkdir -p /work/libfuzzer @@ -30,7 +30,7 @@ RUN mkdir /out VOLUME /out RUN mkdir /src/bin -COPY compile run /src/bin/ +COPY compile revisions run /src/bin/ ENV PATH=/src/bin:$PATH WORKDIR /src CMD ["compile"] diff --git a/infra/base-images/base-libfuzzer/compile b/infra/base-images/base-libfuzzer/compile index 6ace259ba..d05594550 100755 --- a/infra/base-images/base-libfuzzer/compile +++ b/infra/base-images/base-libfuzzer/compile @@ -15,6 +15,7 @@ # ################################################################################ +revisions echo "---------------------------------------------------------------" diff --git a/infra/base-images/base-libfuzzer/revisions b/infra/base-images/base-libfuzzer/revisions new file mode 100755 index 000000000..db693aa75 --- /dev/null +++ b/infra/base-images/base-libfuzzer/revisions @@ -0,0 +1,45 @@ +#!/bin/bash -eux +# Copyright 2016 Google Inc. +# +# Licensed 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. +# +################################################################################ + +# Deterimine revisions of checked out source code + +echo "{}" > /out/revisions.json + +cat /out/revisions.json + +# $1 - json file, $2 - jq program +function jq_inplace() { + F=$(tempfile) && cat $1 | jq "$2" > $F && mv $F $1 +} + +for DOT_GIT_DIR in $(find /src -name ".git" -type d); do + GIT_DIR=$(dirname $DOT_GIT_DIR) + cd $GIT_DIR + GIT_URL=$(git config --get remote.origin.url) + GIT_REV=$(git rev-parse HEAD) + jq_inplace /out/revisions.json ".\"$GIT_DIR\" = { type: \"git\", url: \"$GIT_URL\", rev: \"$GIT_REV\" }" +done + +for DOT_SVN_DIR in $(find /src -name ".svn" -type d); do + SVN_DIR=$(dirname $DOT_SVN_DIR) + cd $SVN_DIR + SVN_URL=$(svn info | grep "^URL:" | sed 's/URL: //g') + SVN_REV=$(svn info -r HEAD | grep "^Revision:" | sed 's/Revision: //g') + jq_inplace /out/revisions.json ".\"$SVN_DIR\" = { type: \"svn\", url: \"$SVN_URL\", rev: \"$SVN_REV\" }" +done + +cat /out/revisions.json