git » autoupdaters.git » commit db0c729

rust joins the auto-updating crowd

author Urja (ARMLFS builder)
2025-12-13 01:50:48 UTC
committer Urja (ARMLFS builder)
2025-12-13 01:50:48 UTC
parent a788d4f5d7c9afa47080a23f98e1ddab4f9dfb68

rust joins the auto-updating crowd

(... I'm tired of building 5 versions of rust in order when i find out
... that it's again too old for something or other...)

autoupdater_helpers/__init__.py +71 -0
crontab.txt +1 -0
rust.py +22 -0

diff --git a/autoupdater_helpers/__init__.py b/autoupdater_helpers/__init__.py
index 7663dd4..a132737 100644
--- a/autoupdater_helpers/__init__.py
+++ b/autoupdater_helpers/__init__.py
@@ -126,3 +126,74 @@ def get_arch_pkgbuild_ver_sum(pkg):
         cmd = ["git", "clone", "--depth=1", url, dir ]
         run(cmd, check=True)
         return parse_pkgbuild_ver_sum(dir + '/PKGBUILD')
+
+def _months_ago(n):
+    from datetime import date, timedelta
+    # This allows float "months" <3
+    d = date.today() - timedelta(days=int(n*30))
+    return d.isoformat()
+
+
+def arch_arm_pkgbuild_update(pkg,aarepo="extra"):
+    """Update our PKGBUILD (and accompanying files) based on Arch-ARM PKGBUILDs repo"""
+    from tempfile import TemporaryDirectory
+    from subprocess import run, PIPE, STDOUT
+    from os import path, getcwd, chdir, mkdir
+    url = "https://github.com/archlinuxarm/PKGBUILDs"
+    ourdir = f"/sources/base-pkgbuilds/{pkg}"
+    upcommits = ourdir + "/autoupdate-commits"
+    upcommit_fn = ourdir + "/.upstream_commit"
+    if path.exists(upcommits):
+        return "Previous update unfinished"
+    cwd = getcwd()
+    with TemporaryDirectory(prefix=f"tmp-{pkg}-") as dir:
+        cmd = ["git", "clone", f"--shallow-since={_months_ago(3)}", url, dir ]
+        run(cmd, check=True)
+        chdir(dir)
+        path = f"{aarepo}/{pkg}"
+        with open(upcommit_fn) as f:
+            upstream_commit = f.read().strip()
+
+        cmd2 = [ "git", "rev-list", f"^{upstream_commit}", "HEAD", "--", path ]
+        revlistp = run(cmd2, text=True, stdout=PIPE, stderr=STDOUT, check=True)
+        rl = []
+        for rev in revlistp.stdout.splitlines():
+            r = rev.strip()
+            if len(r):
+                rl.append(r)
+        if len(rl) < 1:
+            chdir(cwd)
+            return "No update necessary"
+        mkdir(upcommits)
+        commits = []
+        # We're recording what we're about to try and apply, to help with manual recovery
+        # when a patch inevitably fails :P
+        with open(upcommits + "/order", 'w') as orderf:
+            for index, rev in enumerate(reversed(rl),start=1):
+                # Changes to .SRCINFO are 1) pointless and 2) ofter fail -> filter them out
+                exclude_srcinfo = f":(exclude){path}/.SRCINFO"
+                cmd3 = [ "git", "format-patch", "--start-number", str(index), "-o", upcommits, "-1", rev, '--', path, exclude_srcinfo ]
+                patchp = run(cmd3, text=True, stdout=PIPE, stderr=STDOUT, check=True)
+                patchfn = patchp.stdout.strip()
+                t = f"{rev} {patchfn}\n"
+                orderf.write(t)
+                commits.append((rev,patchfn))
+        chdir(ourdir)
+    # Recording of the changes is complete, get rid of the repo (thus exit the with block ^^)
+    for rev, patchfn in commits:
+        cmd = [ "patch", "-Np3" ]
+        with open(patchfn) as patchf:
+            print(f"Applying {patchfn}...")
+            pp = run(cmd, stdin=patchf)
+        if pp.returncode:
+            msg = f"Applying patch {patchfn} failed"
+            _log(pkg + ": " + msg)
+            return msg
+        with open(upcommit_fn, 'w') as f:
+            f.write(rev)
+    print("Patches applied succesfully")
+    # Patches applied succesfully, get rid of the patch dir
+    run(["rm", "-r", upcommits])
+    # None as in No problems, go ahead and build the new version
+    chdir(cwd)
+    return None
diff --git a/crontab.txt b/crontab.txt
index 29a40c5..162a9d6 100644
--- a/crontab.txt
+++ b/crontab.txt
@@ -4,3 +4,4 @@
 44   5  8 *      * cd /sources/autoupdaters && ./updater-cron.sh firefox
  7   0  * *      5 cd /sources/autoupdaters && ./updater-cron.sh yt-dlp
 42  23  * *      5 cd /sources/autoupdaters && ./updater-cron.sh mesa
+27   6 20 *      * cd /sources/autoupdaters && ./updater-cron.sh rust
diff --git a/rust.py b/rust.py
new file mode 100755
index 0000000..88269fa
--- /dev/null
+++ b/rust.py
@@ -0,0 +1,22 @@
+#!/usr/bin/env python3
+
+import os
+import sys
+from autoupdater_helpers import *
+
+os.chdir("/sources/base-pkgbuilds/rust")
+prev_ver = pkgbuild_ver()
+result = arch_arm_pkgbuild_update("rust")
+
+if result:
+    print(result)
+    sys.exit(0)
+
+ver = pkgbuild_ver()
+
+os.chdir("..")
+
+print(f"Updating {prev_ver} to {ver}")
+mpkg("rust", ver, carch="aarch64")
+mpkg("rust", ver)
+