| Write the build in babashka, and pin the babashka 34832a8 nandi 18d ago | 1 | #!/bin/sh |
| 2 | #_( |
| 3 | exec "$(dirname "$0")/bb" "$0" "$@" |
| 4 | ) |
| 5 | |
| 6 | ;; The APK, built as a graph. |
| 7 | ;; |
| 8 | ;; apk.bb [build|install|run|log] |
| 9 | ;; |
| 10 | ;; The build itself is android/BUCK; this only asks buck for the file and then |
| 11 | ;; does what was asked with it. android/build-apk.bb is the same APK built step |
| 12 | ;; by step instead, for when the graph is what is being doubted. |
| 13 | (require '[babashka.classpath :as cp]) |
| 14 | (cp/add-classpath (str (babashka.fs/parent *file*))) |
| 15 | (require '[frq.paths :as paths] |
| 16 | '[babashka.fs :as fs] |
| 17 | '[babashka.process :as p] |
| 18 | '[clojure.string :as str]) |
| 19 | |
| 20 | (def root (str (fs/canonicalize (fs/path (fs/parent *file*) "..")))) |
| 21 | (def action (or (first *command-line-args*) "build")) |
| 22 | (def adb (paths/env "ADB" (str (fs/path (fs/home) ".local" "share" "android-sdk" |
| 23 | "platform-tools" "adb")))) |
| 24 | (def package "uk.nandi.frq") |
| 25 | |
| 26 | (defn apk [] |
| 27 | (->> (paths/out (str (fs/path root "scripts" "buck.bb")) |
| 28 | "build" "--show-output" "//:apk") |
| 29 | str/split-lines |
| 30 | (some #(when (str/includes? % "frq.apk") (second (str/split % #"\s+")))) |
| 31 | (str root "/"))) |
| 32 | |
| 33 | (case action |
| 34 | "build" (println (apk)) |
| 35 | "install" (p/shell adb "install" "-r" (apk)) |
| 36 | "run" (let [file (apk)] |
| 37 | (p/shell adb "install" "-r" file) |
| 38 | (p/shell adb "shell" "am" "force-stop" package) |
| 39 | (p/shell adb "shell" "am" "start" "-n" (str package "/.FrqActivity"))) |
| 40 | "log" (p/shell adb "logcat" "-s" "VidyaJolt" "Vidya") |
| 41 | (paths/die "usage: apk.bb [build|install|run|log]")) |