-
Notifications
You must be signed in to change notification settings - Fork 5
/
vendor_hal_makefile_generator.sh
160 lines (142 loc) · 5.64 KB
/
vendor_hal_makefile_generator.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/bin/bash
# Copyright (c) 2018, The Linux Foundation. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of The Linux Foundation nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE US
# This file is used to generate blueprint/makefiles for the vendor hals
# Sanitize host tools
LS=`which ls`
LS=${LS:-ls}
MV=`which mv`
MV=${MV:-mv}
CAT=`which cat`
CAT=${CAT:-cat}
CUT=`which cut`
CUT=${CUT:-cut}
REV=`which rev`
REV=${REV:-rev}
SED=`which sed`
SED=${SED:-sed}
DIFF=`which diff`
DIFF=${DIFF:-diff}
ECHO=`which echo`
ECHO=${ECHO:-echo}
FIND=`which find`
FIND=${FIND:-find}
GREP=`which grep`
GREP=${GREP:-grep}
SORT=`which sort`
SORT=${SORT:-sort}
TOUCH=`which touch`
TOUCH=${TOUCH:-touch}
function generate_make_files() {
local dir_path="$ANDROID_BUILD_TOP/$1"
pushd $dir_path > /dev/null
# Due to same package name in different folders we need to detect
# opensource case so that it can be handled.
local flag_opensource=false
if ${ECHO} "$dir_path" | ${GREP} "opensource" > /dev/null;then
flag_opensource=true
fi
# Search for all HAL files in given dir.
local halFilePaths=`${ECHO} $(${FIND} -iname "*.hal" | ${SORT})`
#Store package name in below array to create a unique set so that we trigger
#hidl-gen only once for a given package.
package_collection=()
#Iterate over identified .hal Paths
local prev_path=""
for file in $halFilePaths; do
local hal_path=`${ECHO} "$file" | ${REV} | ${CUT} -d"/" -f2- | ${REV}`
if [ -e "$hal_path/Android.bp" ] && [ ! -e "$hal_path/.hidl-autogen" ]; then
if [ ! "$hal_path" = "$prev_path" ]; then
${ECHO} "Skipping hidl-gen on $1/$hal_path as Android.bp is not compile-time generated"
prev_path="$hal_path"
fi
continue;
fi
prev_path="$hal_path"
# Find out package name from HAL file
local hal_package=`${ECHO} $(${CAT} $file | ${GREP} -E -m 1 "^package ") | ${CUT} -d' ' -f2`
# Get rid of extra delimter
hal_package=${hal_package%?}
#Check if we already executed hidl-gen for a given package
if ${ECHO} "${package_collection[@]}" | ${GREP} -w $hal_package > /dev/null; then
continue;
else
package_collection+=($hal_package)
local delimeter=`${ECHO} "$file" | ${CUT} -d'/' -f2`
local root=`${ECHO} "$hal_package" | ${SED} "s/$delimeter/#/g" | ${CUT} -d'#' -f1`
#Identify Package Root
root=${root%?}
#Create root arguments for hidl-command
local root_arguments="-r $root:$1 -r $2"
fi
local hal_path2=$1;
#Handling for opensource HAL to solve package name conflict
if [ "$flag_opensource" = true ]; then
root="$root.$delimeter"
hal_path2="$hal_path2/$delimeter"
fi
local root_arguments="-r $root:$hal_path2 -r $2"
update_check=0
if [ -e "$hal_path/Android.bp" ]; then
${MV} $hal_path/Android.bp $hal_path/.hidl-autogen
update_check=1
fi
${TOUCH} $hal_path/.hidl-autogen
${ECHO} -n "Running hidl-gen on $hal_package: "
hidl-gen -Landroidbp $root_arguments $hal_package;
rc=$?; if [[ $rc != 0 ]]; then return $rc; fi
if [ "$update_check" -eq 1 ]; then
${DIFF} -q $hal_path/Android.bp $hal_path/.hidl-autogen > /dev/null
if [ $? -eq 0 ]; then
${ECHO} "no changes"
${MV} $hal_path/.hidl-autogen $hal_path/Android.bp
else
${ECHO} "updated"
fi
else
${ECHO} "created"
fi
${TOUCH} $hal_path/.hidl-autogen
done
popd > /dev/null
}
function start_script_for_interfaces {
#Find interfaces in workspace
local interfaces=$(${LS} -d ${ANDROID_BUILD_TOP}/vendor/qcom/*/interfaces)
${ECHO} "HIDL interfaces: Scanning for changes..."
for interface in $interfaces; do
#generate interfaces
local relative_interface=${interface#${ANDROID_BUILD_TOP}/}
generate_make_files $relative_interface "android.hidl:system/libhidl/transport"
if [ $? -ne 0 ] ; then
${ECHO} "HIDL interfaces: Update Failed"
return 1;
fi
done
${ECHO} "HIDL interfaces: Update complete."
}
#Start script for interfaces
start_script_for_interfaces