summaryrefslogtreecommitdiff
path: root/gnu/packages/lua.scm
diff options
context:
space:
mode:
authorCarlo Zancanaro <carlo@zancanaro.id.au>2026-06-08 22:35:37 +1000
committerNguyễn Gia Phong <cnx@loang.net>2026-06-17 21:59:16 +0900
commit95f33b0c5e5f35401ec5250de0fa24ce8460abc3 (patch)
treef748b703c07796adc63f5cb98fb5f31bec5b18a4 /gnu/packages/lua.scm
parent029b8b91eb176b42b2168040b161333f04519673 (diff)
gnu: lua: Introduce helpers to rewrite Lua input versions.
* gnu/packages/lua.scm (make-lua-rewriter, package-with-lua-5.1) (package-with-lua-5.2, package-with-lua-5.3, package-with-lua-5.4) (package-with-lua-5.5): New procedures. (define-public-lua-variant, define-public-lua-variants) (this-lua-version, this-lua-input): New macros. Merges: https://codeberg.org/guix/guix/pulls/9183 Signed-off-by: Nguyễn Gia Phong <cnx@loang.net>
Diffstat (limited to 'gnu/packages/lua.scm')
-rw-r--r--gnu/packages/lua.scm97
1 files changed, 97 insertions, 0 deletions
diff --git a/gnu/packages/lua.scm b/gnu/packages/lua.scm
index adc5ab02bc3..3a838b883bb 100644
--- a/gnu/packages/lua.scm
+++ b/gnu/packages/lua.scm
@@ -327,6 +327,103 @@ considered a fork, since changes are regularly synchronized from the upstream
327LuaJIT project. This package also enables the Lua 5.2 compat mode needed by 327LuaJIT project. This package also enables the Lua 5.2 compat mode needed by
328some projects."))) 328some projects.")))
329 329
330(define (make-lua-rewriter lua-package old-prefix new-prefix)
331 "Define a procedure that replaces lua inputs with LUA-PACKAGE. This only
332operates on packages with a name starting with OLD-PREFIX, which is rewritten to
333NEW-PREFIX."
334 (define (transform-name name)
335 (if (string-prefix? old-prefix name)
336 (string-append new-prefix
337 (substring name (string-length old-prefix)))
338 name))
339
340 (define (rewrite-input-labels inputs)
341 (map (lambda (input)
342 (match input
343 ((label (? package? package) outputs ...)
344 (cons* (transform-name label) package outputs))
345 (_
346 input)))
347 inputs))
348
349 (define (transform package)
350 (if (eq? package lua)
351 lua-package
352 (let* ((old-name (package-name package))
353 (new-name (transform-name old-name)))
354 (if (string= old-name new-name)
355 package
356 (package/inherit package
357 (location (package-location package))
358 (name new-name)
359 (source
360 (cond
361 ;; If we're using {git,hg}-fetch, then rewrite the file-name
362 ;; of the resulting package. This avoids causing rebuilds
363 ;; when migrating from the older method of defining Lua
364 ;; packages.
365 ((eq? (origin-method (package-source package)) git-fetch)
366 (origin
367 (inherit (package-source package))
368 (file-name (git-file-name name (package-version package)))))
369 ((eq? (origin-method (package-source package)) hg-fetch)
370 (origin
371 (inherit (package-source package))
372 (file-name (hg-file-name name (package-version package)))))
373 (else
374 (package-source package))))
375 ;; We also need to rewrite the input labels, otherwise the
376 ;; differences cause rebuilds.
377 (inputs (rewrite-input-labels (package-inputs package)))
378 (native-inputs (rewrite-input-labels (package-native-inputs package)))
379 (propagated-inputs (rewrite-input-labels (package-propagated-inputs package))))))))
380
381 (define (cut? package)
382 (or (eq? package lua)
383 (eq? package lua-package)))
384
385 (package-mapping transform cut?))
386
387(define package-with-lua-5.5 (make-lua-rewriter lua-5.5 "lua-" "lua5.5-"))
388(define package-with-lua-5.4 (make-lua-rewriter lua-5.4 "lua-" "lua5.4-"))
389(define package-with-lua-5.3 (make-lua-rewriter lua "lua-" "lua5.3-"))
390(define package-with-lua-5.2 (make-lua-rewriter lua-5.2 "lua-" "lua5.2-"))
391(define package-with-lua-5.1 (make-lua-rewriter lua-5.1 "lua-" "lua5.1-"))
392
393(define-syntax define-public-lua-variant
394 (syntax-rules (lua-5.5 lua-5.4 lua-5.3 lua-5.2 lua-5.1)
395 "Helper to define a single variant for PACKAGE, called NEW-PACKAGE, for the
396specified lua version. We explicitly match the lua package name as a symbol, so
397we can pick the rewriting function to rewrite package names appropriately."
398 ((_ package (lua-5.5 new-package))
399 (define-public new-package (package-with-lua-5.5 package)))
400 ((_ package (lua-5.4 new-package))
401 (define-public new-package (package-with-lua-5.4 package)))
402 ((_ package (lua-5.3 new-package))
403 (define-public new-package (package-with-lua-5.3 package)))
404 ((_ package (lua-5.2 new-package))
405 (define-public new-package (package-with-lua-5.2 package)))
406 ((_ package (lua-5.1 new-package))
407 (define-public new-package (package-with-lua-5.1 package)))))
408
409(define-syntax-rule (define-public-lua-variants package (lua-version new-package) ...)
410 "Define variants of PACKAGE for each LUA-VERSION, naming the corresponding
411package NEW-PACKAGE."
412 (begin (define-public-lua-variant package (lua-version new-package)) ...))
413
414(define-syntax-rule (this-lua-version)
415 "Return the major+minor version string of the current package's lua input."
416 (version-major+minor (package-version (or (this-package-input "lua")
417 (this-package-native-input "lua")))))
418
419(define-syntax-rule (this-lua-input name)
420 "Return the package input which matches NAME, after replacing any lua- prefix
421with the appropriate luaX.X- prefix for this package."
422 (this-package-input
423 (if (string-prefix? "lua-" name)
424 (string-append "lua" (this-lua-version) "-" (substring name 4))
425 name)))
426
330(define (make-lua-expat name lua) 427(define (make-lua-expat name lua)
331 (package 428 (package
332 (name name) 429 (name name)