Maak 发布 用 Lisp 编写构建任务的命令运行器

原标题:Maak v1.0.0 – infinitely extensible command runner, build sys in Lisp
42AI 研判分

Maak v1.0.0 发布,这是一个以 Guile Scheme 模块作为任务清单的命令运行器与构建系统,每个过程即一个可在命令行调用的任务,无需学习额外 DSL。项目还提供对 Gradle、Emacs Lisp 及 Guix/Nix 可复现构建的集成文档,定位为可无限扩展的构建工具。

报道正文

#+title: maak: infinitely extensible command runner #+author: Josep Bigorra #+email: [email protected] #+options: toc num

[[https://jointhefreeworld.org/ggg/dist/scheme-guile.svg]] [[https://jointhefreeworld.org/ggg/dist/gnu-guix.svg]] [[https://jointhefreeworld.org/ggg/dist/maak.svg]] [[https://jointhefreeworld.org/ggg/dist/license-mit.svg]] [[https://jointhefreeworld.org/ggg/dist/jointhefreeworld-org.svg]]

#+attr_html: 160 maak logo [[file.svg]]

  • Every task is a λ

maak is a command runner, and its task list is a Lisp file. You write =maak.scm= — a perfectly normal Guile module — and every procedure in it becomes a task you can name on the command line. There is no DSL to learn and no second language to keep in your head: the build is the program.

#+begin_src scheme (define-module (maak) #? #t # (maak maak))

;; A task is a λ: (define (build) ...) is (define build (lambda () ...)). (define (build) "Compile every page in ./pages into ./build." (let ((out "build")) (mkdir-p out) (for-each (lambda (page) (run (list "pandoc" (~ "pages/a.md" page) "-o" ( "~a/a.html" out page)))) '("index" "about")) (when (file-exists? "static/style.css") (cp "static/style.css" ( "~a/style.css" out)))))

;; Two programs, one pipe, and a failure that names the stage that failed. (define (check) "Lint every tracked page." (run-pipeline (list (list "git" "ls-files" "pages") (list "xargs" "markdownlint"))))

;; Its arguments arrive as the strings typed on the command line. (define (deploy host) "Ship ./build to HOST, replacing what is there." (unless (file-exists? "build/index.html") (task-error "nothing to deploy" # "Run `maak build' first.")) (run (list "rsync" "-av" "--delete" "build/" (~ "~a:/srv/www/" host))))

;; Procedures are values, so tasks compose like any other function. (define (ci host) "Check, build and ship in one go." (check) (build) (deploy host)) #+end_src

The loop and the conditional expand into four commands, and =--plan= shows each one as the argv it is — no shell to re-parse, no quote to guess at:

#+begin_src shell $ maak --plan build maak plan [1] build mkdir -pv build cwd: /home/me/site [2] build pandoc pages/index.md -o build/index.html cwd: /home/me/site [3] build pandoc pages/about.md -o build/about.html cwd: /home/me/site [4] build cp -r -v static/style.css build/style.css cwd: /home/me/site #+end_src

#+begin_quote Most build tools invent their own limited domain-specific language. Maak embraces the powerful λ Lisp and the amazing Guile Scheme programming language.

/This also means your code is flexible, robust and reliable (+declarative) for at least the next 50 years./ #+end_quote

  • Why it matters. Tasks are real Scheme functions: composable, testable, declarative, dry-runnable, parallelisable, and reproducible.
  • Lisp all the way down
  • The entire language, not a DSL. Define functions, use lists and hash tables, write macros, import libraries. If you can write it in Guile, you can write it in a task.
  • Lambdas compose. A task calls another task with a function call, and a list of tasks is a list — no subprocess, no re-parsing a file to find out what to run.
  • Your editor already knows the language. Docstrings are the task list, the REPL is the development loop, and =maak --list= reads like =apropos=.
  • Guix and Nix are values too. A pin is a store path a task can decide on, not a string another tool has to interpret.
  • Shell-free by default. run takes a program and its arguments as separate strings, so a path with a space in it stays one argument.
  • Errors that read like sentences. task-error prints one line and a hint, exits non-zero, and keeps the backtrace behind --debug.

See the full list pipelines, background jobs, -j, guix, nix, containers, niri, downloads, gettext, maven, uv, python in [[file/features.org][Features]].

** How a function becomes a task

A Maak file is read, not run, when maak answers a question about it: a top-level define, define* or a name bound to a lambda is a task, the # list decides which of them are visible, the docstring is the documentation and the lambda list is the argument grammar. That is what lets a listing, a plan and the call graph be answered for a file somebody is halfway through writing, on a machine that does not have its libraries.

#+attr_html: 720 Taking a maak.scm file from data to a task description and the views built on it [[file/diagrams/task-description.svg]]

  • See it run

#+attr_html: 800 maak --plan deploy, in a terminal [[file/maak-demo.gif]]

  • Documentation

Start with the quick start, or open the whole [[file/index.org][documentation index]].

PageWhat it covers
------+----------------
[[file/quick-start.org][Quick start]]Your first Maak file: eight steps from a module to a dry run.
[[file/tasks.org][Tasks]]How a function becomes a task, what exports hide, how arguments arrive.
[[file/cli.org][The command line]]Every option, the grammar of tasks and arguments, =--list= output.
[[file/configuration.org][Configuration]]Environment variables, and the parameters behind dry-run and quiet.
[[file/builtins.org][The built-in toolkit]]=run=, pipelines, jobs, file helpers, =task-error=, gettext.
[[file/rust-and-cargo.org][Rust and Cargo]]Cargo and rustup helpers, the structured command line, metadata as a value, artefact paths.
[[file/python.org][Python, uv and pyproject]]uv helpers, the version and name a release reads, and the four CI checks.
[[file/frontend.org][Frontend projects]]npm, pnpm and yarn behind one set of procedures, and the package.json a release reads.
[[file/task-files.org][Task files in JSON, TOML and YAML]]A task list without the language: the schema, the formats, their limits.
[[file/maven-and-gradle.org][Maven, Gradle and the JVM]]The Maven lifecycle and Gradle tasks as argv, wrapper detection, and the JVM reports.
[[file/emacs-lisp.org][Emacs Lisp packages]]Byte-compiling, ERT and checkdoc in batch, and the packaging conventions.
[[file/guix-and-nix.org][Guix, Nix and reproducibilit

(注:更多技术实现细节与完整 API 文档请查阅原项目 README)