| # 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. |
| |
| # This allows you to cache commands from the command line. |
| # Usage: |
| |
| cachecmd_usage() { |
| cat <<EOF |
| Usage: cachecmd ID command [dep1 [dep2 ...]] |
| where |
| ID is the command ID (unique within the directory) |
| command is the command to run (remember to quote multiword commands) |
| dep1 .. depN are file and environment dependencies |
| EOF |
| } |
| |
| cachecmd() { |
| if [ -z "$2" ]; then |
| cachecmd_usage |
| else |
| local tmpfile=.cachepipe.$$.$(date +%s) |
| rm -f $tmpfile |
| # $@ must be in quotes, or quoted args get split up |
| # see VonC's answer at http://stackoverflow.com/questions/255898/how-to-iterate-over-arguments-in-bash-script |
| for arg in "$@"; do |
| echo $arg >> $tmpfile |
| done |
| |
| perl -MCachePipe -e "cache_from_file('$tmpfile')" |
| rm -f $tmpfile |
| fi |
| } |