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 | 6c58d0a | 2015-12-05 17:20:33 -0800 | [diff] [blame] | 39 | 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] | 40 | outdir="$ANDROID_PRODUCT_OUT/obj/ETC/system-media-camera-docs_intermediates" |
Colin Cross | abc7c49 | 2017-05-05 09:36:03 -0700 | [diff] [blame] | 41 | 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] | 42 | ndk_impl_dir="$ANDROID_BUILD_TOP/frameworks/av/camera/ndk/impl" |
Yin-Chia Yeh | cf145ce | 2016-04-01 17:37:47 -0700 | [diff] [blame] | 43 | device_info_dir="$ANDROID_BUILD_TOP/cts/tools/cts-device-info/"` |
| 44 | `"src/com/android/cts/deviceinfo" |
Igor Murashkin | 1232dd2 | 2013-06-21 12:10:42 -0700 | [diff] [blame] | 45 | out_files=() |
Igor Murashkin | eaddcd4 | 2012-11-26 12:01:11 -0800 | [diff] [blame] | 46 | |
Igor Murashkin | 5804a48 | 2012-12-05 13:06:59 -0800 | [diff] [blame] | 47 | function relpath() { |
| 48 | python -c "import os.path; print os.path.relpath('$1', '$PWD')" |
| 49 | } |
| 50 | |
Igor Murashkin | 1232dd2 | 2013-06-21 12:10:42 -0700 | [diff] [blame] | 51 | # Generates a file. Appends to $out_files array as a side effect. |
Igor Murashkin | eaddcd4 | 2012-11-26 12:01:11 -0800 | [diff] [blame] | 52 | function gen_file() { |
| 53 | local in=$thisdir/$1 |
| 54 | local out=$thisdir/$2 |
| 55 | |
Igor Murashkin | aa133d3 | 2013-06-28 17:27:49 -0700 | [diff] [blame] | 56 | gen_file_abs "$in" "$out" |
| 57 | return $? |
| 58 | } |
| 59 | |
| 60 | function gen_file_abs() { |
| 61 | local in="$1" |
| 62 | local out="$2" |
Eino-Ville Talvala | d4e240a | 2013-08-08 12:56:37 -0700 | [diff] [blame] | 63 | local intermediates="$3" |
Eino-Ville Talvala | 0d40495 | 2017-11-10 15:13:04 -0800 | [diff] [blame^] | 64 | local spec_file=$thisdir/metadata_definitions.xml |
Yin-Chia Yeh | c9c2c68 | 2016-05-25 01:29:55 -0700 | [diff] [blame] | 65 | |
| 66 | python $thisdir/metadata_parser_xml.py $spec_file $in $out |
Igor Murashkin | 5804a48 | 2012-12-05 13:06:59 -0800 | [diff] [blame] | 67 | |
| 68 | local succ=$? |
| 69 | |
| 70 | if [[ $succ -eq 0 ]] |
| 71 | then |
| 72 | echo "OK: Generated $(relpath "$out")" |
Eino-Ville Talvala | d4e240a | 2013-08-08 12:56:37 -0700 | [diff] [blame] | 73 | if [[ "$intermediates" != "no" ]]; then |
| 74 | out_files+=$'\n'" $out" |
| 75 | fi |
Igor Murashkin | 5804a48 | 2012-12-05 13:06:59 -0800 | [diff] [blame] | 76 | else |
| 77 | echo "FAIL: Errors while generating $(relpath "$out")" >& 2 |
| 78 | fi |
| 79 | |
| 80 | return $succ |
Igor Murashkin | eaddcd4 | 2012-11-26 12:01:11 -0800 | [diff] [blame] | 81 | } |
| 82 | |
Igor Murashkin | 1232dd2 | 2013-06-21 12:10:42 -0700 | [diff] [blame] | 83 | # Print a list of git repository paths which were affected after file generation |
| 84 | function affected_git_directories() { |
| 85 | local input_files=($@) |
| 86 | local git_directories=() |
| 87 | |
| 88 | for file in "${input_files[@]}"; do |
| 89 | local dir_path="$(dirname "$file")" |
| 90 | echo "Trying to cd into $dir_path" >& /dev/null |
| 91 | # Absolute path to the git repository root of that file |
| 92 | local git_path="$(cd "$dir_path"; |
| 93 | git rev-parse --show-toplevel 2> /dev/null)" |
| 94 | if [[ $? -eq 0 ]]; then |
| 95 | # Both staged and unstaged changes |
Igor Murashkin | b8dc881 | 2013-07-17 16:29:34 -0700 | [diff] [blame] | 96 | local diff_result="$(cd "$dir_path"; |
| 97 | git status --porcelain | egrep -c -v '^[?][?]')" |
Igor Murashkin | 1232dd2 | 2013-06-21 12:10:42 -0700 | [diff] [blame] | 98 | echo "Diff result was $diff_result" >& /dev/null |
| 99 | echo "Diff result was $diff_result" >& /dev/null |
| 100 | if [[ $diff_result -eq 0 ]]; then |
Igor Murashkin | aa133d3 | 2013-06-28 17:27:49 -0700 | [diff] [blame] | 101 | echo "No changes in ${git_path}" >& /dev/null |
Igor Murashkin | 1232dd2 | 2013-06-21 12:10:42 -0700 | [diff] [blame] | 102 | else |
| 103 | echo "There are changes in ${git_path}" >& /dev/null |
| 104 | git_directories+=("$git_path") |
| 105 | fi |
| 106 | fi |
| 107 | done |
| 108 | |
| 109 | # print as result the unique list of git directories affected |
Igor Murashkin | aa133d3 | 2013-06-28 17:27:49 -0700 | [diff] [blame] | 110 | printf %s\\n "${git_directories[@]}" | sort | uniq |
Igor Murashkin | 1232dd2 | 2013-06-21 12:10:42 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Eino-Ville Talvala | d4e240a | 2013-08-08 12:56:37 -0700 | [diff] [blame] | 113 | # Insert a file into the middle of another, starting at the line containing the |
| 114 | # start delim and ending on the end delim, both of which are replaced |
| 115 | function insert_file() { |
| 116 | local src_part="$1" |
| 117 | local dst_file="$2" |
| 118 | local start_delim="/*@O~" |
| 119 | local end_delim="~O@*/" |
| 120 | |
| 121 | local start_line="$(grep -n -F "${start_delim}" "${dst_file}" | cut -d: -f1)" |
| 122 | local end_line="$(grep -n -F "${end_delim}" "${dst_file}" | cut -d: -f1)" |
| 123 | |
| 124 | # Adjust cutoff points to use start/end line from inserted file |
| 125 | (( start_line-- )) |
| 126 | (( end_line++ )) |
| 127 | |
| 128 | # Do some basic sanity checks |
| 129 | |
| 130 | if [[ -z "$start_line" ]]; then |
| 131 | echo "No starting delimiter found in ${dst_file}" >& 2 |
| 132 | echo "FAIL: Errors in inserting into $(relpath ${dst_file})" >& 2 |
| 133 | return 1 |
| 134 | fi |
| 135 | |
| 136 | if [[ -z "$end_line" ]]; then |
| 137 | echo "No ending delimiter found in ${dst_file}" >& 2 |
| 138 | echo "FAIL: Errors in inserting into $(relpath ${dst_file})" >& 2 |
| 139 | return 1 |
| 140 | fi |
| 141 | |
| 142 | if [[ "$start_line" -ge "$end_line" ]]; then |
| 143 | echo "Starting delim later than ending delim: $start_line vs $end_line" >& 2 |
| 144 | echo "FAIL: Errors in inserting into $(relpath ${dst_file})" >& 2 |
| 145 | return 1 |
| 146 | fi |
| 147 | |
| 148 | local tmp_name=$(mktemp -t XXXXXXXX) |
| 149 | |
| 150 | # Compose the three parts of the final file together |
| 151 | |
| 152 | head -n "$start_line" "${dst_file}" > "${tmp_name}" |
| 153 | cat "${src_part}" >> "${tmp_name}" |
| 154 | tail -n "+${end_line}" "${dst_file}" >> "${tmp_name}" |
| 155 | |
| 156 | # And replace the destination file with the new version |
| 157 | |
| 158 | mv "${tmp_name}" "${dst_file}" |
| 159 | echo "OK: Inserted $(relpath "$src_part") into $(relpath "$dst_file")" |
| 160 | out_files+=$'\n'" $dst_file" |
| 161 | } |
| 162 | |
Igor Murashkin | 1dd4ecb | 2013-12-11 13:31:00 -0800 | [diff] [blame] | 163 | # Recursively copy a directory tree from $1 to $2. Pretty-prints status. |
| 164 | function copy_directory() { |
| 165 | local src="$thisdir/$1" # Relative to directory of this script |
| 166 | local dst="$2" # Absolute path |
| 167 | |
| 168 | if ! [[ -d $src ]]; then |
| 169 | echo "FAIL: Source directory $src does not exist" >& 2 |
| 170 | return 1 |
| 171 | fi |
| 172 | if ! [[ -d $dst ]]; then |
| 173 | echo "FAIL: Destination directory $dst does not exist" >& 2 |
| 174 | return 1 |
| 175 | fi |
| 176 | |
| 177 | cp -R "$src" "$dst" |
| 178 | local retval=$? |
| 179 | |
| 180 | if [[ $retval -ne 0 ]]; then |
| 181 | echo "ERROR: Failed to copy $(relpath "$src") to $(relpath "$dst")" >& 2 |
| 182 | else |
| 183 | echo "OK: Copied $(relpath "$src") to $(relpath "$dst")" |
| 184 | fi |
| 185 | |
| 186 | return $retval |
| 187 | } |
| 188 | |
Igor Murashkin | 0334aa0 | 2012-12-04 14:59:53 -0800 | [diff] [blame] | 189 | $thisdir/metadata-check-dependencies || exit 1 |
Eino-Ville Talvala | 0d40495 | 2017-11-10 15:13:04 -0800 | [diff] [blame^] | 190 | $thisdir/metadata-validate $thisdir/metadata_definitions.xml || exit 1 |
Igor Murashkin | eaddcd4 | 2012-11-26 12:01:11 -0800 | [diff] [blame] | 191 | $thisdir/metadata-parser-sanity-check || exit 1 |
Eino-Ville Talvala | d4e240a | 2013-08-08 12:56:37 -0700 | [diff] [blame] | 192 | |
| 193 | # Generate HTML properties documentation |
Igor Murashkin | eaddcd4 | 2012-11-26 12:01:11 -0800 | [diff] [blame] | 194 | gen_file html.mako docs.html || exit 1 |
Eino-Ville Talvala | d4e240a | 2013-08-08 12:56:37 -0700 | [diff] [blame] | 195 | |
| 196 | # Generate C API headers and implementation |
Igor Murashkin | eaddcd4 | 2012-11-26 12:01:11 -0800 | [diff] [blame] | 197 | gen_file camera_metadata_tag_info.mako ../src/camera_metadata_tag_info.c || exit 1 |
| 198 | gen_file camera_metadata_tags.mako ../include/system/camera_metadata_tags.h || exit 1 |
Eino-Ville Talvala | d4e240a | 2013-08-08 12:56:37 -0700 | [diff] [blame] | 199 | |
Yin-Chia Yeh | ea7662f | 2015-12-22 16:25:00 -0800 | [diff] [blame] | 200 | #Generate NDK header |
Eino-Ville Talvala | 0d40495 | 2017-11-10 15:13:04 -0800 | [diff] [blame^] | 201 | 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] | 202 | |
Eino-Ville Talvala | d4e240a | 2013-08-08 12:56:37 -0700 | [diff] [blame] | 203 | # Generate Java API definitions |
| 204 | mkdir -p "${outdir}" |
| 205 | gen_file_abs CameraMetadataEnums.mako "$outdir/CameraMetadataEnums.java.part" no || exit 1 |
Igor Murashkin | 21d0f1a | 2013-09-10 12:25:56 -0700 | [diff] [blame] | 206 | 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] | 207 | gen_file_abs CaptureRequestKeys.mako "$outdir/CaptureRequestKeys.java.part" no || exit 1 |
| 208 | gen_file_abs CaptureResultKeys.mako "$outdir/CaptureResultKeys.java.part" no || exit 1 |
| 209 | |
| 210 | insert_file "$outdir/CameraMetadataEnums.java.part" "$fwkdir/CameraMetadata.java" || exit 1 |
Igor Murashkin | 21d0f1a | 2013-09-10 12:25:56 -0700 | [diff] [blame] | 211 | insert_file "$outdir/CameraCharacteristicsKeys.java.part" "$fwkdir/CameraCharacteristics.java" || exit 1 |
Eino-Ville Talvala | d4e240a | 2013-08-08 12:56:37 -0700 | [diff] [blame] | 212 | insert_file "$outdir/CaptureRequestKeys.java.part" "$fwkdir/CaptureRequest.java" || exit 1 |
| 213 | insert_file "$outdir/CaptureResultKeys.java.part" "$fwkdir/CaptureResult.java" || exit 1 |
Yin-Chia Yeh | c9b27dd | 2016-02-23 19:18:15 -0800 | [diff] [blame] | 214 | |
| 215 | # Generate CTS test code |
| 216 | 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] | 217 | insert_file "$outdir/CaptureResultTest.java.part" "$ctsdir/CaptureResultTest.java" || exit 1 |
Eino-Ville Talvala | d4e240a | 2013-08-08 12:56:37 -0700 | [diff] [blame] | 218 | |
Yin-Chia Yeh | ea7662f | 2015-12-22 16:25:00 -0800 | [diff] [blame] | 219 | # Generate NDK implementation |
| 220 | gen_file_abs ACameraMetadata.mako "$outdir/ACameraMetadata.cpp.part" no || exit 1 |
| 221 | insert_file "$outdir/ACameraMetadata.cpp.part" "$ndk_impl_dir/ACameraMetadata.cpp" || exit 1 |
| 222 | |
Yin-Chia Yeh | c9b27dd | 2016-02-23 19:18:15 -0800 | [diff] [blame] | 223 | # Generate CameraDeviceInfo code |
| 224 | gen_file_abs CameraDeviceInfo.mako "$outdir/CameraDeviceInfo.java.part" no || exit 1 |
| 225 | insert_file "$outdir/CameraDeviceInfo.java.part" "$device_info_dir/CameraDeviceInfo.java" || exit 1 |
| 226 | |
| 227 | # Generate protocol buffer definition corresponding to CameraDeviceInfo |
| 228 | gen_file camera_device_info.mako ./camera_device_info.proto || exit 1 |
| 229 | |
Igor Murashkin | 1dd4ecb | 2013-12-11 13:31:00 -0800 | [diff] [blame] | 230 | # Copy ./images directory into javadoc directory |
| 231 | copy_directory "images" "$fwkdir_html" || exit 1 |
| 232 | |
Igor Murashkin | 1232dd2 | 2013-06-21 12:10:42 -0700 | [diff] [blame] | 233 | echo "" |
| 234 | echo "====================================================" |
Igor Murashkin | eaddcd4 | 2012-11-26 12:01:11 -0800 | [diff] [blame] | 235 | echo "Successfully generated all metadata source files" |
Igor Murashkin | 1232dd2 | 2013-06-21 12:10:42 -0700 | [diff] [blame] | 236 | echo "====================================================" |
| 237 | echo "" |
| 238 | |
| 239 | echo "****************************************************" |
| 240 | echo "The following git repositories need to be committed:" |
| 241 | echo "****************************************************" |
| 242 | echo "" |
| 243 | affected_git_directories "${out_files[@]}" |
| 244 | echo "" |
Igor Murashkin | eaddcd4 | 2012-11-26 12:01:11 -0800 | [diff] [blame] | 245 | |
| 246 | exit 0 |