commit d98c8d83ba3da17fcc854b9d3d49d9f31b2ec612
parent 8ae98e8495ba3fe156074df98f43a7510ec7b75b
Author: Szymon Mikulicz <szymon.mikulicz@posteo.net>
Date: Tue, 24 Feb 2026 19:14:38 +0100
Some more work on this
Diffstat:
| M | instowl | | | 39 | +++++++++++++++++++++++++++++++++++---- |
| M | instowl.janet | | | 70 | +++++++++++++++++++++++++++++++++++++++++++++++++++------------------- |
2 files changed, 86 insertions(+), 23 deletions(-)
diff --git a/instowl b/instowl
@@ -11,6 +11,8 @@ install_state="make_install"
main() {
local dir="$HOME/.local"
+ local target="$dir"
+ local stowdir="$dir/pkg"
local pkg="${pkg:-$(basename "$PWD")}"
local prefix=""
local pkgdir="$dir/pkg/$pkg"
@@ -35,6 +37,10 @@ main() {
state="cargo"
elif [ -f Build.PL ]; then
state="perl"
+ elif [ -f go.mod ]; then
+ state="go"
+ elif [ -f requirements.txt ]; then
+ state="python"
fi
;;
autogen)
@@ -80,13 +86,29 @@ main() {
install_state="perl_install"
state="pre_install"
;;
+ go)
+ go build || return 2
+ install_state="go_install"
+ state="pre_install"
+ ;;
perl_install)
./Build install --install_base "$prefix" --destdir "$destdir" || return 3
state="post_install"
;;
+ python)
+ prefix="$dir"
+ python3 -m build --wheel --no-isolation
+ install_state="python_install"
+ state="pre_install"
+ ;;
post_install)
if [ -n "$prefix" ]; then
- find "$destdir$prefix" \( -type f -o -type l \) -printf "%P\n" | xargs -I{} install -Dpv "$destdir$prefix/{}" "$pkgdir/{}"
+ [ -d "$destdir$prefix" ] || {
+ echo "Didn't find the right prefix"
+ find "$destdir"
+ exit 1
+ }
+ find "$destdir$prefix$postfix" \( -type f -o -type l \) -printf "%P\n" | xargs -I{} install -Dpv "$destdir$prefix$postfix/{}" "$pkgdir/{}"
fi
state="stow"
;;
@@ -95,11 +117,20 @@ main() {
state="pre_install"
;;
cargo_install)
- cargo install --force --no-track --root "$pkgdir" --path . || return 3
+ cargo install --force --locked --no-track --root "$pkgdir" --path . || return 3
+ state="post_install"
+ ;;
+ python_install)
+ python3 -m installer --destdir="$destdir" --prefix="$prefix" dist/*.whl
+ postfix="/local"
+ state="post_install"
+ ;;
+ go_install)
+ GOPATH="$pkgdir" go install
state="post_install"
;;
stow)
- stow -vv -d "$dir/pkg" "$pkg"
+ stow -vv -d "$stowdir" -t "$target" "$pkg"
state="exit"
;;
esac
@@ -120,7 +151,7 @@ printer() {
state="$(awk '{print $2}' <<< "$line")"
else
pretext="\33[2K\r[$chr] [$state] "
- printf "$pretext%s" "$(cut -c -"$(( $(tput cols) - $(wc -c <<< "$pretext") - 1 ))" <<< "$line")"
+ printf "$pretext%s" "$(cut -c -"$(( $(tput cols) - $(wc -c <<< "$pretext") - 3 ))" <<< "$line")"
fi
echo "$line" >> instowl.log
done
diff --git a/instowl.janet b/instowl.janet
@@ -1,39 +1,71 @@
#!/usr/bin/env janet
+(import jpm/shutil)
+
+(ffi/context nil)
+(ffi/defbind mkdtemp :ptr [template :ptr])
+(ffi/defbind get_nprocs :int [])
+
(def spinner "⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏")
+(var ch (string/slice spinner 0 3))
(defn rotate
[ch]
(def nxt (+ 3 (string/find ch spinner)))
(if (= nxt (length spinner)) (string/slice spinner 0 3) (string/slice spinner nxt (+ nxt 3))))
+(defn file-exists? [path]
+ (not (nil? (os/stat path))))
+
+(defn prinfer [state pipe]
+ (do
+ (def buf @"")
+ (while (ev/read pipe 1024 buf)
+ (def lines (string/split "\n" buf))
+ (def len (length lines))
+ (if (> len 1)
+ (loop [[idx line] :pairs lines]
+ (if (< idx (- len 1))
+ (do
+ (prinf "\x1b[2K{%s}⸉%s⸊→%s\r" state ch (string/slice line 0 (min 80 (length line))))
+ (flush))
+ (do (buffer/clear buf) (buffer/push-string buf line))))))))
+
(defn runp
- [& args]
- (def proc (os/spawn args : {:out :pipe}))
- (var ch (string/slice spinner 0 3))
+ [state & args]
+ (def proc (os/spawn args : {:out :pipe :err :pipe}))
(ev/gather
- (do
- (def buf @"")
- (while (ev/read (proc :out) 1024 buf)
- (def lines (string/split "\n" buf))
- (def len (length lines))
- (if (> len 1)
- (loop [[idx line] :pairs lines]
- (if (< idx (- len 1))
- (do
- (prinf "\x1b[2K\r⸉%s⸊→%s" ch line)
- (flush))
- (do (buffer/clear buf) (buffer/push-string buf line)))))))
+ (prinfer state (proc :out))
+ (prinfer state (proc :err))
(os/proc-wait proc)
- (while (= (get proc :return-code) nil) (ev/sleep 0.1) (set ch (rotate ch))))
+ (while (= (get proc :return-code) nil) (ev/sleep 0.2) (do
+ (set ch (rotate ch))
+ (prinf "{%s}⸉%s⸊\r" state ch)
+ (flush))))
(def code (get proc :return-code))
(os/proc-close proc)
code)
(defn main
[& args]
- (if (= (runp "./configure") 0)
- (printf "\x1b[2K\r⸉x⸊→Done")
- (printf "\x1b[2K\r⸉!⸊→Error")))
+ (do
+ (def target (string/join [(os/getenv "HOME") "/.local"]))
+ (def stowdir (string/join [target "/pkg"]))
+ (def pkg (shutil/basename (os/getenv "PWD")))
+ (def pkgdir (string/join [stowdir pkg]))
+ (def destdir @"/tmp/instowl.XXXXXX")
+ (var prefix target)
+ (var state :init)
+ (while (not= state :exit)
+ (case state
+ :init (if (file-exists? "configure.ac") (set state :conf/autotools) (set state :conf/configure))
+ :conf/autotools (if (= (runp state "/usr/bin/autoreconf" "-vi") 0) (set state :conf/configure) (set state :error))
+ :conf/configure (if (= (runp state "./configure" "--prefix" prefix) 0) (set state :build/make) (set state :error))
+ :build/make (if (= (runp state "/usr/bin/make") 0) (set state :install/pre) (set state :error))
+ :install/pre (do (shutil/create-dirs pkgdir) (mkdtemp destdir) (set state :install/make))
+ :install/make (if (= (runp state "/usr/bin/make" "install" (string/format "-j%d" (get_nprocs)) (string/join ["DESTDIR=" destdir])) 0) (set state :install/post))
+ :install/post (set state :done)
+ :error (do (printf "\x1b[2K⸉!⸊→Error") (set state :exit))
+ :done (do (printf "\x1b[2K⸉x⸊→Done") (set state :exit))))))