Skip to content

Commit

Permalink
Use variables to allow overriding build tools
Browse files Browse the repository at this point in the history
In particular, this is useful for a situation where we want to use
podman instead of docker, or where adb is not in $PATH.
  • Loading branch information
dylanmccall committed Apr 18, 2022
1 parent 947fa84 commit 150ea59
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
21 changes: 13 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ ANDROIDNDKVER := 21.4.7075529

SDK := ${ANDROID_HOME}/android-sdk-$(PLATFORM)

ADB := adb
DOCKER := docker
P4A := p4a
PYTHON_FOR_ANDROID := python-for-android

# This checks if an environment variable with a specific name
# exists. If it doesn't, it prints an error message and exits.
# For example to check for the presence of the ANDROIDSDK environment
Expand All @@ -41,9 +46,9 @@ clean:
- rm -rf dist/*.apk src/kolibri tmpenv

deepclean: clean
python-for-android clean_dists
$(PYTHON_FOR_ANDROID) clean_dists
rm -r dist || true
yes y | docker system prune -a || true
yes y | $(DOCKER) system prune -a || true
rm build_docker 2> /dev/null

.PHONY: clean-whl
Expand All @@ -68,7 +73,7 @@ src/kolibri: clean

.PHONY: p4a_android_distro
p4a_android_distro: needs-android-dirs
p4a create --arch=$(P4A_ARCH)
$(P4A) create --arch=$(P4A_ARCH)

.PHONY: needs-version
needs-version:
Expand Down Expand Up @@ -103,19 +108,19 @@ kolibri.apk.unsigned: p4a_android_distro src/kolibri needs-version
# Makes dummy file
.PHONY: build_docker
build_docker: Dockerfile
docker build -t android_kolibri .
$(DOCKER) build -t android_kolibri .

# Run the docker image.
# TODO Would be better to just specify the file here?
run_docker: build_docker
./scripts/rundocker.sh
env DOCKER="$(DOCKER)" ./scripts/rundocker.sh

install:
adb uninstall org.learningequality.Kolibri || true 2> /dev/null
adb install dist/*$(ARM_VER)-debug-*.apk
$(ADB) uninstall org.learningequality.Kolibri || true 2> /dev/null
$(ADB) install dist/*$(ARM_VER)-debug-*.apk

logcat:
adb logcat | grep -i -E "python|kolibr| `adb shell ps | grep ' org.learningequality.Kolibri$$' | tr -s [:space:] ' ' | cut -d' ' -f2` " | grep -E -v "WifiTrafficPoller|localhost:5000|NetworkManagementSocketTagger|No jobs to start"
$(ADB) logcat | grep -i -E "python|kolibr| `$(ADB) shell ps | grep ' org.learningequality.Kolibri$$' | tr -s [:space:] ' ' | cut -d' ' -f2` " | grep -E -v "WifiTrafficPoller|localhost:5000|NetworkManagementSocketTagger|No jobs to start"

$(SDK)/cmdline-tools:
@echo "Downloading Android SDK build tools"
Expand Down
11 changes: 6 additions & 5 deletions scripts/rundocker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
set -e

CONTAINER_HOME=/home/kivy
DOCKER=${DOCKER:-"docker"}

# Specifies the name of the docker volume used to store p4a cache
P4A_CACHE=p4a_cached_dir_$ARCH
Expand All @@ -11,7 +12,7 @@ CID_FILE=kolibri-android-app-container-id.cid.txt

# create the container to be used throughout the script
# creates a volume for reuse between builds, holding p4a's android distro
docker create -it \
${DOCKER} create -it \
--mount type=volume,src=${P4A_CACHE},dst=${CONTAINER_HOME}/.local \
--env BUILDKITE_BUILD_NUMBER \
--env P4A_RELEASE_KEYSTORE=${CONTAINER_HOME}/$(basename "${P4A_RELEASE_KEYSTORE}") \
Expand All @@ -35,18 +36,18 @@ if [ "${P4A_RELEASE_KEYSTORE}" ]; then
if [ -a ${P4A_RELEASE_KEYSTORE} ]; then
echo -e "Copying the signing key \n\t From ${P4A_RELEASE_KEYSTORE} to ${CONTAINER_ID}:${CONTAINER_HOME}"
# copy keystore to same location on the container
docker cp ${P4A_RELEASE_KEYSTORE} ${CONTAINER_ID}:${CONTAINER_HOME}
${DOCKER} cp ${P4A_RELEASE_KEYSTORE} ${CONTAINER_ID}:${CONTAINER_HOME}
fi
fi

# run the container, generating the apk
echo "Starting ${CONTAINER_ID}"
docker start -i ${CONTAINER_ID}
${DOCKER} start -i ${CONTAINER_ID}

# copy the apk to our host. Handles permissions.
echo -e "Copying APK \n\t From ${CONTAINER_ID}:${CONTAINER_HOME}/dist/ to ${PWD}"
docker cp ${CONTAINER_ID}:${CONTAINER_HOME}/dist/ .
${DOCKER} cp ${CONTAINER_ID}:${CONTAINER_HOME}/dist/ .

# manually remove the container afterward
echo -n "Removing "
docker rm ${CONTAINER_ID}
${DOCKER} rm ${CONTAINER_ID}

0 comments on commit 150ea59

Please sign in to comment.