blob: 6009c40a8b1ce63ba3a53d0b56ec357c4ad1a3b8 [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
Yin-Chia Yehea7662f2015-12-22 16:25:00 -080024# ../../../../frameworks/av/include/camera/ndk/NdkCameraMetadataTags.h
25# ../../../../frameworks/av/camera/ndk/impl/ACameraMetadata.cpp
Yin-Chia Yeh6c58d0a2015-12-05 17:20:33 -080026# ../../../../cts/tests/camera/src/android/hardware/camera2/cts/CaptureResultTest.java
Igor Murashkin21d0f1a2013-09-10 12:25:56 -070027# ../../../../frameworks/base/core/java/android/hardware/camera2/CameraCharacteristics.java
28# ../../../../frameworks/base/core/java/android/hardware/camera2/CaptureRequest.java
29# ../../../../frameworks/base/core/java/android/hardware/camera2/CaptureResult.java
Igor Murashkineaddcd42012-11-26 12:01:11 -080030
Igor Murashkinaa133d32013-06-28 17:27:49 -070031if [[ -z $ANDROID_BUILD_TOP ]]; then
32 echo "Please source build/envsetup.sh before running script" >& 2
33 exit 1
34fi
35
Eino-Ville Talvala08885562013-03-18 09:43:57 -070036thisdir=$(cd "$(dirname "$0")"; pwd)
Eino-Ville Talvala47aa24d2013-07-25 17:10:11 -070037fwkdir="$ANDROID_BUILD_TOP/frameworks/base/core/java/android/hardware/camera2/"
Igor Murashkin1dd4ecb2013-12-11 13:31:00 -080038fwkdir_html="$ANDROID_BUILD_TOP/frameworks/base/docs/html"
Yin-Chia Yeh6c58d0a2015-12-05 17:20:33 -080039ctsdir="$ANDROID_BUILD_TOP/cts/tests/camera/src/android/hardware/camera2/cts"
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -070040outdir="$ANDROID_PRODUCT_OUT/obj/ETC/system-media-camera-docs_intermediates"
Yin-Chia Yehea7662f2015-12-22 16:25:00 -080041ndk_header_dir="$ANDROID_BUILD_TOP/frameworks/av/include/camera/ndk"
42ndk_impl_dir="$ANDROID_BUILD_TOP/frameworks/av/camera/ndk/impl"
Igor Murashkin1232dd22013-06-21 12:10:42 -070043out_files=()
Igor Murashkineaddcd42012-11-26 12:01:11 -080044
Igor Murashkin5804a482012-12-05 13:06:59 -080045function relpath() {
46 python -c "import os.path; print os.path.relpath('$1', '$PWD')"
47}
48
Igor Murashkin1232dd22013-06-21 12:10:42 -070049# Generates a file. Appends to $out_files array as a side effect.
Igor Murashkineaddcd42012-11-26 12:01:11 -080050function gen_file() {
51 local in=$thisdir/$1
52 local out=$thisdir/$2
53
Igor Murashkinaa133d32013-06-28 17:27:49 -070054 gen_file_abs "$in" "$out"
55 return $?
56}
57
58function gen_file_abs() {
59 local in="$1"
60 local out="$2"
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -070061 local intermediates="$3"
Igor Murashkinaa133d32013-06-28 17:27:49 -070062
Igor Murashkin48098682012-12-05 14:51:57 -080063 python $thisdir/metadata_parser_xml.py $thisdir/metadata_properties.xml $in $out
Igor Murashkin5804a482012-12-05 13:06:59 -080064
65 local succ=$?
66
67 if [[ $succ -eq 0 ]]
68 then
69 echo "OK: Generated $(relpath "$out")"
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -070070 if [[ "$intermediates" != "no" ]]; then
71 out_files+=$'\n'" $out"
72 fi
Igor Murashkin5804a482012-12-05 13:06:59 -080073 else
74 echo "FAIL: Errors while generating $(relpath "$out")" >& 2
75 fi
76
77 return $succ
Igor Murashkineaddcd42012-11-26 12:01:11 -080078}
79
Igor Murashkin1232dd22013-06-21 12:10:42 -070080# Print a list of git repository paths which were affected after file generation
81function affected_git_directories() {
82 local input_files=($@)
83 local git_directories=()
84
85 for file in "${input_files[@]}"; do
86 local dir_path="$(dirname "$file")"
87 echo "Trying to cd into $dir_path" >& /dev/null
88 # Absolute path to the git repository root of that file
89 local git_path="$(cd "$dir_path";
90 git rev-parse --show-toplevel 2> /dev/null)"
91 if [[ $? -eq 0 ]]; then
92 # Both staged and unstaged changes
Igor Murashkinb8dc8812013-07-17 16:29:34 -070093 local diff_result="$(cd "$dir_path";
94 git status --porcelain | egrep -c -v '^[?][?]')"
Igor Murashkin1232dd22013-06-21 12:10:42 -070095 echo "Diff result was $diff_result" >& /dev/null
96 echo "Diff result was $diff_result" >& /dev/null
97 if [[ $diff_result -eq 0 ]]; then
Igor Murashkinaa133d32013-06-28 17:27:49 -070098 echo "No changes in ${git_path}" >& /dev/null
Igor Murashkin1232dd22013-06-21 12:10:42 -070099 else
100 echo "There are changes in ${git_path}" >& /dev/null
101 git_directories+=("$git_path")
102 fi
103 fi
104 done
105
106 # print as result the unique list of git directories affected
Igor Murashkinaa133d32013-06-28 17:27:49 -0700107 printf %s\\n "${git_directories[@]}" | sort | uniq
Igor Murashkin1232dd22013-06-21 12:10:42 -0700108}
109
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700110# Insert a file into the middle of another, starting at the line containing the
111# start delim and ending on the end delim, both of which are replaced
112function insert_file() {
113 local src_part="$1"
114 local dst_file="$2"
115 local start_delim="/*@O~"
116 local end_delim="~O@*/"
117
118 local start_line="$(grep -n -F "${start_delim}" "${dst_file}" | cut -d: -f1)"
119 local end_line="$(grep -n -F "${end_delim}" "${dst_file}" | cut -d: -f1)"
120
121 # Adjust cutoff points to use start/end line from inserted file
122 (( start_line-- ))
123 (( end_line++ ))
124
125 # Do some basic sanity checks
126
127 if [[ -z "$start_line" ]]; then
128 echo "No starting delimiter found in ${dst_file}" >& 2
129 echo "FAIL: Errors in inserting into $(relpath ${dst_file})" >& 2
130 return 1
131 fi
132
133 if [[ -z "$end_line" ]]; then
134 echo "No ending delimiter found in ${dst_file}" >& 2
135 echo "FAIL: Errors in inserting into $(relpath ${dst_file})" >& 2
136 return 1
137 fi
138
139 if [[ "$start_line" -ge "$end_line" ]]; then
140 echo "Starting delim later than ending delim: $start_line vs $end_line" >& 2
141 echo "FAIL: Errors in inserting into $(relpath ${dst_file})" >& 2
142 return 1
143 fi
144
145 local tmp_name=$(mktemp -t XXXXXXXX)
146
147 # Compose the three parts of the final file together
148
149 head -n "$start_line" "${dst_file}" > "${tmp_name}"
150 cat "${src_part}" >> "${tmp_name}"
151 tail -n "+${end_line}" "${dst_file}" >> "${tmp_name}"
152
153 # And replace the destination file with the new version
154
155 mv "${tmp_name}" "${dst_file}"
156 echo "OK: Inserted $(relpath "$src_part") into $(relpath "$dst_file")"
157 out_files+=$'\n'" $dst_file"
158}
159
Igor Murashkin1dd4ecb2013-12-11 13:31:00 -0800160# Recursively copy a directory tree from $1 to $2. Pretty-prints status.
161function copy_directory() {
162 local src="$thisdir/$1" # Relative to directory of this script
163 local dst="$2" # Absolute path
164
165 if ! [[ -d $src ]]; then
166 echo "FAIL: Source directory $src does not exist" >& 2
167 return 1
168 fi
169 if ! [[ -d $dst ]]; then
170 echo "FAIL: Destination directory $dst does not exist" >& 2
171 return 1
172 fi
173
174 cp -R "$src" "$dst"
175 local retval=$?
176
177 if [[ $retval -ne 0 ]]; then
178 echo "ERROR: Failed to copy $(relpath "$src") to $(relpath "$dst")" >& 2
179 else
180 echo "OK: Copied $(relpath "$src") to $(relpath "$dst")"
181 fi
182
183 return $retval
184}
185
Igor Murashkin0334aa02012-12-04 14:59:53 -0800186$thisdir/metadata-check-dependencies || exit 1
Igor Murashkinc469f7d2013-04-23 14:31:02 -0700187$thisdir/metadata-validate $thisdir/metadata_properties.xml || exit 1
Igor Murashkineaddcd42012-11-26 12:01:11 -0800188$thisdir/metadata-parser-sanity-check || exit 1
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700189
190# Generate HTML properties documentation
Igor Murashkineaddcd42012-11-26 12:01:11 -0800191gen_file html.mako docs.html || exit 1
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700192
193# Generate C API headers and implementation
Igor Murashkineaddcd42012-11-26 12:01:11 -0800194gen_file camera_metadata_tag_info.mako ../src/camera_metadata_tag_info.c || exit 1
195gen_file camera_metadata_tags.mako ../include/system/camera_metadata_tags.h || exit 1
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700196
Yin-Chia Yehea7662f2015-12-22 16:25:00 -0800197#Generate NDK header
198gen_file_abs ndk_camera_metadata_tags.mako "$ndk_header_dir/NdkCameraMetadataTags.h" || exit 1
199
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700200# Generate Java API definitions
201mkdir -p "${outdir}"
202gen_file_abs CameraMetadataEnums.mako "$outdir/CameraMetadataEnums.java.part" no || exit 1
Igor Murashkin21d0f1a2013-09-10 12:25:56 -0700203gen_file_abs CameraCharacteristicsKeys.mako "$outdir/CameraCharacteristicsKeys.java.part" no || exit 1
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700204gen_file_abs CaptureRequestKeys.mako "$outdir/CaptureRequestKeys.java.part" no || exit 1
205gen_file_abs CaptureResultKeys.mako "$outdir/CaptureResultKeys.java.part" no || exit 1
Zhijun Hec92a3882014-03-03 17:39:47 -0800206gen_file_abs CaptureResultTest.mako "$outdir/CaptureResultTest.java.part" no || exit 1
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700207
208insert_file "$outdir/CameraMetadataEnums.java.part" "$fwkdir/CameraMetadata.java" || exit 1
Igor Murashkin21d0f1a2013-09-10 12:25:56 -0700209insert_file "$outdir/CameraCharacteristicsKeys.java.part" "$fwkdir/CameraCharacteristics.java" || exit 1
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700210insert_file "$outdir/CaptureRequestKeys.java.part" "$fwkdir/CaptureRequest.java" || exit 1
211insert_file "$outdir/CaptureResultKeys.java.part" "$fwkdir/CaptureResult.java" || exit 1
Yin-Chia Yeh3a52b8f2015-05-05 23:49:07 -0700212insert_file "$outdir/CaptureResultTest.java.part" "$ctsdir/CaptureResultTest.java" || exit 1
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700213
Yin-Chia Yehea7662f2015-12-22 16:25:00 -0800214# Generate NDK implementation
215gen_file_abs ACameraMetadata.mako "$outdir/ACameraMetadata.cpp.part" no || exit 1
216insert_file "$outdir/ACameraMetadata.cpp.part" "$ndk_impl_dir/ACameraMetadata.cpp" || exit 1
217
Igor Murashkin1dd4ecb2013-12-11 13:31:00 -0800218# Copy ./images directory into javadoc directory
219copy_directory "images" "$fwkdir_html" || exit 1
220
Igor Murashkin1232dd22013-06-21 12:10:42 -0700221echo ""
222echo "===================================================="
Igor Murashkineaddcd42012-11-26 12:01:11 -0800223echo "Successfully generated all metadata source files"
Igor Murashkin1232dd22013-06-21 12:10:42 -0700224echo "===================================================="
225echo ""
226
227echo "****************************************************"
228echo "The following git repositories need to be committed:"
229echo "****************************************************"
230echo ""
231affected_git_directories "${out_files[@]}"
232echo ""
Igor Murashkineaddcd42012-11-26 12:01:11 -0800233
234exit 0