blob: 85c18096a58035c6cbcf23117b2005e4ec307ed3 [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
25# ../../../../frameworks/base/core/java/android/hardware/camera2/CameraCharacteristics.java
26# ../../../../frameworks/base/core/java/android/hardware/camera2/CaptureRequest.java
27# ../../../../frameworks/base/core/java/android/hardware/camera2/CaptureResult.java
Igor Murashkineaddcd42012-11-26 12:01:11 -080028
Igor Murashkinaa133d32013-06-28 17:27:49 -070029if [[ -z $ANDROID_BUILD_TOP ]]; then
30 echo "Please source build/envsetup.sh before running script" >& 2
31 exit 1
32fi
33
Eino-Ville Talvala08885562013-03-18 09:43:57 -070034thisdir=$(cd "$(dirname "$0")"; pwd)
Eino-Ville Talvala47aa24d2013-07-25 17:10:11 -070035fwkdir="$ANDROID_BUILD_TOP/frameworks/base/core/java/android/hardware/camera2/"
Timothy Knight5250aa12013-07-29 19:21:49 -070036ctsdir="$ANDROID_BUILD_TOP/cts/tests/tests/hardware/src/android/hardware/camera2/cts"
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -070037outdir="$ANDROID_PRODUCT_OUT/obj/ETC/system-media-camera-docs_intermediates"
Igor Murashkin1232dd22013-06-21 12:10:42 -070038out_files=()
Igor Murashkineaddcd42012-11-26 12:01:11 -080039
Igor Murashkin5804a482012-12-05 13:06:59 -080040function relpath() {
41 python -c "import os.path; print os.path.relpath('$1', '$PWD')"
42}
43
Igor Murashkin1232dd22013-06-21 12:10:42 -070044# Generates a file. Appends to $out_files array as a side effect.
Igor Murashkineaddcd42012-11-26 12:01:11 -080045function gen_file() {
46 local in=$thisdir/$1
47 local out=$thisdir/$2
48
Igor Murashkinaa133d32013-06-28 17:27:49 -070049 gen_file_abs "$in" "$out"
50 return $?
51}
52
53function gen_file_abs() {
54 local in="$1"
55 local out="$2"
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -070056 local intermediates="$3"
Igor Murashkinaa133d32013-06-28 17:27:49 -070057
Igor Murashkin48098682012-12-05 14:51:57 -080058 python $thisdir/metadata_parser_xml.py $thisdir/metadata_properties.xml $in $out
Igor Murashkin5804a482012-12-05 13:06:59 -080059
60 local succ=$?
61
62 if [[ $succ -eq 0 ]]
63 then
64 echo "OK: Generated $(relpath "$out")"
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -070065 if [[ "$intermediates" != "no" ]]; then
66 out_files+=$'\n'" $out"
67 fi
Igor Murashkin5804a482012-12-05 13:06:59 -080068 else
69 echo "FAIL: Errors while generating $(relpath "$out")" >& 2
70 fi
71
72 return $succ
Igor Murashkineaddcd42012-11-26 12:01:11 -080073}
74
Igor Murashkin1232dd22013-06-21 12:10:42 -070075# Print a list of git repository paths which were affected after file generation
76function affected_git_directories() {
77 local input_files=($@)
78 local git_directories=()
79
80 for file in "${input_files[@]}"; do
81 local dir_path="$(dirname "$file")"
82 echo "Trying to cd into $dir_path" >& /dev/null
83 # Absolute path to the git repository root of that file
84 local git_path="$(cd "$dir_path";
85 git rev-parse --show-toplevel 2> /dev/null)"
86 if [[ $? -eq 0 ]]; then
87 # Both staged and unstaged changes
Igor Murashkinb8dc8812013-07-17 16:29:34 -070088 local diff_result="$(cd "$dir_path";
89 git status --porcelain | egrep -c -v '^[?][?]')"
Igor Murashkin1232dd22013-06-21 12:10:42 -070090 echo "Diff result was $diff_result" >& /dev/null
91 echo "Diff result was $diff_result" >& /dev/null
92 if [[ $diff_result -eq 0 ]]; then
Igor Murashkinaa133d32013-06-28 17:27:49 -070093 echo "No changes in ${git_path}" >& /dev/null
Igor Murashkin1232dd22013-06-21 12:10:42 -070094 else
95 echo "There are changes in ${git_path}" >& /dev/null
96 git_directories+=("$git_path")
97 fi
98 fi
99 done
100
101 # print as result the unique list of git directories affected
Igor Murashkinaa133d32013-06-28 17:27:49 -0700102 printf %s\\n "${git_directories[@]}" | sort | uniq
Igor Murashkin1232dd22013-06-21 12:10:42 -0700103}
104
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700105# Insert a file into the middle of another, starting at the line containing the
106# start delim and ending on the end delim, both of which are replaced
107function insert_file() {
108 local src_part="$1"
109 local dst_file="$2"
110 local start_delim="/*@O~"
111 local end_delim="~O@*/"
112
113 local start_line="$(grep -n -F "${start_delim}" "${dst_file}" | cut -d: -f1)"
114 local end_line="$(grep -n -F "${end_delim}" "${dst_file}" | cut -d: -f1)"
115
116 # Adjust cutoff points to use start/end line from inserted file
117 (( start_line-- ))
118 (( end_line++ ))
119
120 # Do some basic sanity checks
121
122 if [[ -z "$start_line" ]]; then
123 echo "No starting delimiter found in ${dst_file}" >& 2
124 echo "FAIL: Errors in inserting into $(relpath ${dst_file})" >& 2
125 return 1
126 fi
127
128 if [[ -z "$end_line" ]]; then
129 echo "No ending delimiter found in ${dst_file}" >& 2
130 echo "FAIL: Errors in inserting into $(relpath ${dst_file})" >& 2
131 return 1
132 fi
133
134 if [[ "$start_line" -ge "$end_line" ]]; then
135 echo "Starting delim later than ending delim: $start_line vs $end_line" >& 2
136 echo "FAIL: Errors in inserting into $(relpath ${dst_file})" >& 2
137 return 1
138 fi
139
140 local tmp_name=$(mktemp -t XXXXXXXX)
141
142 # Compose the three parts of the final file together
143
144 head -n "$start_line" "${dst_file}" > "${tmp_name}"
145 cat "${src_part}" >> "${tmp_name}"
146 tail -n "+${end_line}" "${dst_file}" >> "${tmp_name}"
147
148 # And replace the destination file with the new version
149
150 mv "${tmp_name}" "${dst_file}"
151 echo "OK: Inserted $(relpath "$src_part") into $(relpath "$dst_file")"
152 out_files+=$'\n'" $dst_file"
153}
154
Igor Murashkin0334aa02012-12-04 14:59:53 -0800155$thisdir/metadata-check-dependencies || exit 1
Igor Murashkinc469f7d2013-04-23 14:31:02 -0700156$thisdir/metadata-validate $thisdir/metadata_properties.xml || exit 1
Igor Murashkineaddcd42012-11-26 12:01:11 -0800157$thisdir/metadata-parser-sanity-check || exit 1
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700158
159# Generate HTML properties documentation
Igor Murashkineaddcd42012-11-26 12:01:11 -0800160gen_file html.mako docs.html || exit 1
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700161
162# Generate C API headers and implementation
Igor Murashkineaddcd42012-11-26 12:01:11 -0800163gen_file camera_metadata_tag_info.mako ../src/camera_metadata_tag_info.c || exit 1
164gen_file camera_metadata_tags.mako ../include/system/camera_metadata_tags.h || exit 1
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700165
166# Generate Java API definitions
167mkdir -p "${outdir}"
168gen_file_abs CameraMetadataEnums.mako "$outdir/CameraMetadataEnums.java.part" no || exit 1
Igor Murashkin21d0f1a2013-09-10 12:25:56 -0700169gen_file_abs CameraCharacteristicsKeys.mako "$outdir/CameraCharacteristicsKeys.java.part" no || exit 1
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700170gen_file_abs CaptureRequestKeys.mako "$outdir/CaptureRequestKeys.java.part" no || exit 1
171gen_file_abs CaptureResultKeys.mako "$outdir/CaptureResultKeys.java.part" no || exit 1
172
173insert_file "$outdir/CameraMetadataEnums.java.part" "$fwkdir/CameraMetadata.java" || exit 1
Igor Murashkin21d0f1a2013-09-10 12:25:56 -0700174insert_file "$outdir/CameraCharacteristicsKeys.java.part" "$fwkdir/CameraCharacteristics.java" || exit 1
Eino-Ville Talvalad4e240a2013-08-08 12:56:37 -0700175insert_file "$outdir/CaptureRequestKeys.java.part" "$fwkdir/CaptureRequest.java" || exit 1
176insert_file "$outdir/CaptureResultKeys.java.part" "$fwkdir/CaptureResult.java" || exit 1
177
178# Generate CTS tests
Igor Murashkin21d0f1a2013-09-10 12:25:56 -0700179gen_file_abs CameraCharacteristicsTest.mako "$ctsdir/CameraCharacteristicsTest.java" || exit 1
Igor Murashkineaddcd42012-11-26 12:01:11 -0800180
Igor Murashkin1232dd22013-06-21 12:10:42 -0700181echo ""
182echo "===================================================="
Igor Murashkineaddcd42012-11-26 12:01:11 -0800183echo "Successfully generated all metadata source files"
Igor Murashkin1232dd22013-06-21 12:10:42 -0700184echo "===================================================="
185echo ""
186
187echo "****************************************************"
188echo "The following git repositories need to be committed:"
189echo "****************************************************"
190echo ""
191affected_git_directories "${out_files[@]}"
192echo ""
Igor Murashkineaddcd42012-11-26 12:01:11 -0800193
194exit 0