forked from material-components/material-components-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_components
executable file
·115 lines (105 loc) · 2.92 KB
/
check_components
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash
#
# Copyright 2016-present the Material Components for iOS 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.
# To check all components:
#
# $ check_components
#
# To check specific components:
#
# $ check_components path/to/component [path/to/component [...]]
function verbose_echo() {
if [[ $verbose -ne 0 ]]; then
echo "$*"
fi
}
verbose=0
checks=""
components=""
while [[ $# -gt 0 ]]; do
case $1 in
"-h" | "--help")
echo "Usage: $0 [-h] [-v] [-c check_script ...] [path/to/component ...]"
echo
echo "Check all components with all checks:"
echo "\$ $0"
echo
echo "Do the same but report what is going on:"
echo "\$ $0 -v"
echo
echo "Check all components with scripts/check/script1 scripts/check/script2:"
echo "\$ $0 -c scripts/check/script1 -c scripts/check/script2"
echo
echo "Check only components/Foo and components/private/Bar:"
echo "\$ $0 components/Foo components/private/Bar"
exit 0
;;
"-v" | "--verbose")
verbose=1
shift 1
;;
"-c" | "--check")
checks="$checks $2"
shift 2
;;
*)
components="$components $1"
shift 1
;;
esac
done
readonly SCRIPTS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly ROOT_DIR=$(dirname "$SCRIPTS_DIR")
verbose_echo "SCRIPTS_DIR: $SCRIPTS_DIR"
verbose_echo "ROOT_DIR: $ROOT_DIR"
# If no component listed on the command line, find them all.
if [[ -z "$components" ]]; then
readonly PUBLIC_COMPONENTS=$($SCRIPTS_DIR/list_components --public)
readonly PRIVATE_COMPONENTS=$($SCRIPTS_DIR/list_components --private)
components="$PUBLIC_COMPONENTS $PRIVATE_COMPONENTS"
fi
verbose_echo "components: $components"
# Find all the check scripts.
if [[ -z "$checks" ]]; then
checks=$(find $SCRIPTS_DIR/check -type f -perm +111)
fi
verbose_echo "checks: $checks"
# Run through each component, running each check in turn.
# Keep track of the number that fail any check.
verbose_echo
failed=""
for component in $components; do
echo "Checking $component ..."
all_checks_passed=1
for check in $checks; do
$check $component
if [[ $? -ne 0 ]]; then
all_checks_passed=0
fi
done
if [[ $all_checks_passed -ne 1 ]]; then
failed="$failed $component"
fi
echo
done
echo
if [[ -z $failed ]]; then
echo Component checks passed.
else
echo "The following components failed:"
for i in $failed; do
echo $i
done
fi