blob: 6084531bef3ffb6ced273c8f5ef6ae1e3e04e3a7 [file] [log] [blame]
Igor Murashkineaddcd42012-11-26 12:01:11 -08001#!/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 Talvala08885562013-03-18 09:43:57 -070026thisdir=$(cd "$(dirname "$0")"; pwd)
Igor Murashkin1232dd22013-06-21 12:10:42 -070027out_files=()
Igor Murashkineaddcd42012-11-26 12:01:11 -080028
Igor Murashkin5804a482012-12-05 13:06:59 -080029function relpath() {
30 python -c "import os.path; print os.path.relpath('$1', '$PWD')"
31}
32
Igor Murashkin1232dd22013-06-21 12:10:42 -070033# Generates a file. Appends to $out_files array as a side effect.
Igor Murashkineaddcd42012-11-26 12:01:11 -080034function gen_file() {
35 local in=$thisdir/$1
36 local out=$thisdir/$2
37
Igor Murashkin48098682012-12-05 14:51:57 -080038 python $thisdir/metadata_parser_xml.py $thisdir/metadata_properties.xml $in $out
Igor Murashkin5804a482012-12-05 13:06:59 -080039
40 local succ=$?
41
42 if [[ $succ -eq 0 ]]
43 then
44 echo "OK: Generated $(relpath "$out")"
Igor Murashkin1232dd22013-06-21 12:10:42 -070045 out_files+=$'\n'" $out"
Igor Murashkin5804a482012-12-05 13:06:59 -080046 else
47 echo "FAIL: Errors while generating $(relpath "$out")" >& 2
48 fi
49
50 return $succ
Igor Murashkineaddcd42012-11-26 12:01:11 -080051}
52
Igor Murashkin1232dd22013-06-21 12:10:42 -070053# Print a list of git repository paths which were affected after file generation
54function 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 Murashkin0334aa02012-12-04 14:59:53 -080082$thisdir/metadata-check-dependencies || exit 1
Igor Murashkinc469f7d2013-04-23 14:31:02 -070083$thisdir/metadata-validate $thisdir/metadata_properties.xml || exit 1
Igor Murashkineaddcd42012-11-26 12:01:11 -080084$thisdir/metadata-parser-sanity-check || exit 1
85gen_file html.mako docs.html || exit 1
86gen_file camera_metadata_tag_info.mako ../src/camera_metadata_tag_info.c || exit 1
87gen_file camera_metadata_tags.mako ../include/system/camera_metadata_tags.h || exit 1
88
Igor Murashkin1232dd22013-06-21 12:10:42 -070089echo ""
90echo "===================================================="
Igor Murashkineaddcd42012-11-26 12:01:11 -080091echo "Successfully generated all metadata source files"
Igor Murashkin1232dd22013-06-21 12:10:42 -070092echo "===================================================="
93echo ""
94
95echo "****************************************************"
96echo "The following git repositories need to be committed:"
97echo "****************************************************"
98echo ""
99affected_git_directories "${out_files[@]}"
100echo ""
Igor Murashkineaddcd42012-11-26 12:01:11 -0800101
102exit 0