blob: 3a2a000431ec8524be464605ebb1d080ae1d118d [file] [log] [blame]
Igor Murashkineaddcd42012-11-26 12:01:11 -08001#!/bin/bash
2
3#
4# Copyright (C) 2012 The Android Open Source Project
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18
19#
20# Generate all files we have templates for:
21# docs.html
22# ../src/camera_metadata_tag_info.c
23# ../src/camera_metadata_tags.h
Colin Crossabc7c492017-05-05 09:36:03 -070024# ../../../../frameworks/av/camera/ndk/include/camera/NdkCameraMetadataTags.h
Yin-Chia Yehea7662f2015-12-22 16:25:00 -080025# ../../../../frameworks/av/camera/ndk/impl/ACameraMetadata.cpp
Yin-Chia Yeh6c58d0a2015-12-05 17:20:33 -080026# ../../../../cts/tests/camera/src/android/hardware/camera2/cts/CaptureResultTest.java
Igor Murashkin21d0f1a2013-09-10 12:25:56 -070027# ../../../../frameworks/base/core/java/android/hardware/camera2/CameraCharacteristics.java
28# ../../../../frameworks/base/core/java/android/hardware/camera2/CaptureRequest.java
29# ../../../../frameworks/base/core/java/android/hardware/camera2/CaptureResult.java
Igor Murashkineaddcd42012-11-26 12:01:11 -080030
Igor Murashkinaa133d32013-06-28 17:27:49 -070031if [[ -z $ANDROID_BUILD_TOP ]]; then
32 echo "Please source build/envsetup.sh before running script" >& 2
33 exit 1
34fi
35
Eino-Ville Talvala08885562013-03-18 09:43:57 -070036thisdir=$(cd "$(dirname "$0")"; pwd)
Eino-Ville Talvala47aa24d2013-07-25 17:10:11 -070037fwkdir="$ANDROID_BUILD_TOP/frameworks/base/core/java/android/hardware/camera2/"
Eino-Ville Talvala0d404952017-11-10 15:13:04 -080038fwkdir_html="$ANDROID_BUILD_TOP/frameworks/base/docs/html/reference"
Yin-Chia Yeh4d24e412018-03-15 11:08:49 -070039ndkdir_html="$ANDROID_BUILD_TOP/frameworks/native/docs"
Austin Borger476684b2022-03-18 11:08:37 -070040aidldir="$ANDROID_BUILD_TOP/hardware/interfaces/camera/metadata/aidl/android/hardware/camera/metadata"
Yin-Chia Yeh6c58d0a2015-12-05 17:20:33 -080041ctsdir="$ANDROID_BUILD_TOP/cts/tests/camera/src/android/hardware/camera2/cts"
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -070042outdir="$ANDROID_PRODUCT_OUT/obj/ETC/system-media-camera-docs_intermediates"
Colin Crossabc7c492017-05-05 09:36:03 -070043ndk_header_dir="$ANDROID_BUILD_TOP/frameworks/av/camera/ndk/include/camera"
Yin-Chia Yehea7662f2015-12-22 16:25:00 -080044ndk_impl_dir="$ANDROID_BUILD_TOP/frameworks/av/camera/ndk/impl"
Jayant Chowdharyeca91ca2022-05-05 19:21:25 +000045libcameraservice_hidl_dir="$ANDROID_BUILD_TOP/frameworks/av/services/camera/libcameraservice/hidl"
Yin-Chia Yehcf145ce2016-04-01 17:37:47 -070046device_info_dir="$ANDROID_BUILD_TOP/cts/tools/cts-device-info/"`
47 `"src/com/android/cts/deviceinfo"
Igor Murashkin1232dd22013-06-21 12:10:42 -070048out_files=()
Igor Murashkineaddcd42012-11-26 12:01:11 -080049
Igor Murashkin5804a482012-12-05 13:06:59 -080050function relpath() {
Eino-Ville Talvalaa5213a22020-05-10 16:57:36 -070051 python3 -c "import os.path; print(os.path.relpath('$1', '$PWD'))"
Igor Murashkin5804a482012-12-05 13:06:59 -080052}
53
Igor Murashkin1232dd22013-06-21 12:10:42 -070054# Generates a file. Appends to $out_files array as a side effect.
Igor Murashkineaddcd42012-11-26 12:01:11 -080055function gen_file() {
56 local in=$thisdir/$1
57 local out=$thisdir/$2
58
Igor Murashkinaa133d32013-06-28 17:27:49 -070059 gen_file_abs "$in" "$out"
60 return $?
61}
62
63function gen_file_abs() {
64 local in="$1"
65 local out="$2"
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -070066 local intermediates="$3"
Austin Borger476684b2022-03-18 11:08:37 -070067 local copyright_year="${4:-2022}"
Eino-Ville Talvala0d404952017-11-10 15:13:04 -080068 local spec_file=$thisdir/metadata_definitions.xml
Yin-Chia Yehc9c2c682016-05-25 01:29:55 -070069
Austin Borger476684b2022-03-18 11:08:37 -070070 python3 $thisdir/metadata_parser_xml.py $spec_file $in $out $copyright_year
Igor Murashkin5804a482012-12-05 13:06:59 -080071
72 local succ=$?
73
74 if [[ $succ -eq 0 ]]
75 then
76 echo "OK: Generated $(relpath "$out")"
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -070077 if [[ "$intermediates" != "no" ]]; then
78 out_files+=$'\n'" $out"
79 fi
Igor Murashkin5804a482012-12-05 13:06:59 -080080 else
81 echo "FAIL: Errors while generating $(relpath "$out")" >& 2
82 fi
83
84 return $succ
Igor Murashkineaddcd42012-11-26 12:01:11 -080085}
86
Austin Borger476684b2022-03-18 11:08:37 -070087function gen_enum_files() {
88 local in="$1"
89 local out_dir="$2"
90 local intermediates="$3"
91 local copyright_year="${4:-2022}"
92 local spec_file=$thisdir/metadata_definitions.xml
93
94 python3 $thisdir/metadata_enums.py $spec_file $in $out_dir $copyright_year
95
96 local succ=$?
97
98 if [[ $succ -eq 0 ]]
99 then
100 echo "OK: Generated enum files in $(relpath "$out_dir")" >& 2
101 if [[ "$intermediates" != "no" ]]; then
102 out_files+=$'\n'" $out_dir/*.aidl"
103 fi
104 else
105 echo "FAIL: Errors while generating enum aidl files in $(relpath "$out_dir")" >& 2
106 fi
107
108 return $succ
109}
110
Igor Murashkin1232dd22013-06-21 12:10:42 -0700111# Print a list of git repository paths which were affected after file generation
112function affected_git_directories() {
113 local input_files=($@)
114 local git_directories=()
115
116 for file in "${input_files[@]}"; do
117 local dir_path="$(dirname "$file")"
118 echo "Trying to cd into $dir_path" >& /dev/null
119 # Absolute path to the git repository root of that file
120 local git_path="$(cd "$dir_path";
121 git rev-parse --show-toplevel 2> /dev/null)"
122 if [[ $? -eq 0 ]]; then
123 # Both staged and unstaged changes
Igor Murashkinb8dc8812013-07-17 16:29:34 -0700124 local diff_result="$(cd "$dir_path";
125 git status --porcelain | egrep -c -v '^[?][?]')"
Igor Murashkin1232dd22013-06-21 12:10:42 -0700126 echo "Diff result was $diff_result" >& /dev/null
127 echo "Diff result was $diff_result" >& /dev/null
128 if [[ $diff_result -eq 0 ]]; then
Igor Murashkinaa133d32013-06-28 17:27:49 -0700129 echo "No changes in ${git_path}" >& /dev/null
Igor Murashkin1232dd22013-06-21 12:10:42 -0700130 else
131 echo "There are changes in ${git_path}" >& /dev/null
132 git_directories+=("$git_path")
133 fi
134 fi
135 done
136
137 # print as result the unique list of git directories affected
Igor Murashkinaa133d32013-06-28 17:27:49 -0700138 printf %s\\n "${git_directories[@]}" | sort | uniq
Igor Murashkin1232dd22013-06-21 12:10:42 -0700139}
140
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700141# Insert a file into the middle of another, starting at the line containing the
142# start delim and ending on the end delim, both of which are replaced
143function insert_file() {
144 local src_part="$1"
145 local dst_file="$2"
146 local start_delim="/*@O~"
147 local end_delim="~O@*/"
148
149 local start_line="$(grep -n -F "${start_delim}" "${dst_file}" | cut -d: -f1)"
150 local end_line="$(grep -n -F "${end_delim}" "${dst_file}" | cut -d: -f1)"
151
152 # Adjust cutoff points to use start/end line from inserted file
153 (( start_line-- ))
154 (( end_line++ ))
155
Eino-Ville Talvala54960fa2020-06-19 13:50:40 -0700156 # Do some basic validity checks
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700157
158 if [[ -z "$start_line" ]]; then
159 echo "No starting delimiter found in ${dst_file}" >& 2
160 echo "FAIL: Errors in inserting into $(relpath ${dst_file})" >& 2
161 return 1
162 fi
163
164 if [[ -z "$end_line" ]]; then
165 echo "No ending delimiter found in ${dst_file}" >& 2
166 echo "FAIL: Errors in inserting into $(relpath ${dst_file})" >& 2
167 return 1
168 fi
169
170 if [[ "$start_line" -ge "$end_line" ]]; then
171 echo "Starting delim later than ending delim: $start_line vs $end_line" >& 2
172 echo "FAIL: Errors in inserting into $(relpath ${dst_file})" >& 2
173 return 1
174 fi
175
176 local tmp_name=$(mktemp -t XXXXXXXX)
177
178 # Compose the three parts of the final file together
179
180 head -n "$start_line" "${dst_file}" > "${tmp_name}"
181 cat "${src_part}" >> "${tmp_name}"
182 tail -n "+${end_line}" "${dst_file}" >> "${tmp_name}"
183
184 # And replace the destination file with the new version
185
186 mv "${tmp_name}" "${dst_file}"
187 echo "OK: Inserted $(relpath "$src_part") into $(relpath "$dst_file")"
188 out_files+=$'\n'" $dst_file"
189}
190
Igor Murashkin1dd4ecb2013-12-11 13:31:00 -0800191# Recursively copy a directory tree from $1 to $2. Pretty-prints status.
192function copy_directory() {
193 local src="$thisdir/$1" # Relative to directory of this script
194 local dst="$2" # Absolute path
195
196 if ! [[ -d $src ]]; then
197 echo "FAIL: Source directory $src does not exist" >& 2
198 return 1
199 fi
200 if ! [[ -d $dst ]]; then
201 echo "FAIL: Destination directory $dst does not exist" >& 2
202 return 1
203 fi
204
205 cp -R "$src" "$dst"
206 local retval=$?
207
208 if [[ $retval -ne 0 ]]; then
209 echo "ERROR: Failed to copy $(relpath "$src") to $(relpath "$dst")" >& 2
210 else
211 echo "OK: Copied $(relpath "$src") to $(relpath "$dst")"
Yin-Chia Yeh4d24e412018-03-15 11:08:49 -0700212 out_files+=$'\n'" $dst"
Igor Murashkin1dd4ecb2013-12-11 13:31:00 -0800213 fi
214
215 return $retval
216}
217
Igor Murashkin0334aa02012-12-04 14:59:53 -0800218$thisdir/metadata-check-dependencies || exit 1
Eino-Ville Talvala0d404952017-11-10 15:13:04 -0800219$thisdir/metadata-validate $thisdir/metadata_definitions.xml || exit 1
Eino-Ville Talvala54960fa2020-06-19 13:50:40 -0700220$thisdir/metadata-parser-validity-check || exit 1
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700221
Austin Borger476684b2022-03-18 11:08:37 -0700222# Generate AIDL metadata modules
223mkdir -p "${aidldir}"
224gen_file_abs aidl/CameraMetadataSection.mako "$aidldir/CameraMetadataSection.aidl" yes || exit 1
225gen_file_abs aidl/CameraMetadataSectionStart.mako "$aidldir/CameraMetadataSectionStart.aidl" yes || exit 1
226gen_file_abs aidl/CameraMetadataTag.mako "$aidldir/CameraMetadataTag.aidl" yes || exit 1
227gen_enum_files aidl/CameraMetadataEnum.mako "$aidldir" yes || exit 1
228
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700229# Generate HTML properties documentation
Igor Murashkineaddcd42012-11-26 12:01:11 -0800230gen_file html.mako docs.html || exit 1
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700231
232# Generate C API headers and implementation
Igor Murashkineaddcd42012-11-26 12:01:11 -0800233gen_file camera_metadata_tag_info.mako ../src/camera_metadata_tag_info.c || exit 1
234gen_file camera_metadata_tags.mako ../include/system/camera_metadata_tags.h || exit 1
Austin Borgerd0ad9992022-03-18 11:09:24 -0700235gen_file camera_metadata_asserts.mako ../src/camera_metadata_asserts.cpp || exit 1
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700236
Jayant Chowdharyeca91ca2022-05-05 19:21:25 +0000237#Generate tags with vndk versions for filtering
238gen_file_abs vndk_camera_metadata_tags.mako "$libcameraservice_hidl_dir/VndkVersionMetadataTags.h" yes || exit 1
239
Yin-Chia Yehea7662f2015-12-22 16:25:00 -0800240#Generate NDK header
Eino-Ville Talvala0d404952017-11-10 15:13:04 -0800241gen_file_abs ndk_camera_metadata_tags.mako "$ndk_header_dir/NdkCameraMetadataTags.h" yes || exit 1
Yin-Chia Yehea7662f2015-12-22 16:25:00 -0800242
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700243# Generate Java API definitions
244mkdir -p "${outdir}"
245gen_file_abs CameraMetadataEnums.mako "$outdir/CameraMetadataEnums.java.part" no || exit 1
Igor Murashkin21d0f1a2013-09-10 12:25:56 -0700246gen_file_abs CameraCharacteristicsKeys.mako "$outdir/CameraCharacteristicsKeys.java.part" no || exit 1
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700247gen_file_abs CaptureRequestKeys.mako "$outdir/CaptureRequestKeys.java.part" no || exit 1
248gen_file_abs CaptureResultKeys.mako "$outdir/CaptureResultKeys.java.part" no || exit 1
249
250insert_file "$outdir/CameraMetadataEnums.java.part" "$fwkdir/CameraMetadata.java" || exit 1
Igor Murashkin21d0f1a2013-09-10 12:25:56 -0700251insert_file "$outdir/CameraCharacteristicsKeys.java.part" "$fwkdir/CameraCharacteristics.java" || exit 1
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700252insert_file "$outdir/CaptureRequestKeys.java.part" "$fwkdir/CaptureRequest.java" || exit 1
253insert_file "$outdir/CaptureResultKeys.java.part" "$fwkdir/CaptureResult.java" || exit 1
Yin-Chia Yehc9b27dd2016-02-23 19:18:15 -0800254
255# Generate CTS test code
256gen_file_abs CaptureResultTest.mako "$outdir/CaptureResultTest.java.part" no || exit 1
Yin-Chia Yeh3a52b8f2015-05-05 23:49:07 -0700257insert_file "$outdir/CaptureResultTest.java.part" "$ctsdir/CaptureResultTest.java" || exit 1
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700258
Yin-Chia Yehea7662f2015-12-22 16:25:00 -0800259# Generate NDK implementation
260gen_file_abs ACameraMetadata.mako "$outdir/ACameraMetadata.cpp.part" no || exit 1
261insert_file "$outdir/ACameraMetadata.cpp.part" "$ndk_impl_dir/ACameraMetadata.cpp" || exit 1
262
Yin-Chia Yehc9b27dd2016-02-23 19:18:15 -0800263# Generate CameraDeviceInfo code
264gen_file_abs CameraDeviceInfo.mako "$outdir/CameraDeviceInfo.java.part" no || exit 1
265insert_file "$outdir/CameraDeviceInfo.java.part" "$device_info_dir/CameraDeviceInfo.java" || exit 1
266
267# Generate protocol buffer definition corresponding to CameraDeviceInfo
268gen_file camera_device_info.mako ./camera_device_info.proto || exit 1
269
Igor Murashkin1dd4ecb2013-12-11 13:31:00 -0800270# Copy ./images directory into javadoc directory
271copy_directory "images" "$fwkdir_html" || exit 1
272
Yin-Chia Yeh4d24e412018-03-15 11:08:49 -0700273# Copy ./images directory into ndk doc directory
274copy_directory "images" "$ndkdir_html" || exit 1
275
Igor Murashkin1232dd22013-06-21 12:10:42 -0700276echo ""
277echo "===================================================="
Igor Murashkineaddcd42012-11-26 12:01:11 -0800278echo "Successfully generated all metadata source files"
Igor Murashkin1232dd22013-06-21 12:10:42 -0700279echo "===================================================="
280echo ""
281
282echo "****************************************************"
283echo "The following git repositories need to be committed:"
284echo "****************************************************"
285echo ""
286affected_git_directories "${out_files[@]}"
287echo ""
Igor Murashkineaddcd42012-11-26 12:01:11 -0800288
289exit 0