blob: 4a8a6eda2f9d3caf0bacf8ffa42293cb435a344b [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
Igor Murashkin21d0f1a2013-09-10 12:25:56 -070024# ../../../../cts/tests/tests/hardware/src/android/hardware/camera2/cts/CameraCharacteristicsTest.java
Zhijun Hec92a3882014-03-03 17:39:47 -080025# ../../../../cts/tests/tests/hardware/src/android/hardware/camera2/cts/CaptureResultTest.java
Igor Murashkin21d0f1a2013-09-10 12:25:56 -070026# ../../../../frameworks/base/core/java/android/hardware/camera2/CameraCharacteristics.java
27# ../../../../frameworks/base/core/java/android/hardware/camera2/CaptureRequest.java
28# ../../../../frameworks/base/core/java/android/hardware/camera2/CaptureResult.java
Igor Murashkineaddcd42012-11-26 12:01:11 -080029
Igor Murashkinaa133d32013-06-28 17:27:49 -070030if [[ -z $ANDROID_BUILD_TOP ]]; then
31 echo "Please source build/envsetup.sh before running script" >& 2
32 exit 1
33fi
34
Eino-Ville Talvala08885562013-03-18 09:43:57 -070035thisdir=$(cd "$(dirname "$0")"; pwd)
Eino-Ville Talvala47aa24d2013-07-25 17:10:11 -070036fwkdir="$ANDROID_BUILD_TOP/frameworks/base/core/java/android/hardware/camera2/"
Igor Murashkin1dd4ecb2013-12-11 13:31:00 -080037fwkdir_html="$ANDROID_BUILD_TOP/frameworks/base/docs/html"
Timothy Knight5250aa12013-07-29 19:21:49 -070038ctsdir="$ANDROID_BUILD_TOP/cts/tests/tests/hardware/src/android/hardware/camera2/cts"
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -070039outdir="$ANDROID_PRODUCT_OUT/obj/ETC/system-media-camera-docs_intermediates"
Igor Murashkin1232dd22013-06-21 12:10:42 -070040out_files=()
Igor Murashkineaddcd42012-11-26 12:01:11 -080041
Igor Murashkin5804a482012-12-05 13:06:59 -080042function relpath() {
43 python -c "import os.path; print os.path.relpath('$1', '$PWD')"
44}
45
Igor Murashkin1232dd22013-06-21 12:10:42 -070046# Generates a file. Appends to $out_files array as a side effect.
Igor Murashkineaddcd42012-11-26 12:01:11 -080047function gen_file() {
48 local in=$thisdir/$1
49 local out=$thisdir/$2
50
Igor Murashkinaa133d32013-06-28 17:27:49 -070051 gen_file_abs "$in" "$out"
52 return $?
53}
54
55function gen_file_abs() {
56 local in="$1"
57 local out="$2"
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -070058 local intermediates="$3"
Igor Murashkinaa133d32013-06-28 17:27:49 -070059
Igor Murashkin48098682012-12-05 14:51:57 -080060 python $thisdir/metadata_parser_xml.py $thisdir/metadata_properties.xml $in $out
Igor Murashkin5804a482012-12-05 13:06:59 -080061
62 local succ=$?
63
64 if [[ $succ -eq 0 ]]
65 then
66 echo "OK: Generated $(relpath "$out")"
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -070067 if [[ "$intermediates" != "no" ]]; then
68 out_files+=$'\n'" $out"
69 fi
Igor Murashkin5804a482012-12-05 13:06:59 -080070 else
71 echo "FAIL: Errors while generating $(relpath "$out")" >& 2
72 fi
73
74 return $succ
Igor Murashkineaddcd42012-11-26 12:01:11 -080075}
76
Igor Murashkin1232dd22013-06-21 12:10:42 -070077# Print a list of git repository paths which were affected after file generation
78function affected_git_directories() {
79 local input_files=($@)
80 local git_directories=()
81
82 for file in "${input_files[@]}"; do
83 local dir_path="$(dirname "$file")"
84 echo "Trying to cd into $dir_path" >& /dev/null
85 # Absolute path to the git repository root of that file
86 local git_path="$(cd "$dir_path";
87 git rev-parse --show-toplevel 2> /dev/null)"
88 if [[ $? -eq 0 ]]; then
89 # Both staged and unstaged changes
Igor Murashkinb8dc8812013-07-17 16:29:34 -070090 local diff_result="$(cd "$dir_path";
91 git status --porcelain | egrep -c -v '^[?][?]')"
Igor Murashkin1232dd22013-06-21 12:10:42 -070092 echo "Diff result was $diff_result" >& /dev/null
93 echo "Diff result was $diff_result" >& /dev/null
94 if [[ $diff_result -eq 0 ]]; then
Igor Murashkinaa133d32013-06-28 17:27:49 -070095 echo "No changes in ${git_path}" >& /dev/null
Igor Murashkin1232dd22013-06-21 12:10:42 -070096 else
97 echo "There are changes in ${git_path}" >& /dev/null
98 git_directories+=("$git_path")
99 fi
100 fi
101 done
102
103 # print as result the unique list of git directories affected
Igor Murashkinaa133d32013-06-28 17:27:49 -0700104 printf %s\\n "${git_directories[@]}" | sort | uniq
Igor Murashkin1232dd22013-06-21 12:10:42 -0700105}
106
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700107# Insert a file into the middle of another, starting at the line containing the
108# start delim and ending on the end delim, both of which are replaced
109function insert_file() {
110 local src_part="$1"
111 local dst_file="$2"
112 local start_delim="/*@O~"
113 local end_delim="~O@*/"
114
115 local start_line="$(grep -n -F "${start_delim}" "${dst_file}" | cut -d: -f1)"
116 local end_line="$(grep -n -F "${end_delim}" "${dst_file}" | cut -d: -f1)"
117
118 # Adjust cutoff points to use start/end line from inserted file
119 (( start_line-- ))
120 (( end_line++ ))
121
122 # Do some basic sanity checks
123
124 if [[ -z "$start_line" ]]; then
125 echo "No starting delimiter found in ${dst_file}" >& 2
126 echo "FAIL: Errors in inserting into $(relpath ${dst_file})" >& 2
127 return 1
128 fi
129
130 if [[ -z "$end_line" ]]; then
131 echo "No ending delimiter found in ${dst_file}" >& 2
132 echo "FAIL: Errors in inserting into $(relpath ${dst_file})" >& 2
133 return 1
134 fi
135
136 if [[ "$start_line" -ge "$end_line" ]]; then
137 echo "Starting delim later than ending delim: $start_line vs $end_line" >& 2
138 echo "FAIL: Errors in inserting into $(relpath ${dst_file})" >& 2
139 return 1
140 fi
141
142 local tmp_name=$(mktemp -t XXXXXXXX)
143
144 # Compose the three parts of the final file together
145
146 head -n "$start_line" "${dst_file}" > "${tmp_name}"
147 cat "${src_part}" >> "${tmp_name}"
148 tail -n "+${end_line}" "${dst_file}" >> "${tmp_name}"
149
150 # And replace the destination file with the new version
151
152 mv "${tmp_name}" "${dst_file}"
153 echo "OK: Inserted $(relpath "$src_part") into $(relpath "$dst_file")"
154 out_files+=$'\n'" $dst_file"
155}
156
Igor Murashkin1dd4ecb2013-12-11 13:31:00 -0800157# Recursively copy a directory tree from $1 to $2. Pretty-prints status.
158function copy_directory() {
159 local src="$thisdir/$1" # Relative to directory of this script
160 local dst="$2" # Absolute path
161
162 if ! [[ -d $src ]]; then
163 echo "FAIL: Source directory $src does not exist" >& 2
164 return 1
165 fi
166 if ! [[ -d $dst ]]; then
167 echo "FAIL: Destination directory $dst does not exist" >& 2
168 return 1
169 fi
170
171 cp -R "$src" "$dst"
172 local retval=$?
173
174 if [[ $retval -ne 0 ]]; then
175 echo "ERROR: Failed to copy $(relpath "$src") to $(relpath "$dst")" >& 2
176 else
177 echo "OK: Copied $(relpath "$src") to $(relpath "$dst")"
178 fi
179
180 return $retval
181}
182
Igor Murashkin0334aa02012-12-04 14:59:53 -0800183$thisdir/metadata-check-dependencies || exit 1
Igor Murashkinc469f7d2013-04-23 14:31:02 -0700184$thisdir/metadata-validate $thisdir/metadata_properties.xml || exit 1
Igor Murashkineaddcd42012-11-26 12:01:11 -0800185$thisdir/metadata-parser-sanity-check || exit 1
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700186
187# Generate HTML properties documentation
Igor Murashkineaddcd42012-11-26 12:01:11 -0800188gen_file html.mako docs.html || exit 1
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700189
190# Generate C API headers and implementation
Igor Murashkineaddcd42012-11-26 12:01:11 -0800191gen_file camera_metadata_tag_info.mako ../src/camera_metadata_tag_info.c || exit 1
192gen_file camera_metadata_tags.mako ../include/system/camera_metadata_tags.h || exit 1
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700193
194# Generate Java API definitions
195mkdir -p "${outdir}"
196gen_file_abs CameraMetadataEnums.mako "$outdir/CameraMetadataEnums.java.part" no || exit 1
Igor Murashkin21d0f1a2013-09-10 12:25:56 -0700197gen_file_abs CameraCharacteristicsKeys.mako "$outdir/CameraCharacteristicsKeys.java.part" no || exit 1
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700198gen_file_abs CaptureRequestKeys.mako "$outdir/CaptureRequestKeys.java.part" no || exit 1
199gen_file_abs CaptureResultKeys.mako "$outdir/CaptureResultKeys.java.part" no || exit 1
Zhijun Hec92a3882014-03-03 17:39:47 -0800200gen_file_abs CaptureResultTest.mako "$outdir/CaptureResultTest.java.part" no || exit 1
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700201
202insert_file "$outdir/CameraMetadataEnums.java.part" "$fwkdir/CameraMetadata.java" || exit 1
Igor Murashkin21d0f1a2013-09-10 12:25:56 -0700203insert_file "$outdir/CameraCharacteristicsKeys.java.part" "$fwkdir/CameraCharacteristics.java" || exit 1
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700204insert_file "$outdir/CaptureRequestKeys.java.part" "$fwkdir/CaptureRequest.java" || exit 1
205insert_file "$outdir/CaptureResultKeys.java.part" "$fwkdir/CaptureResult.java" || exit 1
206
Igor Murashkin1dd4ecb2013-12-11 13:31:00 -0800207# Copy ./images directory into javadoc directory
208copy_directory "images" "$fwkdir_html" || exit 1
209
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700210# Generate CTS tests
Igor Murashkin21d0f1a2013-09-10 12:25:56 -0700211gen_file_abs CameraCharacteristicsTest.mako "$ctsdir/CameraCharacteristicsTest.java" || exit 1
Zhijun Hec92a3882014-03-03 17:39:47 -0800212insert_file "$outdir/CaptureResultTest.java.part" "$ctsdir/CaptureResultTest.java" || exit 1
Igor Murashkineaddcd42012-11-26 12:01:11 -0800213
Igor Murashkin1232dd22013-06-21 12:10:42 -0700214echo ""
215echo "===================================================="
Igor Murashkineaddcd42012-11-26 12:01:11 -0800216echo "Successfully generated all metadata source files"
Igor Murashkin1232dd22013-06-21 12:10:42 -0700217echo "===================================================="
218echo ""
219
220echo "****************************************************"
221echo "The following git repositories need to be committed:"
222echo "****************************************************"
223echo ""
224affected_git_directories "${out_files[@]}"
225echo ""
Igor Murashkineaddcd42012-11-26 12:01:11 -0800226
227exit 0