TARGET_SPEC='targetspec'
LIBFUZZER_PKGS=('libFuzzer' 'fuzz-force-options')
SRCS_DIR="${TIZEN_FUZZ_HOME}/sources"
-GBS_EMULATOR64_CONFIG="${CONFIG_DIR}/gbs_emulator64.conf"
-GBS_EMULATOR32_CONFIG="${CONFIG_DIR}/gbs_emulator32.conf"
-GBS_EMULATOR64_PROFILE="emulator64"
-GBS_EMULATOR32_PROFILE="emulator32"
-GBS_CONFIG="${GBS_EMULATOR64_CONFIG}"
-GBS_PROFILE="${GBS_EMULATOR64_PROFILE}"
EXTRA_GBS_ARGS=('--clean' '--skip-srcrpm' '--clean-repos' '--include-all')
CUSTOM_SPEC=""
ARCH='x86_64'
exit 1
fi
-case ${ARCH} in
- 'x86_64')
- GBS_CONFIG="${GBS_EMULATOR64_CONFIG}"
- GBS_PROFILE="${GBS_EMULATOR64_PROFILE}"
- ;;
- 'i586')
- GBS_CONFIG="${GBS_EMULATOR32_CONFIG}"
- GBS_PROFILE="${GBS_EMULATOR32_PROFILE}"
- ;;
- *)
- echo "Error: Unsupported architecture '${ARCH}'."
- print_help
- exit 1
- ;;
-esac
+GBS_CONFIG=$(get_config_by_arch "${ARCH}")
+GBS_PROFILE=$(get_profile_by_arch "${ARCH}")
+
+if [[ -z ${GBS_CONFIG} || -z ${GBS_PROFILE} ]]; then
+ echo "Error: Unsupported architecture '${ARCH}'."
+ print_help
+ exit 1
+fi
+
if [[ -n ${CUSTOM_SPEC} && ! -f ${CUSTOM_SPEC} ]]; then
echo "Error: ${CUSTOM_SPEC} file was not found."
sdb_shell_verbose ${@} >/dev/null
}
+# Checks the device architecture
+function get_device_arch {
+ declare -A archs=([x86_64]='x86_64' [i686]='i586')
+ echo "${archs[$(sdb_shell_verbose uname -m)]}"
+}
+
+# Gets gbs config file by architecture
+# Args:
+# 1) architecture
+function get_config_by_arch {
+ declare -A configs=([x86_64]="${CONFIG_DIR}/gbs_emulator64.conf"
+ [i586]="${CONFIG_DIR}/gbs_emulator32.conf")
+ echo "${configs[$1]}"
+}
+
+# Gets gbs profile by architecture
+# Args:
+# 1) architecture
+function get_profile_by_arch {
+ declare -A profiles=([x86_64]='emulator64'
+ [i586]='emulator32')
+ echo "${profiles[$1]}"
+}
+
+# Installs specified dependencies on device
+# Args:
+# 1) repository: base or unified
+# 2-..) list of dependencies with prepended arch (e.g. x86_64/cpio)
+function install_deps {
+ local arch
+ local config
+ local url
+
+ arch=$(get_device_arch)
+ config=$(get_config_by_arch "${arch}")
+
+ if [[ -z ${config} ]]; then
+ echo "Error: unsupported architecture '${arch}'."
+ exit 1
+ fi
+
+ if [[ ${1} = "base" || ${1} = "unified" ]]; then
+ url=$(sed -En "s|url=(.*/tizen/${1}/.*)|\1|p" "${config}")
+ else
+ echo "Error: unsupported repository '${1}'"
+ exit 1
+ fi
+
+ shift
+ local tmp_dir=$(mktemp -d '/tmp/XXXX')
+ mkdir -p "${tmp_dir}"
+ pushd "${tmp_dir}"
+ for dependency in "${@}"; do
+ wget -q -nd -r -np -A "${dependency}-[0-9]*.rpm" "${url}"
+ done
+ popd
+
+ echo "Pushing following packages on device:"
+ ls -1A "${tmp_dir}"
+
+ "${SDB_CMD[@]}" push "${tmp_dir}" "/tmp" >/dev/null
+ sdb_shell rpm -ivh "/tmp/*.rpm"
+ sdb_shell rm -f "/tmp/*.rpm"
+
+ rm -rf "${tmp_dir}"
+}
+
+# Checks that all specified dependencies are installed on device and prints missing.
+# Args:
+# 1-..) list of dependencies to check
+function check_deps {
+ local found
+ for dependency in "${@}"; do
+ found=$("${SDB_CMD[@]}" shell rpm -qa '|' grep "${dependency}")
+ if [[ -z ${found} ]]; then
+ echo "${dependency}"
+ fi
+ done
+}
+
+# Checks and installs, if needed, specified dependencies from specified repo.
+# Args:
+# 1) Whether missing dependencies should be installed (1) or not (0).
+# 2) Repo: 'base' or 'unified'.
+# 3-..) List of packages to be installed.
+function check_and_install_deps {
+ local repo
+ local missing
+ local install
+ local deps
+
+ install="${1}"
+ repo="${2}"
+ missing=$(check_deps "${@:3}")
+ if [[ -n ${missing} ]]; then
+ if (( install == 1 )); then
+ deps=(${missing//$'\n'/ })
+ echo "Installing following packages: ${deps[*]}"
+ install_deps "${repo}" "${deps[@]}"
+ else
+ echo "Error: following dependencies are not installed on the device: ${deps[*]}"
+ echo "Use '--instal-deps' option to install them."
+ exit 1
+ fi
+ fi
+}
+
# Exports all current environment
function export_all {
`echo "export" $((set -o posix ; set) | awk -F "=" 'BEGIN{ORS=" "}1 $1~/[a-zA-Z]/ {print $1}')`
export -f remove_element
export -f sdb_shell_verbose
export -f sdb_shell
+ export -f get_device_arch
+ export -f get_config_by_arch
+ export -f get_profile_by_arch
+ export -f install_deps
+ export -f check_deps
+ export -f check_and_install_deps
export -f export_all
}