blob: a013eaf54f6e16e49bc4157b9d52302210dcac12 [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"
Yin-Chia Yehcf145ce2016-04-01 17:37:47 -070043device_info_dir="$ANDROID_BUILD_TOP/cts/tools/cts-device-info/"`
44 `"src/com/android/cts/deviceinfo"
Igor Murashkin1232dd22013-06-21 12:10:42 -070045out_files=()
Igor Murashkineaddcd42012-11-26 12:01:11 -080046
Igor Murashkin5804a482012-12-05 13:06:59 -080047function relpath() {
48 python -c "import os.path; print os.path.relpath('$1', '$PWD')"
49}
50
Igor Murashkin1232dd22013-06-21 12:10:42 -070051# Generates a file. Appends to $out_files array as a side effect.
Igor Murashkineaddcd42012-11-26 12:01:11 -080052function gen_file() {
53 local in=$thisdir/$1
54 local out=$thisdir/$2
55
Igor Murashkinaa133d32013-06-28 17:27:49 -070056 gen_file_abs "$in" "$out"
57 return $?
58}
59
60function gen_file_abs() {
61 local in="$1"
62 local out="$2"
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -070063 local intermediates="$3"
Igor Murashkinaa133d32013-06-28 17:27:49 -070064
Igor Murashkin48098682012-12-05 14:51:57 -080065 python $thisdir/metadata_parser_xml.py $thisdir/metadata_properties.xml $in $out
Igor Murashkin5804a482012-12-05 13:06:59 -080066
67 local succ=$?
68
69 if [[ $succ -eq 0 ]]
70 then
71 echo "OK: Generated $(relpath "$out")"
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -070072 if [[ "$intermediates" != "no" ]]; then
73 out_files+=$'\n'" $out"
74 fi
Igor Murashkin5804a482012-12-05 13:06:59 -080075 else
76 echo "FAIL: Errors while generating $(relpath "$out")" >& 2
77 fi
78
79 return $succ
Igor Murashkineaddcd42012-11-26 12:01:11 -080080}
81
Igor Murashkin1232dd22013-06-21 12:10:42 -070082# Print a list of git repository paths which were affected after file generation
83function affected_git_directories() {
84 local input_files=($@)
85 local git_directories=()
86
87 for file in "${input_files[@]}"; do
88 local dir_path="$(dirname "$file")"
89 echo "Trying to cd into $dir_path" >& /dev/null
90 # Absolute path to the git repository root of that file
91 local git_path="$(cd "$dir_path";
92 git rev-parse --show-toplevel 2> /dev/null)"
93 if [[ $? -eq 0 ]]; then
94 # Both staged and unstaged changes
Igor Murashkinb8dc8812013-07-17 16:29:34 -070095 local diff_result="$(cd "$dir_path";
96 git status --porcelain | egrep -c -v '^[?][?]')"
Igor Murashkin1232dd22013-06-21 12:10:42 -070097 echo "Diff result was $diff_result" >& /dev/null
98 echo "Diff result was $diff_result" >& /dev/null
99 if [[ $diff_result -eq 0 ]]; then
Igor Murashkinaa133d32013-06-28 17:27:49 -0700100 echo "No changes in ${git_path}" >& /dev/null
Igor Murashkin1232dd22013-06-21 12:10:42 -0700101 else
102 echo "There are changes in ${git_path}" >& /dev/null
103 git_directories+=("$git_path")
104 fi
105 fi
106 done
107
108 # print as result the unique list of git directories affected
Igor Murashkinaa133d32013-06-28 17:27:49 -0700109 printf %s\\n "${git_directories[@]}" | sort | uniq
Igor Murashkin1232dd22013-06-21 12:10:42 -0700110}
111
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700112# Insert a file into the middle of another, starting at the line containing the
113# start delim and ending on the end delim, both of which are replaced
114function insert_file() {
115 local src_part="$1"
116 local dst_file="$2"
117 local start_delim="/*@O~"
118 local end_delim="~O@*/"
119
120 local start_line="$(grep -n -F "${start_delim}" "${dst_file}" | cut -d: -f1)"
121 local end_line="$(grep -n -F "${end_delim}" "${dst_file}" | cut -d: -f1)"
122
123 # Adjust cutoff points to use start/end line from inserted file
124 (( start_line-- ))
125 (( end_line++ ))
126
127 # Do some basic sanity checks
128
129 if [[ -z "$start_line" ]]; then
130 echo "No starting delimiter found in ${dst_file}" >& 2
131 echo "FAIL: Errors in inserting into $(relpath ${dst_file})" >& 2
132 return 1
133 fi
134
135 if [[ -z "$end_line" ]]; then
136 echo "No ending delimiter found in ${dst_file}" >& 2
137 echo "FAIL: Errors in inserting into $(relpath ${dst_file})" >& 2
138 return 1
139 fi
140
141 if [[ "$start_line" -ge "$end_line" ]]; then
142 echo "Starting delim later than ending delim: $start_line vs $end_line" >& 2
143 echo "FAIL: Errors in inserting into $(relpath ${dst_file})" >& 2
144 return 1
145 fi
146
147 local tmp_name=$(mktemp -t XXXXXXXX)
148
149 # Compose the three parts of the final file together
150
151 head -n "$start_line" "${dst_file}" > "${tmp_name}"
152 cat "${src_part}" >> "${tmp_name}"
153 tail -n "+${end_line}" "${dst_file}" >> "${tmp_name}"
154
155 # And replace the destination file with the new version
156
157 mv "${tmp_name}" "${dst_file}"
158 echo "OK: Inserted $(relpath "$src_part") into $(relpath "$dst_file")"
159 out_files+=$'\n'" $dst_file"
160}
161
Igor Murashkin1dd4ecb2013-12-11 13:31:00 -0800162# Recursively copy a directory tree from $1 to $2. Pretty-prints status.
163function copy_directory() {
164 local src="$thisdir/$1" # Relative to directory of this script
165 local dst="$2" # Absolute path
166
167 if ! [[ -d $src ]]; then
168 echo "FAIL: Source directory $src does not exist" >& 2
169 return 1
170 fi
171 if ! [[ -d $dst ]]; then
172 echo "FAIL: Destination directory $dst does not exist" >& 2
173 return 1
174 fi
175
176 cp -R "$src" "$dst"
177 local retval=$?
178
179 if [[ $retval -ne 0 ]]; then
180 echo "ERROR: Failed to copy $(relpath "$src") to $(relpath "$dst")" >& 2
181 else
182 echo "OK: Copied $(relpath "$src") to $(relpath "$dst")"
183 fi
184
185 return $retval
186}
187
Igor Murashkin0334aa02012-12-04 14:59:53 -0800188$thisdir/metadata-check-dependencies || exit 1
Igor Murashkinc469f7d2013-04-23 14:31:02 -0700189$thisdir/metadata-validate $thisdir/metadata_properties.xml || exit 1
Igor Murashkineaddcd42012-11-26 12:01:11 -0800190$thisdir/metadata-parser-sanity-check || exit 1
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700191
192# Generate HTML properties documentation
Igor Murashkineaddcd42012-11-26 12:01:11 -0800193gen_file html.mako docs.html || exit 1
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700194
195# Generate C API headers and implementation
Igor Murashkineaddcd42012-11-26 12:01:11 -0800196gen_file camera_metadata_tag_info.mako ../src/camera_metadata_tag_info.c || exit 1
197gen_file camera_metadata_tags.mako ../include/system/camera_metadata_tags.h || exit 1
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700198
Yin-Chia Yehea7662f2015-12-22 16:25:00 -0800199#Generate NDK header
200gen_file_abs ndk_camera_metadata_tags.mako "$ndk_header_dir/NdkCameraMetadataTags.h" || exit 1
201
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700202# Generate Java API definitions
203mkdir -p "${outdir}"
204gen_file_abs CameraMetadataEnums.mako "$outdir/CameraMetadataEnums.java.part" no || exit 1
Igor Murashkin21d0f1a2013-09-10 12:25:56 -0700205gen_file_abs CameraCharacteristicsKeys.mako "$outdir/CameraCharacteristicsKeys.java.part" no || exit 1
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700206gen_file_abs CaptureRequestKeys.mako "$outdir/CaptureRequestKeys.java.part" no || exit 1
207gen_file_abs CaptureResultKeys.mako "$outdir/CaptureResultKeys.java.part" no || exit 1
208
209insert_file "$outdir/CameraMetadataEnums.java.part" "$fwkdir/CameraMetadata.java" || exit 1
Igor Murashkin21d0f1a2013-09-10 12:25:56 -0700210insert_file "$outdir/CameraCharacteristicsKeys.java.part" "$fwkdir/CameraCharacteristics.java" || exit 1
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700211insert_file "$outdir/CaptureRequestKeys.java.part" "$fwkdir/CaptureRequest.java" || exit 1
212insert_file "$outdir/CaptureResultKeys.java.part" "$fwkdir/CaptureResult.java" || exit 1
Yin-Chia Yehc9b27dd2016-02-23 19:18:15 -0800213
214# Generate CTS test code
215gen_file_abs CaptureResultTest.mako "$outdir/CaptureResultTest.java.part" no || exit 1
Yin-Chia Yeh3a52b8f2015-05-05 23:49:07 -0700216insert_file "$outdir/CaptureResultTest.java.part" "$ctsdir/CaptureResultTest.java" || exit 1
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700217
Yin-Chia Yehea7662f2015-12-22 16:25:00 -0800218# Generate NDK implementation
219gen_file_abs ACameraMetadata.mako "$outdir/ACameraMetadata.cpp.part" no || exit 1
220insert_file "$outdir/ACameraMetadata.cpp.part" "$ndk_impl_dir/ACameraMetadata.cpp" || exit 1
221
Yin-Chia Yehc9b27dd2016-02-23 19:18:15 -0800222# Generate CameraDeviceInfo code
223gen_file_abs CameraDeviceInfo.mako "$outdir/CameraDeviceInfo.java.part" no || exit 1
224insert_file "$outdir/CameraDeviceInfo.java.part" "$device_info_dir/CameraDeviceInfo.java" || exit 1
225
226# Generate protocol buffer definition corresponding to CameraDeviceInfo
227gen_file camera_device_info.mako ./camera_device_info.proto || exit 1
228
Igor Murashkin1dd4ecb2013-12-11 13:31:00 -0800229# Copy ./images directory into javadoc directory
230copy_directory "images" "$fwkdir_html" || exit 1
231
Igor Murashkin1232dd22013-06-21 12:10:42 -0700232echo ""
233echo "===================================================="
Igor Murashkineaddcd42012-11-26 12:01:11 -0800234echo "Successfully generated all metadata source files"
Igor Murashkin1232dd22013-06-21 12:10:42 -0700235echo "===================================================="
236echo ""
237
238echo "****************************************************"
239echo "The following git repositories need to be committed:"
240echo "****************************************************"
241echo ""
242affected_git_directories "${out_files[@]}"
243echo ""
Igor Murashkineaddcd42012-11-26 12:01:11 -0800244
245exit 0