nandi/frqpublic Fork 0
234c54f1c44e80e5ffe4ddfb2e600d19b417fd80
Commits
Clone
git clone https://git.rickub.com/nandi/frq.git
git clone ssh://git@rickub.com/nandi/frq.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

bump-jolt-native.bb · 130 lines · 6.1 KBBlitzBasic Blame HistoryRaw
Take every jolt-native half from the release, and only from there a008d3b nandi 18d ago1#!/bin/sh
2#_(
3exec "$(dirname "$0")/bb" "$0" "$@"
4)
5
6;; Move every jolt-native pin in this tree to a release of it.
7;;
8;; scripts/bump-jolt-native.bb # the latest release
9;; scripts/bump-jolt-native.bb v0.1.3 # a named one
10;;
Build the desktop libraries rather than fetching a release of them 0b81161 nandi 15d ago11;; A jolt-native bump is three facts in two places: the URL and the digest of
12;; each Android archive in nix/android.nix, and the release's commit in
Build the APK as derivations only, and retire the buck2 graph 3bc3aaa nandi 16d ago13;; deps.edn. Done by hand it is a lot of copying between a browser and a
14;; sha256sum, and the failure mode is a pin that still says v0.1.2 while its
Build the desktop libraries rather than fetching a release of them 0b81161 nandi 15d ago15;; digest is v0.1.3's — which fetchurl catches at build time and no sooner.
Build the APK as derivations only, and retire the buck2 graph 3bc3aaa nandi 16d ago16;;
Build the desktop libraries rather than fetching a release of them 0b81161 nandi 15d ago17;; Only the APK fetches a release now; a desktop run builds jolt-native out of
18;; the flake input, whose rev is flake.lock's. So the two halves this moves are
19;; the phone's bytes and the Jolt source that binds them, and the thing to
20;; remember is that flake.lock is a third pin nothing here touches — see the
21;; jolt-native input's comment in flake.nix for why it runs ahead.
Take every jolt-native half from the release, and only from there a008d3b nandi 18d ago22;;
23;; So: ask GitLab what the release holds, fetch each archive once, weigh it,
Build the desktop libraries rather than fetching a release of them 0b81161 nandi 15d ago24;; write nix/android.nix back, and put the release's commit in deps.edn — which
25;; is what jolt resolves glimmer-vidya from, and so what the boot image
26;; compiles against.
Take every jolt-native half from the release, and only from there a008d3b nandi 18d ago27;;
28;; Nothing here decides whether the new release is a good idea. It only makes
29;; the tree say one version instead of two.
30(require '[babashka.classpath :as cp])
31(cp/add-classpath (str (babashka.fs/parent *file*)))
32(require '[frq.paths :as paths]
33 '[babashka.fs :as fs]
34 '[babashka.process :as p]
35 '[cheshire.core :as json]
36 '[clojure.string :as str])
37
Build the desktop libraries rather than fetching a release of them 0b81161 nandi 15d ago38(def root (str (fs/parent (fs/parent (fs/canonicalize *file*)))))
Take every jolt-native half from the release, and only from there a008d3b nandi 18d ago39(def project "nandithebull%2Fjolt-native")
40(def repo "https://gitlab.com/nandithebull/jolt-native")
41
42;; The release, as GitLab has it. `?per_page=1` when no tag is asked for: the
43;; list is newest first, and the newest is what "latest" means here — the
44;; /releases/permalink/latest endpoint sorts by release date, which is not the
45;; same thing once a release is edited.
46(defn release [tag]
47 (let [url (if tag
48 (str "https://gitlab.com/api/v4/projects/" project "/releases/" tag)
49 (str "https://gitlab.com/api/v4/projects/" project "/releases?per_page=1"))
50 body (json/parse-string (paths/out "curl" "-fsSL" url))]
51 (if tag
52 body
53 (or (first body) (paths/die (str "no releases at all under " repo))))))
54
Build the desktop libraries rather than fetching a release of them 0b81161 nandi 15d ago55;; The archive an entry names, at the new tag. The URL a pin carries is the
Take every jolt-native half from the release, and only from there a008d3b nandi 18d ago56;; release permalink — /-/releases/<tag>/downloads/<asset> — so the asset's name
57;; is its last segment, and the name carries the version too. Both move.
58(defn retag [url old new]
59 (-> url
60 (str/replace (str "/releases/" old "/") (str "/releases/" new "/"))
61 (str/replace (str "-" old ".") (str "-" new "."))))
62
63(defn tag-of [url]
64 (second (re-find #"/-/releases/([^/]+)/downloads/" url)))
65
Build the desktop libraries rather than fetching a release of them 0b81161 nandi 15d ago66;; Fetch once per distinct URL, then weigh it: the digest is over the archive as
67;; downloaded, which is what fetchurl hashes too — not of anything inside it.
Take every jolt-native half from the release, and only from there a008d3b nandi 18d ago68(def weigh
69 (memoize
70 (fn [dir url]
71 (let [file (fs/path dir (last (str/split url #"/")))]
72 (println (str " fetching " (fs/file-name file)))
73 (p/shell "curl" "-fsSL" "-o" (str file) url)
Build the desktop libraries rather than fetching a release of them 0b81161 nandi 15d ago74 (first (str/split (paths/out "sha256sum" (str file)) #"\s+"))))))
Take every jolt-native half from the release, and only from there a008d3b nandi 18d ago75
Build the desktop libraries rather than fetching a release of them 0b81161 nandi 15d ago76;; nix/android.nix fetches the release archives as `pkgs.fetchurl`, which is the
77;; only fetch of a release left in this tree. Rewritten as text for the same
78;; reason deps.edn is — the file is mostly the comments explaining each step,
79;; and there is no round-tripping Nix as data here anyway.
Build the APK as derivations only, and retire the buck2 graph 3bc3aaa nandi 16d ago80;;
81;; Every fetchurl whose url points at the repo, whatever it is called: a third
82;; archive appearing in android.nix should move with the other two rather than
83;; be remembered about.
84(defn bump-nix! [tmp tag]
85 (let [file (fs/path root "nix" "android.nix")
86 text (slurp (str file))
87 ;; url and sha256 as one match, so the pair moves together. Anything
88 ;; between them — a comment, another attribute — would not match, and
89 ;; not matching is the safe direction: it leaves the pin alone and says
90 ;; nothing was written.
91 pattern (re-pattern (str "(url\\s*=\\s*\")(" (java.util.regex.Pattern/quote repo)
92 "[^\"]*)(\";\\s*\n\\s*sha256\\s*=\\s*\")([^\"]*)(\")"))
93 seen (atom [])
94 updated (str/replace text pattern
95 (fn [[_ head url mid _ tail]]
96 (let [new-url (retag url (tag-of url) tag)
Build the desktop libraries rather than fetching a release of them 0b81161 nandi 15d ago97 digest (weigh tmp new-url)]
Build the APK as derivations only, and retire the buck2 graph 3bc3aaa nandi 16d ago98 (swap! seen conj (last (str/split new-url #"/")))
99 (str head new-url mid digest tail))))]
100 (when (empty? @seen)
101 (paths/die (str "no fetchurl in " file " points at " repo)))
102 (spit (str file) updated)
103 (doseq [name @seen] (println (str " nix/android.nix " name)))))
104
Take every jolt-native half from the release, and only from there a008d3b nandi 18d ago105;; deps.edn takes glimmer-vidya as a git dependency, and the boot image is
106;; compiled from the source root jolt resolves that to. Replaced as text rather
107;; than round-tripped as EDN: the file is mostly comments explaining why each
108;; pin is where it is, and rewriting it as data would throw all of them away.
109(defn bump-deps! [commit]
110 (let [file (fs/path root "deps.edn")
111 text (slurp (str file))
112 old (paths/dep-sha root repo)]
113 (cond
114 (nil? old) (paths/die (str "no dependency on " repo " in deps.edn"))
115 (= old commit) (println " deps.edn already at this commit")
116 :else (do (spit (str file) (str/replace text old commit))
117 (println (str " deps.edn " (subs old 0 8) " -> " (subs commit 0 8)))))))
118
119(let [tag (first *command-line-args*)
120 rel (release tag)
121 tag (get rel "tag_name")
122 commit (get-in rel ["commit" "id"])
123 tmp (fs/create-temp-dir {:prefix "jolt-native-"})]
124 (println (str "jolt-native " tag " (" (subs commit 0 8) ")"))
125 (try
Build the desktop libraries rather than fetching a release of them 0b81161 nandi 15d ago126 (bump-nix! tmp tag)
Take every jolt-native half from the release, and only from there a008d3b nandi 18d ago127 (finally (fs/delete-tree tmp)))
128 (bump-deps! commit)
Build the desktop libraries rather than fetching a release of them 0b81161 nandi 15d ago129 (println (str "\nNow: git diff, then `just apk` — the pins are "
Take every jolt-native half from the release, and only from there a008d3b nandi 18d ago130 "written, nothing is built.")))