1 #!/bin/sh 2 # 3 # Copyright 2015 Google Inc. All rights reserved 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http:#www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 set -e 18 19 log=/tmp/log 20 mk="$@" 21 22 sleep_if_necessary() { 23 if [ x$(uname) != x"Linux" -o x"${TRAVIS}" != x"" ]; then 24 sleep "$@" 25 fi 26 } 27 28 export VAR=hoge 29 30 cat <<EOF > Makefile 31 all: 32 echo foo 33 EOF 34 35 ${mk} 2> ${log} 36 if [ -e ninja.sh ]; then 37 ./ninja.sh 38 fi 39 40 sleep_if_necessary 1 41 cat <<EOF > Makefile 42 all: 43 echo bar 44 echo VAR=\$(VAR) 45 echo VAR2=\$(VAR2) 46 echo wildcard=\$(wildcard *.mk) 47 other: 48 echo foo 49 EOF 50 51 ${mk} 2> ${log} 52 if [ -e ninja.sh ]; then 53 if ! grep regenerating ${log} > /dev/null; then 54 echo 'Should be regenerated (Makefile)' 55 fi 56 ./ninja.sh 57 fi 58 59 export VAR=fuga 60 ${mk} 2> ${log} 61 if [ -e ninja.sh ]; then 62 if ! grep regenerating ${log} > /dev/null; then 63 echo 'Should be regenerated (env changed)' 64 fi 65 ./ninja.sh 66 fi 67 68 export VAR2=OK 69 ${mk} 2> ${log} 70 if [ -e ninja.sh ]; then 71 if ! grep regenerating ${log} > /dev/null; then 72 echo 'Should be regenerated (env added)' 73 fi 74 ./ninja.sh 75 fi 76 77 export PATH=/random_path:$PATH 78 ${mk} 2> ${log} 79 if [ -e ninja.sh ]; then 80 if ! grep regenerating ${log} > /dev/null; then 81 echo 'Should be regenerated (PATH changed)' 82 fi 83 ./ninja.sh 84 fi 85 86 sleep_if_necessary 1 87 touch PASS.mk 88 ${mk} 2> ${log} 89 if [ -e ninja.sh ]; then 90 if ! grep regenerating ${log} > /dev/null; then 91 echo 'Should be regenerated (wildcard)' 92 fi 93 ./ninja.sh 94 fi 95 96 sleep_if_necessary 1 97 touch XXX 98 ${mk} 2> ${log} 99 if [ -e ninja.sh ]; then 100 if grep regenerating ${log}; then 101 echo 'Should not be regenerated' 102 fi 103 ./ninja.sh 104 fi 105 106 ${mk} other 2> ${log} 107 if [ -e ninja.sh ]; then 108 if ! grep regenerating ${log} >/dev/null; then 109 echo 'Should be regenerated (argument)' 110 fi 111 ./ninja.sh other 112 fi 113