lin
2025-04-25 6a7002bcc41716f11f4ca7eb68ebd06c18fdd5e8
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
#! /bin/bash
# Copyright (c) 2016, Intel Corporation
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. 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.
#
# 3. Neither the name of the copyright holder 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 BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
cd "$ANDROID_BUILD_TOP"
. build/envsetup.sh
cd -
 
set -eo pipefail
 
# INSTRUCTIONS
#
# Prior to running this script you should git-rm the previous content of the
# directory pointed to by the "asio" symbolic link, extract the version you
# want to integrate and finally, make the "asio" symbolic link point to the
# extracted directory. Additionaly, the build environment must be ready; i.e.
# you must have sourced "build/envestup.sh" and lunched any target.
#
# Then, run this script by passing it a list of lunch targets. ASIO will be
# minified based on which files were used when building the Parameter Framework
# on those lunch targets. As results may very among targets, it is advised to
# pass lunch targets of various architectures (ideally, all lunch targets).
 
# USAGE
# See the usage() function below
 
usage () {
    echo "run from the Parameter Framework's git root"
    echo "\tsupport/android/asio/asio_shrinker.sh <lunch target> [more lunch targets]"
    exit 1
}
 
fail () {
    code=$?
    echo "Asio shrinker error: $1"
    exit $code
}
 
list_compiled_files () {
    directory=$1
    output=$2
 
    # list all files used during compilation. Ignore "grep" errors: some .P
    # files may well not contain any "asio" line.
    find "$directory/obj" -name "*.P" | \
        xargs grep --no-filename 'external/parameter-framework/asio' >> "$output" || true
}
 
if [ $# -eq 0 ]; then
    echo "Not enough arguments."
    usage
fi
 
# This script must be run from the Parameter Framework's git root.
cd asio
 
asio_includes=$(mktemp)
find include -type f -name '*.[ih]pp' > "$asio_includes"
 
# unifdef can't parse multi-line macros. Help him out by removing the wrapping
xargs sed -i -e :a -e '/\\$/N' -e 's@\\ *\n@ @' -e ta < "$asio_includes"
 
# apply macro definitions
# "-x 2" means: only exit with a code != 0 if an error happened
# "-m" means: work on multiple files
# -f" means: read define and undef directives from the following file
xargs unifdef -x 2 -m -f ../support/android/asio/asio_defines.txt < "$asio_includes"
rm "$asio_includes"
 
 
# Take a list of lunch targets as argument and run "mma" on all of them.
# Why? because it seems that different target architectures require different
# sets of files
pushd ..
tmpfile=$(mktemp)
for target in "$@"; do
    lunch $target || fail "Failed to lunch $target"
 
    # compile and list the source files that actually have been used
    mma -j$(nproc) || fail "Failed to build $target"
    list_compiled_files "$ANDROID_PRODUCT_OUT" $tmpfile
done
popd
list_compiled_files "$ANDROID_HOST_OUT" $tmpfile
 
# In .P files, a line may contain several entries and may be terminated by " \"
# or " :" or nothing. Let's make sure we have one entry per line.
sed -r -e 's@^ *([^:\\]*)( [:\\])?$@\1@' \
    -e 's@^external/parameter-framework/asio/@@g' \
    -e 's@ @\n@' $tmpfile | \
        sort -u | \
        xargs git add || fail "Failed to git-add some necessary ASIO headers"
rm $tmpfile
 
# Add copyright mentions and readmes
git add COPYING LICENSE_1_0.txt README
# Remove asio.hpp because we override it
git rm -f include/asio.hpp || true # it may already have been removed
 
cat > README.parameter-framework << __EOF__
This version of ASIO has been minified for lower disk footprint for Android
integraton by support/android/asio/asio_shrinker.sh.
 
Although unlikely (thanks to having been tested on all AOSP lunch targets), if
the Parameter Framework fails to compile on your lunch target because of a
missing ASIO header, you may download a vanilla ASIO version from
'http://sourceforge.net/projects/asio/files/asio/1.10.6%20%28Stable%29/' and
run that script anew.
__EOF__
git add README.parameter-framework