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