Skip to content

Instantly share code, notes, and snippets.

@xingrz
Created October 24, 2018 03:08
Show Gist options
  • Save xingrz/848013a9450daf73c288125f315c9a90 to your computer and use it in GitHub Desktop.
Save xingrz/848013a9450daf73c288125f315c9a90 to your computer and use it in GitHub Desktop.
function get_build() {
if [[ "$MK_BUILD" ]]; then
echo $MK_BUILD
elif [[ "$LINEAGE_BUILD" ]]; then
echo $LINEAGE_BUILD
elif [[ "$CM_BUILD" ]]; then
echo $CM_BUILD
fi
}
function get_device() {
find "${ANDROID_BUILD_TOP}/device" -maxdepth 2 -type d -name "${1}"
}
function get_vendor() {
find "${ANDROID_BUILD_TOP}/vendor" -maxdepth 2 -type d -name "${1}"
}
function get_common_device() {
local device=$(get_device "${1}")
local common=$(grep 'BoardConfigCommon.mk' "${device}/BoardConfig.mk" | sed 's|\-include\s*\(.*\)\/BoardConfigCommon\.mk|\1|')
echo "${ANDROID_BUILD_TOP}/${common}"
}
function get_kernel() {
local device=$(get_device "${1}")
local kernel=$(grep 'TARGET_KERNEL_SOURCE' "${device}/BoardConfig.mk" | sed 's|.*\:\=\s*\(.*\)$|\1|')
if [[ "$kernel" ]]; then
echo "${ANDROID_BUILD_TOP}/${kernel}"
return
fi
local common=$(get_common_device "${1}")
local kernel=$(grep 'TARGET_KERNEL_SOURCE' "${common}/BoardConfigCommon.mk" | sed 's|.*\:\=\s*\(.*\)$|\1|')
if [[ "$kernel" ]]; then
echo "${ANDROID_BUILD_TOP}/${kernel}"
return
fi
}
function cdd() {
local build=$(get_build)
if [[ "$build" ]]; then
local device=$(get_device "${build}")
echo $device
cd "$device"
fi
}
function cdcd() {
local build=$(get_build)
if [[ "$build" ]]; then
local device=$(get_common_device "${build}")
echo $device
cd "$device"
fi
}
function cdv() {
local build=$(get_build)
if [[ "$build" ]]; then
local vendor=$(get_vendor "${build}")
echo $vendor
cd "$vendor"
fi
}
function cdk() {
local build=$(get_build)
if [[ "$build" ]]; then
local kernel=$(get_kernel "${build}")
echo $kernel
cd "$kernel"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment