Generate basic actor file

This commit is contained in:
xenia 2020-05-01 19:43:37 -04:00
parent 3137913552
commit 438b14d76f
2 changed files with 88 additions and 7 deletions

View File

@ -2,8 +2,15 @@
;; compiler
(provide (struct-out rule)
generate-operations
execute-rule)
;; A compiler rule
;; Input files, output file, compile function
(struct rule [inputs output compiler] #:transparent)
;; Converts set of rules into ordered list of rules to execute based on current filesystem state
(define (generate-operations rules)
(define nodes (mutable-set))
(define edges (make-hash))
@ -92,10 +99,19 @@
(error "self-check failed lmao"))
dirty-sorted)
(define compiler-rules
(set
(rule '("test.o") "my_binary" void)
(rule '("test.c") "test.o" void)))
(generate-operations compiler-rules)
;; Executes one rule
(define (execute-rule r)
(match-define (rule in out func) r)
(define cust (make-custodian))
(parameterize ([current-custodian cust])
(thread-wait
(thread
(lambda ()
(call-with-atomic-output-file
out
(lambda (out-port tmp-path)
(func
(for/hash ([fn (in-list in)])
(values fn (open-input-file fn)))
out-port)))))))
(custodian-shutdown-all cust))

65
private/rules.rkt Normal file
View File

@ -0,0 +1,65 @@
#lang racket
;; static generation rules
(require json
"compile.rkt")
(define ACTOR-CONTEXT
(list "https://www.w3.org/ns/activitystreams"
"https://w3id.org/security/v1"
(hash 'manuallyApprovesFollowers "as:manuallyApprovesFollowers"
'sensitive "as:sensitive"
'movedTo "as:movedTo"
'Hashtag "as:Hashtag"
'toot "http://joinmastodon.org/ns#"
'Emoji "toot:Emoji"
'focalPoint (hash '@container "@list"
'@id "toot:focalPoint")
'featured "toot:featured")))
(define compile-index-json
(rule '("db/actorkey.pub") "public/index.json"
(lambda (in out)
(define key (port->string (hash-ref in "db/actorkey.pub")))
(define actor (hash
'@context ACTOR-CONTEXT
'Type "Person"
'id "https://example.tld/"
'name "haskal"
'preferredUsername "haskal"
'icon (hash 'type "Image"
'url "something"
'sensitive #f)
'image (hash 'type "Image"
'url "something"
'sensitive #f)
'tag (list (hash 'type "Hashtag"
'href "https://example.tld/tags/blahaj"
'name "#blahaj"))
'manuallyApprovesFollowers #f
'summary "summary lol"
'attachment (list (hash 'type "PropertyValue"
'name "pronouns"
'value "they/them"))
'url "https://example.tld/"
'inbox "https://example.tld/inbox"
'sharedInbox "https://example.tld/inbox"
'endpoints (hash 'sharedInbox "https://example.tld/inbox")
'outbox "https://example.tld/outbox"
'following 'null
'followers "https://example.tld/followers"
'liked 'null
'publicKey (hash 'id "https://example.tld/#main-key"
'type "Key"
'owner "https://example.tld/"
'publicKeyPem key)))
(write-json actor out))))
(define compiler-rules
(set compile-index-json))
(define ops (generate-operations compiler-rules))
(for ([op (in-list ops)])
(printf "executing ~s\n" op)
(execute-rule op))