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