]> Cypherpunks.ru repositories - prepro.git/commitdiff
.ziphash
authorSergey Matveev <stargrave@stargrave.org>
Wed, 16 Aug 2023 06:52:40 +0000 (09:52 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Wed, 16 Aug 2023 07:18:05 +0000 (10:18 +0300)
build [new file with mode: 0755]
cmd/zip-create/main.go [moved from main.go with 100% similarity]
cmd/zip-hash/main.go [new file with mode: 0644]
mk-mod

diff --git a/build b/build
new file mode 100755 (executable)
index 0000000..63cf534
--- /dev/null
+++ b/build
@@ -0,0 +1,5 @@
+#!/bin/sh -e
+
+for cmd in zip-create zip-hash ; do
+    go build -C cmd/$cmd -o $PWD/$cmd -ldflags=-s
+done
similarity index 100%
rename from main.go
rename to cmd/zip-create/main.go
diff --git a/cmd/zip-hash/main.go b/cmd/zip-hash/main.go
new file mode 100644 (file)
index 0000000..69c448f
--- /dev/null
@@ -0,0 +1,16 @@
+package main
+
+import (
+       "log"
+       "os"
+
+       "golang.org/x/mod/sumdb/dirhash"
+)
+
+func main() {
+       hsh, err := dirhash.HashZip(os.Args[1], dirhash.DefaultHash)
+       if err != nil {
+               log.Fatal(err)
+       }
+       os.Stdout.WriteString(hsh + "\n")
+}
diff --git a/mk-mod b/mk-mod
index ba138153bdbaf61d4b54e6207c9095e65080b2ce273b7f2574dc0d639ee99c4c..dc83c8bf8be142889436f2375614a4166b0e57c7f491b14a42451060dc882db1 100755 (executable)
--- a/mk-mod
+++ b/mk-mod
@@ -12,7 +12,9 @@ mkdir -p $dst
 cd $dst
 [[ -s $version.zip ]] && exit
 
-prepro=$0:h:a/prepro
+root=$0:h:a
+zipcreate=$root/zip-create
+ziphash=$root/zip-hash
 zmodload -F zsh/datetime b:strftime
 git -C $vcspath cat-file -p $version | while read line ; do
     [[ $line =~ ^object ]] && hsh=${${=line}[-1]}
@@ -25,8 +27,9 @@ done
 [[ -n $sec ]]
 strftime -s when %Y-%m-%dT%H:%M:%SZ $sec
 
-$prepro -vcs $vcspath -mod $modname -version $version > $version.zip
+$zipcreate -vcs $vcspath -mod $modname -version $version > $version.zip
+$ziphash $version.zip > $version.ziphash
 unzip -p $version.zip ${modname}@${version}/go.mod > $version.mod
 printf '{"Version":"%s","Time":"%s","Origin":{"VCS":"git","URL":"%s","Ref":"refs/tags/%s","Hash":"%s"}}' \
     $version $when $vcsurl $version $hsh > $version.info
-touch -d $when $version.info $version.mod $version.zip
+touch -d $when $version.info $version.mod $version.zip $version.ziphash