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