blob: 36df140ba60dd90f61585c59a3b66f896cf50a8a [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
Timothy Knight5250aa12013-07-29 19:21:49 -070024# ../../../../cts/tests/tests/hardware/src/android/hardware/camera2/cts/CameraPropertiesTest.java
Igor Murashkineaddcd42012-11-26 12:01:11 -080025
Igor Murashkinaa133d32013-06-28 17:27:49 -070026if [[ -z $ANDROID_BUILD_TOP ]]; then
27 echo "Please source build/envsetup.sh before running script" >& 2
28 exit 1
29fi
30
Eino-Ville Talvala08885562013-03-18 09:43:57 -070031thisdir=$(cd "$(dirname "$0")"; pwd)
Eino-Ville Talvala47aa24d2013-07-25 17:10:11 -070032fwkdir="$ANDROID_BUILD_TOP/frameworks/base/core/java/android/hardware/camera2/"
Timothy Knight5250aa12013-07-29 19:21:49 -070033ctsdir="$ANDROID_BUILD_TOP/cts/tests/tests/hardware/src/android/hardware/camera2/cts"
34
Igor Murashkin1232dd22013-06-21 12:10:42 -070035out_files=()
Igor Murashkineaddcd42012-11-26 12:01:11 -080036
Igor Murashkin5804a482012-12-05 13:06:59 -080037function relpath() {
38 python -c "import os.path; print os.path.relpath('$1', '$PWD')"
39}
40
Igor Murashkin1232dd22013-06-21 12:10:42 -070041# Generates a file. Appends to $out_files array as a side effect.
Igor Murashkineaddcd42012-11-26 12:01:11 -080042function gen_file() {
43 local in=$thisdir/$1
44 local out=$thisdir/$2
45
Igor Murashkinaa133d32013-06-28 17:27:49 -070046 gen_file_abs "$in" "$out"
47 return $?
48}
49
50function gen_file_abs() {
51 local in="$1"
52 local out="$2"
53
Igor Murashkin48098682012-12-05 14:51:57 -080054 python $thisdir/metadata_parser_xml.py $thisdir/metadata_properties.xml $in $out
Igor Murashkin5804a482012-12-05 13:06:59 -080055
56 local succ=$?
57
58 if [[ $succ -eq 0 ]]
59 then
60 echo "OK: Generated $(relpath "$out")"
Igor Murashkin1232dd22013-06-21 12:10:42 -070061 out_files+=$'\n'" $out"
Igor Murashkin5804a482012-12-05 13:06:59 -080062 else
63 echo "FAIL: Errors while generating $(relpath "$out")" >& 2
64 fi
65
66 return $succ
Igor Murashkineaddcd42012-11-26 12:01:11 -080067}
68
Igor Murashkin1232dd22013-06-21 12:10:42 -070069# Print a list of git repository paths which were affected after file generation
70function 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 Murashkinb8dc8812013-07-17 16:29:34 -070082 local diff_result="$(cd "$dir_path";
83 git status --porcelain | egrep -c -v '^[?][?]')"
Igor Murashkin1232dd22013-06-21 12:10:42 -070084 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 Murashkinaa133d32013-06-28 17:27:49 -070087 echo "No changes in ${git_path}" >& /dev/null
Igor Murashkin1232dd22013-06-21 12:10:42 -070088 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 Murashkinaa133d32013-06-28 17:27:49 -070096 printf %s\\n "${git_directories[@]}" | sort | uniq
Igor Murashkin1232dd22013-06-21 12:10:42 -070097}
98
Igor Murashkin0334aa02012-12-04 14:59:53 -080099$thisdir/metadata-check-dependencies || exit 1
Igor Murashkinc469f7d2013-04-23 14:31:02 -0700100$thisdir/metadata-validate $thisdir/metadata_properties.xml || exit 1
Igor Murashkineaddcd42012-11-26 12:01:11 -0800101$thisdir/metadata-parser-sanity-check || exit 1
102gen_file html.mako docs.html || exit 1
103gen_file camera_metadata_tag_info.mako ../src/camera_metadata_tag_info.c || exit 1
104gen_file camera_metadata_tags.mako ../include/system/camera_metadata_tags.h || exit 1
Igor Murashkinaa133d32013-06-28 17:27:49 -0700105gen_file_abs CaptureResultKeys.mako "$fwkdir/CaptureResultKeys.java" || exit 1
106gen_file_abs CaptureRequestKeys.mako "$fwkdir/CaptureRequestKeys.java" || exit 1
107gen_file_abs CameraPropertiesKeys.mako "$fwkdir/CameraPropertiesKeys.java" || exit 1
Timothy Knight5250aa12013-07-29 19:21:49 -0700108gen_file_abs CameraPropertiesTest.mako "$ctsdir/CameraPropertiesTest.java" || exit 1
Igor Murashkineaddcd42012-11-26 12:01:11 -0800109
Igor Murashkin1232dd22013-06-21 12:10:42 -0700110echo ""
111echo "===================================================="
Igor Murashkineaddcd42012-11-26 12:01:11 -0800112echo "Successfully generated all metadata source files"
Igor Murashkin1232dd22013-06-21 12:10:42 -0700113echo "===================================================="
114echo ""
115
116echo "****************************************************"
117echo "The following git repositories need to be committed:"
118echo "****************************************************"
119echo ""
120affected_git_directories "${out_files[@]}"
121echo ""
Igor Murashkineaddcd42012-11-26 12:01:11 -0800122
123exit 0