Skip to content

Commit

Permalink
feat(spec): impl ARCH, impl CHKUPDATE
Browse files Browse the repository at this point in the history
Signed-off-by: Kaiyang Wu <[email protected]>
  • Loading branch information
OriginCode committed Jan 6, 2025
1 parent fe5a5ea commit 56c4e03
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 13 deletions.
39 changes: 38 additions & 1 deletion aosc-test/spec-test.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,21 @@
"SRCS=\"tbl::rename=racket::https://download.racket-lang.org/releases/8.15/installers/racket-8.15-src.tgz git::copy-repo=true;rename=nvidia;commit=tags/v0.0.1;submodule=recursive::https://github.com/NVIDIA/nvidia-settings\""
"SRCS ->string")

(check-equal?
(srcs->string
(list
(tbl
"https://download.racket-lang.org/releases/8.15/installers/racket-8.15-src.tgz"
#:options (list (rename "racket")))
(git "https://github.com/NVIDIA/nvidia-settings"
#:options (list (copy-repo? #t)
(rename "nvidia")
(commit (string-append "tags/v" "0.0.1"))
(submodule 'recursive))))
'amd64)
"SRCS__AMD64=\"tbl::rename=racket::https://download.racket-lang.org/releases/8.15/installers/racket-8.15-src.tgz git::copy-repo=true;rename=nvidia;commit=tags/v0.0.1;submodule=recursive::https://github.com/NVIDIA/nvidia-settings\""
"SRCS ->string with ARCH")

(test-suite "CHKSUMS tests"
(check-equal?
(chksums->string
Expand All @@ -131,4 +146,26 @@
'sha256
"4ccdbbd95d4aef058502c8ee07b1abb490f5ef4a4d6ff711440facd0b8eded33")))
"CHKSUMS=\"SKIP sha256::4ccdbbd95d4aef058502c8ee07b1abb490f5ef4a4d6ff711440facd0b8eded33\""
"CHKSUMS ->string"))))
"CHKSUMS ->string")

(check-equal?
(chksums->string
(list
(skip)
(checksum
'sha256
"4ccdbbd95d4aef058502c8ee07b1abb490f5ef4a4d6ff711440facd0b8eded33"))
'amd64)
"CHKSUMS__AMD64=\"SKIP sha256::4ccdbbd95d4aef058502c8ee07b1abb490f5ef4a4d6ff711440facd0b8eded33\""
"CHKSUMS ->string with ARCH"))

(test-suite "CHKUPDATE tests"
(check-equal?
(chkupdate->string
(gitlab "OriginCode/aosc-racket"
"https://factoria.origincode.me"
"\\d+\\.\\d+\\.\\d+"
#t))
"CHKUPDATE=gitlab::repo=OriginCode/aosc-racket;instance=https://factoria.origincode.me;pattern=\\d+\\.\\d+\\.\\d+;sort_version=true"
"CHKUPDATE ->string GitLab"))
))
109 changes: 97 additions & 12 deletions aosc/private/spec.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@
(-> boolean? symbol?)
(if b 'true 'false))

(define/contract (spec-entries->string
entry-name entries entry->string [arch 'any])
(->* (string? (listof any/c) (-> any/c string?))
(symbol?)
string?)
(string-append entry-name
(if (equal? arch 'any)
""
(string-append "__" (string-upcase (symbol->string arch))))
"=\""
(string-join (map entry->string entries))
"\""))

;; SRCS options
;;==============
(struct src-option (field value) #:transparent)
Expand Down Expand Up @@ -73,10 +86,9 @@
,(src-value src))
"::"))

;; TODO: __$ARCH support
(define/contract (srcs->string srcs)
(-> (listof src?) string?)
(string-append "SRCS=\"" (string-join (map src->string srcs)) "\""))
(define/contract (srcs->string srcs [arch 'any])
(->* ((listof src?)) (symbol?) string?)
(spec-entries->string "SRCS" srcs src->string arch))

;; CHKSUMS= field
;;================
Expand All @@ -96,24 +108,97 @@
"SKIP"
(format "~a::~a" (chksum-type chksum) (chksum-value chksum))))

;; TODO: __$ARCH support
(define/contract (chksums->string chksums)
(-> (listof chksum?) string?)
(string-append "CHKSUMS=\"" (string-join (map chksum->string chksums)) "\""))
(define/contract (chksums->string chksums [arch 'any])
(->* ((listof chksum?)) (symbol?) string?)
(spec-entries->string "CHKSUMS" chksums chksum->string arch))

;; TODO: CHKUPDATE= field
;; CHKUPDATE= field (https://wiki.aosc.io/developer/packaging/aosc-findupdate/)
;;==================
(struct chkupdate (type value) #:transparent)

(define/contract (anitya id)
(-> exact-nonnegative-integer? chkupdate?)
(chkupdate 'anitya (format "id=~a" id)))

(define/contract (github repo [pattern #f] [sort-version #f])
(->* (string?)
((or/c boolean? string?)
boolean?)
chkupdate?)
(chkupdate 'github
(string-append
(string-append "repo="repo)
(if pattern
(string-append ";pattern=" pattern)
"")
(if sort-version
(string-append ";sort_version=" (symbol->string (boolean->symbol
sort-version)))
""))))

(define/contract (gitlab repo [instance #f] [pattern #f] [sort-version #f])
(->* (string?)
((or/c boolean? string?)
(or/c boolean? string?)
boolean?)
chkupdate?)
(chkupdate 'gitlab
(string-append
(string-append "repo="repo)
(if instance
(string-append ";instance=" instance)
"")
(if pattern
(string-append ";pattern=" pattern)
"")
(if sort-version
(string-append ";sort_version=" (symbol->string (boolean->symbol
sort-version)))
""))))

(define/contract (gitweb url [pattern #f])
(->* (string?)
((or/c boolean? string?))
chkupdate?)
(chkupdate 'gitweb
(string-append
(string-append "url=" url)
(if pattern
(string-append ";pattern=" pattern)
"")
)))

(define/contract (git-generic url [pattern #f])
(->* (string?)
((or/c boolean? string?))
chkupdate?)
(chkupdate 'git
(string-append
(string-append "url=" url)
(if pattern
(string-append ";pattern=" pattern)
"")
)))

(define/contract (html url pattern)
(-> string? string?
chkupdate?)
(chkupdate 'gitweb
(string-append
"url=" url
";pattern=" pattern)))

(define/contract (chkupdate->string chkupdate)
(-> chkupdate? string?)
(string-append "CHKUPDATE="
(symbol->string (chkupdate-type chkupdate))
"::"
(chkupdate-value chkupdate)))

;; Whole `spec` file struct
(struct spec-type (ver rel srcs chksums chkupdate dummysrc?) #:transparent)

;; `spec` constructor
;; TODO: __$ARCH support, probably (or/c (hash/c symbol? (listof obj?)) (listof obj?))
(define/contract (spec #:ver ver
#:rel [rel #f]
#:srcs [srcs null]
Expand All @@ -123,9 +208,9 @@
#:dummysrc? [dummysrc? #f])
(->* (#:ver string?)
(#:rel exact-nonnegative-integer?
#:srcs (listof src?)
#:srcs (or/c (hash/c symbol? (listof src?)) (listof src?))
#:subdir string?
#:chksums (listof chksum?)
#:chksums (or/c (hash/c symbol? (listof chksum?)) (listof chksum?))
#:chkupdate chkupdate?
#:dummysrc? boolean?)
spec-type?)
Expand Down

0 comments on commit 56c4e03

Please sign in to comment.