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