forked from sounddrill31/actions_generate_local_manifests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.sh
203 lines (172 loc) · 5.41 KB
/
generate.sh
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#
# Copyright (C) 2024 Souhrud Reddy
#
# SPDX-License-Identifier: Apache-2.0
#
#!/bin/bash
# Check if a filename is provided as an argument
if [ -z "$1" ]; then
echo "Please provide a filename as an argument."
exit 1
fi
# Check if the input file exists
if [ ! -f "$1" ]; then
echo "File not found: $1"
exit 1
fi
if [ ! -f *.output ]; then
echo "Output not found! Run adapt.sh first"
exit 1
fi
# Define the input file
INFILE="$1"
FILENAME=$(basename "$1")
echo "Processing input file: $INFILE"
# Start the XML file with the header
cat << EOF > local_manifests.xml
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
<!-- Generated using sounddrill31/actions_generate_local_manifests -->
EOF
# Initialize associative arrays to store remotes, projects, and remove-projects
declare -A REMOTES
declare -A PROJECTS
declare -A REMOVE_PROJECTS
# Initialize counters
ADD_COUNT=0
REMOVE_COUNT=0
# Read the input file line by line
while IFS= read -r LINE || [ -n "$LINE" ]; do
# Remove carriage return and leading/trailing whitespace
LINE=$(echo "$LINE" | tr -d '\r' | xargs)
echo "Processing line: $LINE"
# Check if the line starts with curly braces
if [[ $LINE =~ ^\{.*\}$ ]]; then
# Extract TESTING_URL and TESTING_BRANCH
read -r TESTING_URL TESTING_BRANCH <<< $(echo "$LINE" | tr -d '{}' | tr '"' ' ')
echo "$TESTING_URL" > url
echo "$TESTING_BRANCH" > branch
echo "true" > test_status
echo "Set TESTING_URL=$TESTING_URL and TESTING_BRANCH=$TESTING_BRANCH"
continue
fi
# Call add.sh for 'add' lines
if [[ $LINE == add* ]]; then
echo "Calling add.sh with: $LINE"
if source ./add.sh "$LINE"; then
((ADD_COUNT++))
else
echo "Error in add.sh"
fi
fi
# Call remove.sh for 'remove' lines
if [[ $LINE == remove* ]]; then
echo "Calling remove.sh with: $LINE $TESTING_URL $TESTING_BRANCH"
if source ./remove.sh "$LINE" "$TESTING_URL" "$TESTING_BRANCH"; then
((REMOVE_COUNT++))
else
echo "Error in remove.sh"
fi
fi
done < "$INFILE"
# Clean up
rm -rf manifest
echo "" >> local_manifests.xml
# Output remotes
echo " <!-- Remotes -->" >> local_manifests.xml
for remote in "${REMOTES[@]}"; do
echo "$remote" >> local_manifests.xml
done
echo "" >> local_manifests.xml
# Output remove-project entries
echo " <!-- Removals -->" >> local_manifests.xml
for remove_project in "${REMOVE_PROJECTS[@]}"; do
echo "$remove_project" >> local_manifests.xml
done
echo "" >> local_manifests.xml
# Output projects
echo " <!-- Repos -->" >> local_manifests.xml
echo " <!-- Device -->" >> local_manifests.xml
for project in "${PROJECTS[@]}"; do
if [[ $project == *"device/"* && $project != *"common"* ]]; then
echo "$project" >> local_manifests.xml
fi
done
echo "" >> local_manifests.xml
echo " <!-- Device - Common -->" >> local_manifests.xml
for project in "${PROJECTS[@]}"; do
if [[ $project == *"device/"* && $project == *"common"* ]]; then
echo "$project" >> local_manifests.xml
fi
done
echo "" >> local_manifests.xml
echo " <!-- Kernel -->" >> local_manifests.xml
for project in "${PROJECTS[@]}"; do
if [[ $project == *"kernel/"* ]]; then
echo "$project" >> local_manifests.xml
fi
done
echo "" >> local_manifests.xml
echo " <!-- Vendor -->" >> local_manifests.xml
for project in "${PROJECTS[@]}"; do
if [[ $project == *"vendor/"* && $project != *"common"* ]]; then
echo "$project" >> local_manifests.xml
fi
done
echo "" >> local_manifests.xml
echo " <!-- Vendor - Common -->" >> local_manifests.xml
for project in "${PROJECTS[@]}"; do
if [[ $project == *"vendor/"* && $project == *"common"* ]]; then
echo "$project" >> local_manifests.xml
fi
done
echo "" >> local_manifests.xml
# Check if there are any hardware projects
HARDWARE_PROJECTS=()
for project in "${PROJECTS[@]}"; do
if [[ $project == *"hardware/"* ]]; then
HARDWARE_PROJECTS+=("$project")
fi
done
if [[ ${#HARDWARE_PROJECTS[@]} -gt 0 ]]; then
echo " <!-- Hardware -->" >> local_manifests.xml
for project in "${HARDWARE_PROJECTS[@]}"; do
echo "$project" >> local_manifests.xml
done
echo "" >> local_manifests.xml
fi
# Check if there are any other projects
OTHER_PROJECTS=()
for project in "${PROJECTS[@]}"; do
if [[ $project != *"device/"* && $project != *"kernel/"* && $project != *"vendor/"* && $project != *"hardware/"* ]]; then
OTHER_PROJECTS+=("$project")
fi
done
if [[ ${#OTHER_PROJECTS[@]} -gt 0 ]]; then
echo " <!-- Other Repos -->" >> local_manifests.xml
for project in "${OTHER_PROJECTS[@]}"; do
echo "$project" >> local_manifests.xml
done
echo "" >> local_manifests.xml
fi
# Close the XML file
echo '</manifest>' >> local_manifests.xml
echo "Local manifests generated in local_manifests.xml"
echo "Add operations processed: $ADD_COUNT"
echo "Remove operations processed: $REMOVE_COUNT"
# Print the contents of the arrays
echo "REMOTES:"
for key in "${!REMOTES[@]}"; do
echo " $key: ${REMOTES[$key]}"
done
echo "PROJECTS:"
for key in "${!PROJECTS[@]}"; do
echo " $key: ${PROJECTS[$key]}"
done
echo "REMOVE_PROJECTS:"
for key in "${!REMOVE_PROJECTS[@]}"; do
echo " $key: ${REMOVE_PROJECTS[$key]}"
done
# Print the exported variables
echo "TESTING_URL: $TESTING_URL"
echo "TESTING_BRANCH: $TESTING_BRANCH"