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" |
| 34 | |
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" |
| 53 | |
Igor Murashkin | 4809868 | 2012-12-05 14:51:57 -0800 | [diff] [blame] | 54 | python $thisdir/metadata_parser_xml.py $thisdir/metadata_properties.xml $in $out |
Igor Murashkin | 5804a48 | 2012-12-05 13:06:59 -0800 | [diff] [blame] | 55 | |
| 56 | local succ=$? |
| 57 | |
| 58 | if [[ $succ -eq 0 ]] |
| 59 | then |
| 60 | echo "OK: Generated $(relpath "$out")" |
Igor Murashkin | 1232dd2 | 2013-06-21 12:10:42 -0700 | [diff] [blame] | 61 | out_files+=$'\n'" $out" |
Igor Murashkin | 5804a48 | 2012-12-05 13:06:59 -0800 | [diff] [blame] | 62 | else |
| 63 | echo "FAIL: Errors while generating $(relpath "$out")" >& 2 |
| 64 | fi |
| 65 | |
| 66 | return $succ |
Igor Murashkin | eaddcd4 | 2012-11-26 12:01:11 -0800 | [diff] [blame] | 67 | } |
| 68 | |
Igor Murashkin | 1232dd2 | 2013-06-21 12:10:42 -0700 | [diff] [blame] | 69 | # Print a list of git repository paths which were affected after file generation |
| 70 | function affected_git_directories() { |
| 71 | local input_files=($@) |
| 72 | local git_directories=() |
| 73 | |
| 74 | for file in "${input_files[@]}"; do |
| 75 | local dir_path="$(dirname "$file")" |
| 76 | echo "Trying to cd into $dir_path" >& /dev/null |
| 77 | # Absolute path to the git repository root of that file |
| 78 | local git_path="$(cd "$dir_path"; |
| 79 | git rev-parse --show-toplevel 2> /dev/null)" |
| 80 | if [[ $? -eq 0 ]]; then |
| 81 | # Both staged and unstaged changes |
Igor Murashkin | b8dc881 | 2013-07-17 16:29:34 -0700 | [diff] [blame] | 82 | local diff_result="$(cd "$dir_path"; |
| 83 | git status --porcelain | egrep -c -v '^[?][?]')" |
Igor Murashkin | 1232dd2 | 2013-06-21 12:10:42 -0700 | [diff] [blame] | 84 | echo "Diff result was $diff_result" >& /dev/null |
| 85 | echo "Diff result was $diff_result" >& /dev/null |
| 86 | if [[ $diff_result -eq 0 ]]; then |
Igor Murashkin | aa133d3 | 2013-06-28 17:27:49 -0700 | [diff] [blame] | 87 | echo "No changes in ${git_path}" >& /dev/null |
Igor Murashkin | 1232dd2 | 2013-06-21 12:10:42 -0700 | [diff] [blame] | 88 | else |
| 89 | echo "There are changes in ${git_path}" >& /dev/null |
| 90 | git_directories+=("$git_path") |
| 91 | fi |
| 92 | fi |
| 93 | done |
| 94 | |
| 95 | # print as result the unique list of git directories affected |
Igor Murashkin | aa133d3 | 2013-06-28 17:27:49 -0700 | [diff] [blame] | 96 | printf %s\\n "${git_directories[@]}" | sort | uniq |
Igor Murashkin | 1232dd2 | 2013-06-21 12:10:42 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Igor Murashkin | 0334aa0 | 2012-12-04 14:59:53 -0800 | [diff] [blame] | 99 | $thisdir/metadata-check-dependencies || exit 1 |
Igor Murashkin | c469f7d | 2013-04-23 14:31:02 -0700 | [diff] [blame] | 100 | $thisdir/metadata-validate $thisdir/metadata_properties.xml || exit 1 |
Igor Murashkin | eaddcd4 | 2012-11-26 12:01:11 -0800 | [diff] [blame] | 101 | $thisdir/metadata-parser-sanity-check || exit 1 |
| 102 | gen_file html.mako docs.html || exit 1 |
| 103 | gen_file camera_metadata_tag_info.mako ../src/camera_metadata_tag_info.c || exit 1 |
| 104 | gen_file camera_metadata_tags.mako ../include/system/camera_metadata_tags.h || exit 1 |
Igor Murashkin | aa133d3 | 2013-06-28 17:27:49 -0700 | [diff] [blame] | 105 | gen_file_abs CaptureResultKeys.mako "$fwkdir/CaptureResultKeys.java" || exit 1 |
| 106 | gen_file_abs CaptureRequestKeys.mako "$fwkdir/CaptureRequestKeys.java" || exit 1 |
| 107 | gen_file_abs CameraPropertiesKeys.mako "$fwkdir/CameraPropertiesKeys.java" || exit 1 |
Timothy Knight | 5250aa1 | 2013-07-29 19:21:49 -0700 | [diff] [blame^] | 108 | gen_file_abs CameraPropertiesTest.mako "$ctsdir/CameraPropertiesTest.java" || exit 1 |
Igor Murashkin | eaddcd4 | 2012-11-26 12:01:11 -0800 | [diff] [blame] | 109 | |
Igor Murashkin | 1232dd2 | 2013-06-21 12:10:42 -0700 | [diff] [blame] | 110 | echo "" |
| 111 | echo "====================================================" |
Igor Murashkin | eaddcd4 | 2012-11-26 12:01:11 -0800 | [diff] [blame] | 112 | echo "Successfully generated all metadata source files" |
Igor Murashkin | 1232dd2 | 2013-06-21 12:10:42 -0700 | [diff] [blame] | 113 | echo "====================================================" |
| 114 | echo "" |
| 115 | |
| 116 | echo "****************************************************" |
| 117 | echo "The following git repositories need to be committed:" |
| 118 | echo "****************************************************" |
| 119 | echo "" |
| 120 | affected_git_directories "${out_files[@]}" |
| 121 | echo "" |
Igor Murashkin | eaddcd4 | 2012-11-26 12:01:11 -0800 | [diff] [blame] | 122 | |
| 123 | exit 0 |