blob: f29a64150e58d39dd58588950c22821029feb052 [file] [log] [blame]
#!/bin/bash
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
#
# 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.
# ==============================================================================
# Compute the MD5 sum.
#
# Parameter(s):
# ${1} - path to the file
function compute_md5() {
UNAME_S=`uname -s`
if [ ${UNAME_S} == Linux ]; then
tflm_md5sum=md5sum
elif [ ${UNAME_S} == Darwin ]; then
tflm_md5sum='md5 -r'
else
tflm_md5sum=md5sum
fi
${tflm_md5sum} ${1} | awk '{print $1}'
}
# Check that MD5 sum matches expected value.
#
# Parameter(s):
# ${1} - path to the file
# ${2} - expected md5
function check_md5() {
MD5=`compute_md5 ${1}`
if [[ ${MD5} != ${2} ]]
then
echo "Bad checksum. Expected: ${2}, Got: ${MD5}"
exit 1
fi
}
# Create a git repo in a folder.
#
# Parameter(s):
# $[1} - relative path to folder
create_git_repo() {
pushd ${1} > /dev/null
git init . > /dev/null
git config user.email "tflm@google.com" --local
git config user.name "TFLM" --local
git add . >&2 2> /dev/null
git commit -a -m "Commit for a temporary repository." > /dev/null
git checkout -b tflm > /dev/null
popd > /dev/null
}
# Create a new commit with a patch in a folder that has a git repo.
#
# Parameter(s):
# $[1} - relative path to folder
# ${2} - path to patch file (relative to ${1})
# ${3} - commit nessage for the patch
function apply_patch_to_folder() {
pushd ${1} > /dev/null
echo >&2 "Applying ${PWD}/${1}/${2} to ${PWD}/${1}"
git apply ${2}
git commit -a -m "${3}" > /dev/null
popd > /dev/null
}