blob: 6999da92c18fffb491289484f5e607c91c0b5513 [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
Colin Crossabc7c492017-05-05 09:36:03 -070024# ../../../../frameworks/av/camera/ndk/include/camera/NdkCameraMetadataTags.h
Yin-Chia Yehea7662f2015-12-22 16:25:00 -080025# ../../../../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/"
Eino-Ville Talvala0d404952017-11-10 15:13:04 -080038fwkdir_html="$ANDROID_BUILD_TOP/frameworks/base/docs/html/reference"
Eino-Ville Talvaladafa6532017-11-17 14:48:20 -080039hidldir="$ANDROID_BUILD_TOP/hardware/interfaces/camera/metadata"
Yin-Chia Yeh6c58d0a2015-12-05 17:20:33 -080040ctsdir="$ANDROID_BUILD_TOP/cts/tests/camera/src/android/hardware/camera2/cts"
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -070041outdir="$ANDROID_PRODUCT_OUT/obj/ETC/system-media-camera-docs_intermediates"
Colin Crossabc7c492017-05-05 09:36:03 -070042ndk_header_dir="$ANDROID_BUILD_TOP/frameworks/av/camera/ndk/include/camera"
Yin-Chia Yehea7662f2015-12-22 16:25:00 -080043ndk_impl_dir="$ANDROID_BUILD_TOP/frameworks/av/camera/ndk/impl"
Yin-Chia Yehcf145ce2016-04-01 17:37:47 -070044device_info_dir="$ANDROID_BUILD_TOP/cts/tools/cts-device-info/"`
45 `"src/com/android/cts/deviceinfo"
Igor Murashkin1232dd22013-06-21 12:10:42 -070046out_files=()
Igor Murashkineaddcd42012-11-26 12:01:11 -080047
Igor Murashkin5804a482012-12-05 13:06:59 -080048function relpath() {
49 python -c "import os.path; print os.path.relpath('$1', '$PWD')"
50}
51
Igor Murashkin1232dd22013-06-21 12:10:42 -070052# Generates a file. Appends to $out_files array as a side effect.
Igor Murashkineaddcd42012-11-26 12:01:11 -080053function gen_file() {
54 local in=$thisdir/$1
55 local out=$thisdir/$2
56
Igor Murashkinaa133d32013-06-28 17:27:49 -070057 gen_file_abs "$in" "$out"
58 return $?
59}
60
61function gen_file_abs() {
62 local in="$1"
63 local out="$2"
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -070064 local intermediates="$3"
Eino-Ville Talvaladafa6532017-11-17 14:48:20 -080065 local hal_version="${4:-3.2}"
Eino-Ville Talvala0d404952017-11-10 15:13:04 -080066 local spec_file=$thisdir/metadata_definitions.xml
Yin-Chia Yehc9c2c682016-05-25 01:29:55 -070067
Eino-Ville Talvaladafa6532017-11-17 14:48:20 -080068 python $thisdir/metadata_parser_xml.py $spec_file $in $out $hal_version
Igor Murashkin5804a482012-12-05 13:06:59 -080069
70 local succ=$?
71
72 if [[ $succ -eq 0 ]]
73 then
74 echo "OK: Generated $(relpath "$out")"
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -070075 if [[ "$intermediates" != "no" ]]; then
76 out_files+=$'\n'" $out"
77 fi
Igor Murashkin5804a482012-12-05 13:06:59 -080078 else
79 echo "FAIL: Errors while generating $(relpath "$out")" >& 2
80 fi
81
82 return $succ
Igor Murashkineaddcd42012-11-26 12:01:11 -080083}
84
Igor Murashkin1232dd22013-06-21 12:10:42 -070085# Print a list of git repository paths which were affected after file generation
86function affected_git_directories() {
87 local input_files=($@)
88 local git_directories=()
89
90 for file in "${input_files[@]}"; do
91 local dir_path="$(dirname "$file")"
92 echo "Trying to cd into $dir_path" >& /dev/null
93 # Absolute path to the git repository root of that file
94 local git_path="$(cd "$dir_path";
95 git rev-parse --show-toplevel 2> /dev/null)"
96 if [[ $? -eq 0 ]]; then
97 # Both staged and unstaged changes
Igor Murashkinb8dc8812013-07-17 16:29:34 -070098 local diff_result="$(cd "$dir_path";
99 git status --porcelain | egrep -c -v '^[?][?]')"
Igor Murashkin1232dd22013-06-21 12:10:42 -0700100 echo "Diff result was $diff_result" >& /dev/null
101 echo "Diff result was $diff_result" >& /dev/null
102 if [[ $diff_result -eq 0 ]]; then
Igor Murashkinaa133d32013-06-28 17:27:49 -0700103 echo "No changes in ${git_path}" >& /dev/null
Igor Murashkin1232dd22013-06-21 12:10:42 -0700104 else
105 echo "There are changes in ${git_path}" >& /dev/null
106 git_directories+=("$git_path")
107 fi
108 fi
109 done
110
111 # print as result the unique list of git directories affected
Igor Murashkinaa133d32013-06-28 17:27:49 -0700112 printf %s\\n "${git_directories[@]}" | sort | uniq
Igor Murashkin1232dd22013-06-21 12:10:42 -0700113}
114
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700115# Insert a file into the middle of another, starting at the line containing the
116# start delim and ending on the end delim, both of which are replaced
117function insert_file() {
118 local src_part="$1"
119 local dst_file="$2"
120 local start_delim="/*@O~"
121 local end_delim="~O@*/"
122
123 local start_line="$(grep -n -F "${start_delim}" "${dst_file}" | cut -d: -f1)"
124 local end_line="$(grep -n -F "${end_delim}" "${dst_file}" | cut -d: -f1)"
125
126 # Adjust cutoff points to use start/end line from inserted file
127 (( start_line-- ))
128 (( end_line++ ))
129
130 # Do some basic sanity checks
131
132 if [[ -z "$start_line" ]]; then
133 echo "No starting delimiter found in ${dst_file}" >& 2
134 echo "FAIL: Errors in inserting into $(relpath ${dst_file})" >& 2
135 return 1
136 fi
137
138 if [[ -z "$end_line" ]]; then
139 echo "No ending delimiter found in ${dst_file}" >& 2
140 echo "FAIL: Errors in inserting into $(relpath ${dst_file})" >& 2
141 return 1
142 fi
143
144 if [[ "$start_line" -ge "$end_line" ]]; then
145 echo "Starting delim later than ending delim: $start_line vs $end_line" >& 2
146 echo "FAIL: Errors in inserting into $(relpath ${dst_file})" >& 2
147 return 1
148 fi
149
150 local tmp_name=$(mktemp -t XXXXXXXX)
151
152 # Compose the three parts of the final file together
153
154 head -n "$start_line" "${dst_file}" > "${tmp_name}"
155 cat "${src_part}" >> "${tmp_name}"
156 tail -n "+${end_line}" "${dst_file}" >> "${tmp_name}"
157
158 # And replace the destination file with the new version
159
160 mv "${tmp_name}" "${dst_file}"
161 echo "OK: Inserted $(relpath "$src_part") into $(relpath "$dst_file")"
162 out_files+=$'\n'" $dst_file"
163}
164
Igor Murashkin1dd4ecb2013-12-11 13:31:00 -0800165# Recursively copy a directory tree from $1 to $2. Pretty-prints status.
166function copy_directory() {
167 local src="$thisdir/$1" # Relative to directory of this script
168 local dst="$2" # Absolute path
169
170 if ! [[ -d $src ]]; then
171 echo "FAIL: Source directory $src does not exist" >& 2
172 return 1
173 fi
174 if ! [[ -d $dst ]]; then
175 echo "FAIL: Destination directory $dst does not exist" >& 2
176 return 1
177 fi
178
179 cp -R "$src" "$dst"
180 local retval=$?
181
182 if [[ $retval -ne 0 ]]; then
183 echo "ERROR: Failed to copy $(relpath "$src") to $(relpath "$dst")" >& 2
184 else
185 echo "OK: Copied $(relpath "$src") to $(relpath "$dst")"
186 fi
187
188 return $retval
189}
190
Igor Murashkin0334aa02012-12-04 14:59:53 -0800191$thisdir/metadata-check-dependencies || exit 1
Eino-Ville Talvala0d404952017-11-10 15:13:04 -0800192$thisdir/metadata-validate $thisdir/metadata_definitions.xml || exit 1
Igor Murashkineaddcd42012-11-26 12:01:11 -0800193$thisdir/metadata-parser-sanity-check || exit 1
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700194
195# Generate HTML properties documentation
Igor Murashkineaddcd42012-11-26 12:01:11 -0800196gen_file html.mako docs.html || exit 1
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700197
198# Generate C API headers and implementation
Igor Murashkineaddcd42012-11-26 12:01:11 -0800199gen_file camera_metadata_tag_info.mako ../src/camera_metadata_tag_info.c || exit 1
200gen_file camera_metadata_tags.mako ../include/system/camera_metadata_tags.h || exit 1
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700201
Eino-Ville Talvaladafa6532017-11-17 14:48:20 -0800202# Generate HIDL metadata modules - new versions need to be added here manually
203mkdir -p "${hidldir}/3.2"
204gen_file_abs HidlMetadata.mako "$hidldir/3.2/types.hal" yes 3.2 || exit 1
Eino-Ville Talvala63674ff2017-12-07 13:06:05 -0800205mkdir -p "${hidldir}/3.3"
206gen_file_abs HidlMetadata.mako "$hidldir/3.3/types.hal" yes 3.3 || exit 1
Eino-Ville Talvaladafa6532017-11-17 14:48:20 -0800207
Yin-Chia Yehea7662f2015-12-22 16:25:00 -0800208#Generate NDK header
Eino-Ville Talvala0d404952017-11-10 15:13:04 -0800209gen_file_abs ndk_camera_metadata_tags.mako "$ndk_header_dir/NdkCameraMetadataTags.h" yes || exit 1
Yin-Chia Yehea7662f2015-12-22 16:25:00 -0800210
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700211# Generate Java API definitions
212mkdir -p "${outdir}"
213gen_file_abs CameraMetadataEnums.mako "$outdir/CameraMetadataEnums.java.part" no || exit 1
Igor Murashkin21d0f1a2013-09-10 12:25:56 -0700214gen_file_abs CameraCharacteristicsKeys.mako "$outdir/CameraCharacteristicsKeys.java.part" no || exit 1
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700215gen_file_abs CaptureRequestKeys.mako "$outdir/CaptureRequestKeys.java.part" no || exit 1
216gen_file_abs CaptureResultKeys.mako "$outdir/CaptureResultKeys.java.part" no || exit 1
217
218insert_file "$outdir/CameraMetadataEnums.java.part" "$fwkdir/CameraMetadata.java" || exit 1
Igor Murashkin21d0f1a2013-09-10 12:25:56 -0700219insert_file "$outdir/CameraCharacteristicsKeys.java.part" "$fwkdir/CameraCharacteristics.java" || exit 1
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700220insert_file "$outdir/CaptureRequestKeys.java.part" "$fwkdir/CaptureRequest.java" || exit 1
221insert_file "$outdir/CaptureResultKeys.java.part" "$fwkdir/CaptureResult.java" || exit 1
Yin-Chia Yehc9b27dd2016-02-23 19:18:15 -0800222
223# Generate CTS test code
224gen_file_abs CaptureResultTest.mako "$outdir/CaptureResultTest.java.part" no || exit 1
Yin-Chia Yeh3a52b8f2015-05-05 23:49:07 -0700225insert_file "$outdir/CaptureResultTest.java.part" "$ctsdir/CaptureResultTest.java" || exit 1
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700226
Yin-Chia Yehea7662f2015-12-22 16:25:00 -0800227# Generate NDK implementation
228gen_file_abs ACameraMetadata.mako "$outdir/ACameraMetadata.cpp.part" no || exit 1
229insert_file "$outdir/ACameraMetadata.cpp.part" "$ndk_impl_dir/ACameraMetadata.cpp" || exit 1
230
Yin-Chia Yehc9b27dd2016-02-23 19:18:15 -0800231# Generate CameraDeviceInfo code
232gen_file_abs CameraDeviceInfo.mako "$outdir/CameraDeviceInfo.java.part" no || exit 1
233insert_file "$outdir/CameraDeviceInfo.java.part" "$device_info_dir/CameraDeviceInfo.java" || exit 1
234
235# Generate protocol buffer definition corresponding to CameraDeviceInfo
236gen_file camera_device_info.mako ./camera_device_info.proto || exit 1
237
Igor Murashkin1dd4ecb2013-12-11 13:31:00 -0800238# Copy ./images directory into javadoc directory
239copy_directory "images" "$fwkdir_html" || exit 1
240
Igor Murashkin1232dd22013-06-21 12:10:42 -0700241echo ""
242echo "===================================================="
Igor Murashkineaddcd42012-11-26 12:01:11 -0800243echo "Successfully generated all metadata source files"
Igor Murashkin1232dd22013-06-21 12:10:42 -0700244echo "===================================================="
245echo ""
246
247echo "****************************************************"
248echo "The following git repositories need to be committed:"
249echo "****************************************************"
250echo ""
251affected_git_directories "${out_files[@]}"
252echo ""
Igor Murashkineaddcd42012-11-26 12:01:11 -0800253
254exit 0