Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add symgen_helper script #36

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

1. Create a copy of any existing config in the `configs` directory with the new version number as the directory name.

2. Manually update `entrypoints.h` and `symgen.yaml` by referring to the official [API docs](https://docs.tizen.org/application/native/api/iot-headed/latest) and the rootstrap.
2. Manually update `entrypoints.h` and `symgen.yaml` by referring to the official [API docs](https://docs.tizen.org/application/native/api/iot-headed/latest) and the rootstrap. (Run `symgen_helper.sh` to find out what to add to `symgen.yaml`. (`scripts/symgen_helper.sh <version>`))

3. Run `ffigen_helper.sh` to generate the contents of the `ffigen.yaml` file.

Expand Down
87 changes: 87 additions & 0 deletions scripts/symgen_helper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/bin/bash
SCRIPT_DIR=$(dirname $(readlink -f $0))
ROOT_DIR=$(readlink -f $SCRIPT_DIR/..)

version=$1
if [ -z "$version" ]; then
echo "$(basename $0) <version>"
exit 1
fi

entrypoints=$ROOT_DIR/configs/$version/entrypoints.h
rootstraps=$ROOT_DIR/rootstraps/$version

show_loading() {
while :; do
for s in '|' '/' '-' '\' '|'; do
printf "\rCollecting symbol information... $s"
sleep 0.2
done
done
}

show_loading &
LOADING_PID=$!

declare -A symbols

while IFS= read -r so_file; do
if file "$so_file" | grep -q 'ELF'; then
while IFS= read -r symbol; do
if [[ -n "$symbol" ]]; then
symbols["$symbol"]+="$so_file "
fi
done < <(nm -gD "$so_file" | awk '{print $3}')
else
echo "Warning: $so_file is not a valid ELF file."
fi
done < <(find "$rootstraps" -type f -name "*.so")

kill $LOADING_PID
wait $LOADING_PID 2>/dev/null

echo -e "\n\n"

declare -a unique_so_file_list

add_symbol_file() {
local value=$1
local exists=0

for item in "${unique_so_file_list[@]}"; do
if [[ "$item" == "$value" ]]; then
exists=1
break
fi
done

if [[ $exists -eq 0 ]]; then
unique_so_file_list+=("$value")
fi
}

file_from_entrypoints=$(grep -oP '#include\s*<\K[^>]*' "$entrypoints")

for header in $file_from_entrypoints; do
header_file=$(find "$rootstraps" -type f -name "$(basename $header)")
if [ ! -f "$header_file" ]; then
continue
fi

functions=$(grep -oP '^\w+\s+\w+\s*\([^)]*\)\s*;' "$header_file" | awk '{print $2}' | sed 's/(.*//')

for symbol in $functions; do
if [[ -n "${symbols[$symbol]}" ]]; then
found_symbol_file=$(basename ${symbols[$symbol]})
echo "$(basename $header_file) / $found_symbol_file"
add_symbol_file $found_symbol_file
break;
fi
done
done

echo "------------------------------------------"

for x in "${unique_so_file_list[@]}"; do
echo "- $x"
done
Loading