Merge "Pass list of module libraries to gen_ndk_backed_by_apex.sh"

This commit is contained in:
Treehugger Robot
2021-02-09 03:21:36 +00:00
committed by Gerrit Code Review
2 changed files with 36 additions and 14 deletions

View File

@@ -700,15 +700,20 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) {
}) })
a.apisUsedByModuleFile = apisUsedbyOutputFile a.apisUsedByModuleFile = apisUsedbyOutputFile
var libNames []string
for _, f := range a.filesInfo {
if f.class == nativeSharedLib {
libNames = append(libNames, f.stem())
}
}
apisBackedbyOutputFile := android.PathForModuleOut(ctx, a.Name()+"_backing.txt") apisBackedbyOutputFile := android.PathForModuleOut(ctx, a.Name()+"_backing.txt")
ndkLibraryList := android.PathForSource(ctx, "system/core/rootdir/etc/public.libraries.android.txt") ndkLibraryList := android.PathForSource(ctx, "system/core/rootdir/etc/public.libraries.android.txt")
rule := android.NewRuleBuilder(pctx, ctx) rule := android.NewRuleBuilder(pctx, ctx)
rule.Command(). rule.Command().
Tool(android.PathForSource(ctx, "build/soong/scripts/gen_ndk_backedby_apex.sh")). Tool(android.PathForSource(ctx, "build/soong/scripts/gen_ndk_backedby_apex.sh")).
Text(imageDir.String()).
Implicits(implicitInputs).
Output(apisBackedbyOutputFile). Output(apisBackedbyOutputFile).
Input(ndkLibraryList) Input(ndkLibraryList).
Flags(libNames)
rule.Build("ndk_backedby_list", "Generate API libraries backed by Apex") rule.Build("ndk_backedby_list", "Generate API libraries backed by Apex")
a.apisBackedByModuleFile = apisBackedbyOutputFile a.apisBackedByModuleFile = apisBackedbyOutputFile

View File

@@ -23,33 +23,50 @@ printHelp() {
echo "**************************** Usage Instructions ****************************" echo "**************************** Usage Instructions ****************************"
echo "This script is used to generate the Mainline modules backed-by NDK symbols." echo "This script is used to generate the Mainline modules backed-by NDK symbols."
echo "" echo ""
echo "To run this script use: ./ndk_backedby_module.sh \$BINARY_IMAGE_DIRECTORY \$OUTPUT_FILE_PATH \$NDK_LIB_NAME_LIST" echo "To run this script use: ./gen_ndk_backed_by_apex.sh \$OUTPUT_FILE_PATH \$NDK_LIB_NAME_LIST \$MODULE_LIB1 \$MODULE_LIB2..."
echo "For example: If all the module image files that you would like to run is under directory '/myModule' and output write to /backedby.txt then the command would be:" echo "For example: If output write to /backedby.txt then the command would be:"
echo "./ndk_usedby_module.sh /myModule /backedby.txt /ndkLibList.txt" echo "./gen_ndk_backed_by_apex.sh /backedby.txt /ndkLibList.txt lib1.so lib2.so"
echo "If the module1 is backing lib1 then the backedby.txt would contains: " echo "If the module1 is backing lib1 then the backedby.txt would contains: "
echo "lib1" echo "lib1"
} }
contains() {
val="$1"
shift
for x in "$@"; do
if [ "$x" = "$val" ]; then
return 0
fi
done
return 1
}
genBackedByList() { genBackedByList() {
dir="$1" out="$1"
[[ ! -e "$2" ]] && echo "" >> "$2" shift
ndk_list="$1"
shift
rm -f "$out"
touch "$out"
while IFS= read -r line while IFS= read -r line
do do
soFileName=$(echo "$line" | sed 's/\(.*so\).*/\1/') soFileName=$(echo "$line" | sed 's/\(.*so\).*/\1/')
if [[ ! -z "$soFileName" && "$soFileName" != *"#"* ]] if [[ ! -z "$soFileName" && "$soFileName" != *"#"* ]]
then then
find "$dir" -type f -name "$soFileName" -exec echo "$soFileName" >> "$2" \; if contains "$soFileName" "$@"; then
echo "$soFileName" >> "$out"
fi fi
done < "$3" fi
done < "$ndk_list"
} }
if [[ "$1" == "help" ]] if [[ "$1" == "help" ]]
then then
printHelp printHelp
elif [[ "$#" -ne 3 ]] elif [[ "$#" -lt 2 ]]
then then
echo "Wrong argument length. Expecting 3 argument representing image file directory, output path, path to ndk library list." echo "Wrong argument length. Expecting at least 2 argument representing output path, path to ndk library list, followed by a list of libraries in the Mainline module."
else else
[[ -e "$2" ]] && rm "$2" genBackedByList "$@"
genBackedByList "$1" "$2" "$3"
fi fi