Igor Murashkin | eaddcd4 | 2012-11-26 12:01:11 -0800 | [diff] [blame] | 1 | #!/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 Cross | abc7c49 | 2017-05-05 09:36:03 -0700 | [diff] [blame] | 24 | # ../../../../frameworks/av/camera/ndk/include/camera/NdkCameraMetadataTags.h |
Yin-Chia Yeh | ea7662f | 2015-12-22 16:25:00 -0800 | [diff] [blame] | 25 | # ../../../../frameworks/av/camera/ndk/impl/ACameraMetadata.cpp |
Yin-Chia Yeh | 6c58d0a | 2015-12-05 17:20:33 -0800 | [diff] [blame] | 26 | # ../../../../cts/tests/camera/src/android/hardware/camera2/cts/CaptureResultTest.java |
Igor Murashkin | 21d0f1a | 2013-09-10 12:25:56 -0700 | [diff] [blame] | 27 | # ../../../../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 Murashkin | eaddcd4 | 2012-11-26 12:01:11 -0800 | [diff] [blame] | 30 | |
Igor Murashkin | aa133d3 | 2013-06-28 17:27:49 -0700 | [diff] [blame] | 31 | if [[ -z $ANDROID_BUILD_TOP ]]; then |
| 32 | echo "Please source build/envsetup.sh before running script" >& 2 |
| 33 | exit 1 |
| 34 | fi |
| 35 | |
Eino-Ville Talvala | 0888556 | 2013-03-18 09:43:57 -0700 | [diff] [blame] | 36 | thisdir=$(cd "$(dirname "$0")"; pwd) |
Eino-Ville Talvala | 47aa24d | 2013-07-25 17:10:11 -0700 | [diff] [blame] | 37 | fwkdir="$ANDROID_BUILD_TOP/frameworks/base/core/java/android/hardware/camera2/" |
Eino-Ville Talvala | 0d40495 | 2017-11-10 15:13:04 -0800 | [diff] [blame] | 38 | fwkdir_html="$ANDROID_BUILD_TOP/frameworks/base/docs/html/reference" |
Yin-Chia Yeh | 4d24e41 | 2018-03-15 11:08:49 -0700 | [diff] [blame] | 39 | ndkdir_html="$ANDROID_BUILD_TOP/frameworks/native/docs" |
Austin Borger | 476684b | 2022-03-18 11:08:37 -0700 | [diff] [blame] | 40 | aidldir="$ANDROID_BUILD_TOP/hardware/interfaces/camera/metadata/aidl/android/hardware/camera/metadata" |
Yin-Chia Yeh | 6c58d0a | 2015-12-05 17:20:33 -0800 | [diff] [blame] | 41 | ctsdir="$ANDROID_BUILD_TOP/cts/tests/camera/src/android/hardware/camera2/cts" |
Eino-Ville Talvala | d4e240a | 2013-08-08 12:56:37 -0700 | [diff] [blame] | 42 | outdir="$ANDROID_PRODUCT_OUT/obj/ETC/system-media-camera-docs_intermediates" |
Colin Cross | abc7c49 | 2017-05-05 09:36:03 -0700 | [diff] [blame] | 43 | ndk_header_dir="$ANDROID_BUILD_TOP/frameworks/av/camera/ndk/include/camera" |
Yin-Chia Yeh | ea7662f | 2015-12-22 16:25:00 -0800 | [diff] [blame] | 44 | ndk_impl_dir="$ANDROID_BUILD_TOP/frameworks/av/camera/ndk/impl" |
Jayant Chowdhary | eca91ca | 2022-05-05 19:21:25 +0000 | [diff] [blame] | 45 | libcameraservice_hidl_dir="$ANDROID_BUILD_TOP/frameworks/av/services/camera/libcameraservice/hidl" |
Yin-Chia Yeh | cf145ce | 2016-04-01 17:37:47 -0700 | [diff] [blame] | 46 | device_info_dir="$ANDROID_BUILD_TOP/cts/tools/cts-device-info/"` |
| 47 | `"src/com/android/cts/deviceinfo" |
Igor Murashkin | 1232dd2 | 2013-06-21 12:10:42 -0700 | [diff] [blame] | 48 | out_files=() |
Igor Murashkin | eaddcd4 | 2012-11-26 12:01:11 -0800 | [diff] [blame] | 49 | |
Igor Murashkin | 5804a48 | 2012-12-05 13:06:59 -0800 | [diff] [blame] | 50 | function relpath() { |
Eino-Ville Talvala | a5213a2 | 2020-05-10 16:57:36 -0700 | [diff] [blame] | 51 | python3 -c "import os.path; print(os.path.relpath('$1', '$PWD'))" |
Igor Murashkin | 5804a48 | 2012-12-05 13:06:59 -0800 | [diff] [blame] | 52 | } |
| 53 | |
Igor Murashkin | 1232dd2 | 2013-06-21 12:10:42 -0700 | [diff] [blame] | 54 | # Generates a file. Appends to $out_files array as a side effect. |
Igor Murashkin | eaddcd4 | 2012-11-26 12:01:11 -0800 | [diff] [blame] | 55 | function gen_file() { |
| 56 | local in=$thisdir/$1 |
| 57 | local out=$thisdir/$2 |
| 58 | |
Igor Murashkin | aa133d3 | 2013-06-28 17:27:49 -0700 | [diff] [blame] | 59 | gen_file_abs "$in" "$out" |
| 60 | return $? |
| 61 | } |
| 62 | |
| 63 | function gen_file_abs() { |
| 64 | local in="$1" |
| 65 | local out="$2" |
Eino-Ville Talvala | d4e240a | 2013-08-08 12:56:37 -0700 | [diff] [blame] | 66 | local intermediates="$3" |
Austin Borger | 476684b | 2022-03-18 11:08:37 -0700 | [diff] [blame] | 67 | local copyright_year="${4:-2022}" |
Eino-Ville Talvala | 0d40495 | 2017-11-10 15:13:04 -0800 | [diff] [blame] | 68 | local spec_file=$thisdir/metadata_definitions.xml |
Yin-Chia Yeh | c9c2c68 | 2016-05-25 01:29:55 -0700 | [diff] [blame] | 69 | |
Austin Borger | 476684b | 2022-03-18 11:08:37 -0700 | [diff] [blame] | 70 | python3 $thisdir/metadata_parser_xml.py $spec_file $in $out $copyright_year |
Igor Murashkin | 5804a48 | 2012-12-05 13:06:59 -0800 | [diff] [blame] | 71 | |
| 72 | local succ=$? |
| 73 | |
| 74 | if [[ $succ -eq 0 ]] |
| 75 | then |
| 76 | echo "OK: Generated $(relpath "$out")" |
Eino-Ville Talvala | d4e240a | 2013-08-08 12:56:37 -0700 | [diff] [blame] | 77 | if [[ "$intermediates" != "no" ]]; then |
| 78 | out_files+=$'\n'" $out" |
| 79 | fi |
Igor Murashkin | 5804a48 | 2012-12-05 13:06:59 -0800 | [diff] [blame] | 80 | else |
| 81 | echo "FAIL: Errors while generating $(relpath "$out")" >& 2 |
| 82 | fi |
| 83 | |
| 84 | return $succ |
Igor Murashkin | eaddcd4 | 2012-11-26 12:01:11 -0800 | [diff] [blame] | 85 | } |
| 86 | |
Austin Borger | 476684b | 2022-03-18 11:08:37 -0700 | [diff] [blame] | 87 | function 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 Murashkin | 1232dd2 | 2013-06-21 12:10:42 -0700 | [diff] [blame] | 111 | # Print a list of git repository paths which were affected after file generation |
| 112 | function 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 Murashkin | b8dc881 | 2013-07-17 16:29:34 -0700 | [diff] [blame] | 124 | local diff_result="$(cd "$dir_path"; |
| 125 | git status --porcelain | egrep -c -v '^[?][?]')" |
Igor Murashkin | 1232dd2 | 2013-06-21 12:10:42 -0700 | [diff] [blame] | 126 | 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 Murashkin | aa133d3 | 2013-06-28 17:27:49 -0700 | [diff] [blame] | 129 | echo "No changes in ${git_path}" >& /dev/null |
Igor Murashkin | 1232dd2 | 2013-06-21 12:10:42 -0700 | [diff] [blame] | 130 | 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 Murashkin | aa133d3 | 2013-06-28 17:27:49 -0700 | [diff] [blame] | 138 | printf %s\\n "${git_directories[@]}" | sort | uniq |
Igor Murashkin | 1232dd2 | 2013-06-21 12:10:42 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Eino-Ville Talvala | d4e240a | 2013-08-08 12:56:37 -0700 | [diff] [blame] | 141 | # 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 |
| 143 | function 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 Talvala | 54960fa | 2020-06-19 13:50:40 -0700 | [diff] [blame] | 156 | # Do some basic validity checks |
Eino-Ville Talvala | d4e240a | 2013-08-08 12:56:37 -0700 | [diff] [blame] | 157 | |
| 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 Murashkin | 1dd4ecb | 2013-12-11 13:31:00 -0800 | [diff] [blame] | 191 | # Recursively copy a directory tree from $1 to $2. Pretty-prints status. |
| 192 | function 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 Yeh | 4d24e41 | 2018-03-15 11:08:49 -0700 | [diff] [blame] | 212 | out_files+=$'\n'" $dst" |
Igor Murashkin | 1dd4ecb | 2013-12-11 13:31:00 -0800 | [diff] [blame] | 213 | fi |
| 214 | |
| 215 | return $retval |
| 216 | } |
| 217 | |
Igor Murashkin | 0334aa0 | 2012-12-04 14:59:53 -0800 | [diff] [blame] | 218 | $thisdir/metadata-check-dependencies || exit 1 |
Eino-Ville Talvala | 0d40495 | 2017-11-10 15:13:04 -0800 | [diff] [blame] | 219 | $thisdir/metadata-validate $thisdir/metadata_definitions.xml || exit 1 |
Eino-Ville Talvala | 54960fa | 2020-06-19 13:50:40 -0700 | [diff] [blame] | 220 | $thisdir/metadata-parser-validity-check || exit 1 |
Eino-Ville Talvala | d4e240a | 2013-08-08 12:56:37 -0700 | [diff] [blame] | 221 | |
Austin Borger | 476684b | 2022-03-18 11:08:37 -0700 | [diff] [blame] | 222 | # Generate AIDL metadata modules |
| 223 | mkdir -p "${aidldir}" |
| 224 | gen_file_abs aidl/CameraMetadataSection.mako "$aidldir/CameraMetadataSection.aidl" yes || exit 1 |
| 225 | gen_file_abs aidl/CameraMetadataSectionStart.mako "$aidldir/CameraMetadataSectionStart.aidl" yes || exit 1 |
| 226 | gen_file_abs aidl/CameraMetadataTag.mako "$aidldir/CameraMetadataTag.aidl" yes || exit 1 |
| 227 | gen_enum_files aidl/CameraMetadataEnum.mako "$aidldir" yes || exit 1 |
| 228 | |
Eino-Ville Talvala | d4e240a | 2013-08-08 12:56:37 -0700 | [diff] [blame] | 229 | # Generate HTML properties documentation |
Igor Murashkin | eaddcd4 | 2012-11-26 12:01:11 -0800 | [diff] [blame] | 230 | gen_file html.mako docs.html || exit 1 |
Eino-Ville Talvala | d4e240a | 2013-08-08 12:56:37 -0700 | [diff] [blame] | 231 | |
| 232 | # Generate C API headers and implementation |
Igor Murashkin | eaddcd4 | 2012-11-26 12:01:11 -0800 | [diff] [blame] | 233 | gen_file camera_metadata_tag_info.mako ../src/camera_metadata_tag_info.c || exit 1 |
| 234 | gen_file camera_metadata_tags.mako ../include/system/camera_metadata_tags.h || exit 1 |
Austin Borger | d0ad999 | 2022-03-18 11:09:24 -0700 | [diff] [blame] | 235 | gen_file camera_metadata_asserts.mako ../src/camera_metadata_asserts.cpp || exit 1 |
Eino-Ville Talvala | d4e240a | 2013-08-08 12:56:37 -0700 | [diff] [blame] | 236 | |
Jayant Chowdhary | eca91ca | 2022-05-05 19:21:25 +0000 | [diff] [blame] | 237 | #Generate tags with vndk versions for filtering |
| 238 | gen_file_abs vndk_camera_metadata_tags.mako "$libcameraservice_hidl_dir/VndkVersionMetadataTags.h" yes || exit 1 |
| 239 | |
Yin-Chia Yeh | ea7662f | 2015-12-22 16:25:00 -0800 | [diff] [blame] | 240 | #Generate NDK header |
Eino-Ville Talvala | 0d40495 | 2017-11-10 15:13:04 -0800 | [diff] [blame] | 241 | gen_file_abs ndk_camera_metadata_tags.mako "$ndk_header_dir/NdkCameraMetadataTags.h" yes || exit 1 |
Yin-Chia Yeh | ea7662f | 2015-12-22 16:25:00 -0800 | [diff] [blame] | 242 | |
Eino-Ville Talvala | d4e240a | 2013-08-08 12:56:37 -0700 | [diff] [blame] | 243 | # Generate Java API definitions |
| 244 | mkdir -p "${outdir}" |
| 245 | gen_file_abs CameraMetadataEnums.mako "$outdir/CameraMetadataEnums.java.part" no || exit 1 |
Igor Murashkin | 21d0f1a | 2013-09-10 12:25:56 -0700 | [diff] [blame] | 246 | gen_file_abs CameraCharacteristicsKeys.mako "$outdir/CameraCharacteristicsKeys.java.part" no || exit 1 |
Eino-Ville Talvala | d4e240a | 2013-08-08 12:56:37 -0700 | [diff] [blame] | 247 | gen_file_abs CaptureRequestKeys.mako "$outdir/CaptureRequestKeys.java.part" no || exit 1 |
| 248 | gen_file_abs CaptureResultKeys.mako "$outdir/CaptureResultKeys.java.part" no || exit 1 |
| 249 | |
| 250 | insert_file "$outdir/CameraMetadataEnums.java.part" "$fwkdir/CameraMetadata.java" || exit 1 |
Igor Murashkin | 21d0f1a | 2013-09-10 12:25:56 -0700 | [diff] [blame] | 251 | insert_file "$outdir/CameraCharacteristicsKeys.java.part" "$fwkdir/CameraCharacteristics.java" || exit 1 |
Eino-Ville Talvala | d4e240a | 2013-08-08 12:56:37 -0700 | [diff] [blame] | 252 | insert_file "$outdir/CaptureRequestKeys.java.part" "$fwkdir/CaptureRequest.java" || exit 1 |
| 253 | insert_file "$outdir/CaptureResultKeys.java.part" "$fwkdir/CaptureResult.java" || exit 1 |
Yin-Chia Yeh | c9b27dd | 2016-02-23 19:18:15 -0800 | [diff] [blame] | 254 | |
| 255 | # Generate CTS test code |
| 256 | gen_file_abs CaptureResultTest.mako "$outdir/CaptureResultTest.java.part" no || exit 1 |
Yin-Chia Yeh | 3a52b8f | 2015-05-05 23:49:07 -0700 | [diff] [blame] | 257 | insert_file "$outdir/CaptureResultTest.java.part" "$ctsdir/CaptureResultTest.java" || exit 1 |
Eino-Ville Talvala | d4e240a | 2013-08-08 12:56:37 -0700 | [diff] [blame] | 258 | |
Yin-Chia Yeh | ea7662f | 2015-12-22 16:25:00 -0800 | [diff] [blame] | 259 | # Generate NDK implementation |
| 260 | gen_file_abs ACameraMetadata.mako "$outdir/ACameraMetadata.cpp.part" no || exit 1 |
| 261 | insert_file "$outdir/ACameraMetadata.cpp.part" "$ndk_impl_dir/ACameraMetadata.cpp" || exit 1 |
| 262 | |
Yin-Chia Yeh | c9b27dd | 2016-02-23 19:18:15 -0800 | [diff] [blame] | 263 | # Generate CameraDeviceInfo code |
| 264 | gen_file_abs CameraDeviceInfo.mako "$outdir/CameraDeviceInfo.java.part" no || exit 1 |
| 265 | insert_file "$outdir/CameraDeviceInfo.java.part" "$device_info_dir/CameraDeviceInfo.java" || exit 1 |
| 266 | |
| 267 | # Generate protocol buffer definition corresponding to CameraDeviceInfo |
| 268 | gen_file camera_device_info.mako ./camera_device_info.proto || exit 1 |
| 269 | |
Igor Murashkin | 1dd4ecb | 2013-12-11 13:31:00 -0800 | [diff] [blame] | 270 | # Copy ./images directory into javadoc directory |
| 271 | copy_directory "images" "$fwkdir_html" || exit 1 |
| 272 | |
Yin-Chia Yeh | 4d24e41 | 2018-03-15 11:08:49 -0700 | [diff] [blame] | 273 | # Copy ./images directory into ndk doc directory |
| 274 | copy_directory "images" "$ndkdir_html" || exit 1 |
| 275 | |
Igor Murashkin | 1232dd2 | 2013-06-21 12:10:42 -0700 | [diff] [blame] | 276 | echo "" |
| 277 | echo "====================================================" |
Igor Murashkin | eaddcd4 | 2012-11-26 12:01:11 -0800 | [diff] [blame] | 278 | echo "Successfully generated all metadata source files" |
Igor Murashkin | 1232dd2 | 2013-06-21 12:10:42 -0700 | [diff] [blame] | 279 | echo "====================================================" |
| 280 | echo "" |
| 281 | |
| 282 | echo "****************************************************" |
| 283 | echo "The following git repositories need to be committed:" |
| 284 | echo "****************************************************" |
| 285 | echo "" |
| 286 | affected_git_directories "${out_files[@]}" |
| 287 | echo "" |
Igor Murashkin | eaddcd4 | 2012-11-26 12:01:11 -0800 | [diff] [blame] | 288 | |
| 289 | exit 0 |