From: Julien Lepiller <julien@lepiller.eu>
To: 48766@debbugs.gnu.org
Subject: [bug#48766] [PATCH 03/14] guix: maven: Simplify finding local packages and modules.
Date: Tue, 1 Jun 2021 00:44:16 +0200 [thread overview]
Message-ID: <20210531224427.13300-3-julien@lepiller.eu> (raw)
In-Reply-To: <20210531224427.13300-1-julien@lepiller.eu>
* guix/build/maven-build-system (fix-pom): Fix a single pom file without
recursing
(fix-pom-files): Find local packages and all submodules, and fix them
all at once.
(add-local-package): Move to...
* guix/build/maven/pom.scm (add-local-package): ...here.
(pom-and-submodules, pom-local-packages): New procedures.
---
guix/build/maven-build-system.scm | 41 +++++-------------------
guix/build/maven/pom.scm | 53 ++++++++++++++++++++++++++++++-
2 files changed, 60 insertions(+), 34 deletions(-)
diff --git a/guix/build/maven-build-system.scm b/guix/build/maven-build-system.scm
index 0456bfdf61..374fa2fdb8 100644
--- a/guix/build/maven-build-system.scm
+++ b/guix/build/maven-build-system.scm
@@ -60,47 +60,22 @@
(invoke "mvn" "-v")
#t)
-(define (add-local-package local-packages group artifact version)
- (define (alist-set lst key val)
- (match lst
- ('() (list (cons key val)))
- (((k . v) lst ...)
- (if (equal? k key)
- (cons (cons key val) lst)
- (cons (cons k v) (alist-set lst key val))))))
- (alist-set local-packages group
- (alist-set (or (assoc-ref local-packages group) '()) artifact
- version)))
-
(define (fix-pom pom-file inputs local-packages excludes)
(chmod pom-file #o644)
(format #t "fixing ~a~%" pom-file)
(fix-pom-dependencies pom-file (map cdr inputs)
#:with-plugins? #t #:with-build-dependencies? #t
#:local-packages local-packages
- #:excludes excludes)
- (let* ((pom (get-pom pom-file))
- (java-inputs (map cdr inputs))
- (artifact (pom-artifactid pom))
- (group (pom-groupid pom))
- (version (pom-version pom)))
- (let loop ((modules (pom-ref pom "modules"))
- (local-packages
- (add-local-package local-packages group artifact version)))
- (pk 'local-packages local-packages)
- (match modules
- (#f local-packages)
- ('() local-packages)
- (((? string? _) modules ...)
- (loop modules local-packages))
- (((_ module) modules ...)
- (loop
- modules
- (fix-pom (string-append (dirname pom-file) "/" module "/pom.xml")
- inputs local-packages excludes)))))))
+ #:excludes excludes))
(define* (fix-pom-files #:key inputs local-packages exclude #:allow-other-keys)
- (fix-pom "pom.xml" inputs local-packages exclude)
+ (let ((local-packages (pom-local-packages "pom.xml" #:local-packages local-packages)))
+ (format (current-error-port) "Fix pom files with local packages: ~a~%" local-packages)
+ (for-each
+ (lambda (pom)
+ (when (file-exists? pom)
+ (fix-pom pom inputs local-packages exclude)))
+ (pom-and-submodules "pom.xml")))
#t)
(define* (build #:key outputs #:allow-other-keys)
diff --git a/guix/build/maven/pom.scm b/guix/build/maven/pom.scm
index 327d5f75e8..8f16cf4d26 100644
--- a/guix/build/maven/pom.scm
+++ b/guix/build/maven/pom.scm
@@ -21,7 +21,8 @@
#:use-module (system foreign)
#:use-module (ice-9 match)
#:use-module (srfi srfi-1)
- #:export (get-pom
+ #:export (add-local-package
+ get-pom
pom-ref
pom-description
pom-name
@@ -30,8 +31,24 @@
pom-groupid
pom-dependencies
group->dir
+ pom-and-submodules
+ pom-local-packages
fix-pom-dependencies))
+(define (add-local-package local-packages group artifact version)
+ "Takes @var{local-packages}, a list of local packages, and adds a new one
+for @var{group}:@var{artifact} at @var{version}."
+ (define (alist-set lst key val)
+ (match lst
+ ('() (list (cons key val)))
+ (((k . v) lst ...)
+ (if (equal? k key)
+ (cons (cons key val) lst)
+ (cons (cons k v) (alist-set lst key val))))))
+ (alist-set local-packages group
+ (alist-set (or (assoc-ref local-packages group) '()) artifact
+ version)))
+
(define (get-pom file)
"Return the content of a @file{.pom} file."
(let ((pom-content (call-with-input-file file xml->sxml)))
@@ -234,6 +251,40 @@ to re-declare the namespaces in the top-level element."
http://maven.apache.org/xsd/maven-4.0.0.xsd"))
,(map fix-xml sxml)))))
+(define (pom-and-submodules pom-file)
+ "Given @var{pom-file}, the file name of a pom, return the list of pom file
+names that correspond to itself and its submodules, recursively."
+ (define (get-modules modules)
+ (match modules
+ (#f '())
+ ('() '())
+ (((? string? _) rest ...) (get-modules rest))
+ ((('http://maven.apache.org/POM/4.0.0:module mod) rest ...)
+ (let ((pom (string-append (dirname pom-file) "/" mod "/pom.xml")))
+ (if (file-exists? pom)
+ (cons pom (get-modules rest))
+ (get-modules rest))))))
+
+ (let* ((pom (get-pom pom-file))
+ (modules (get-modules (pom-ref pom "modules"))))
+ (cons pom-file
+ (apply append (map pom-and-submodules modules)))))
+
+(define* (pom-local-packages pom-file #:key (local-packages '()))
+ "Given @var{pom-file}, a pom file name, return a list of local packages that
+this repository contains."
+ (let loop ((modules (pom-and-submodules pom-file))
+ (local-packages local-packages))
+ (match modules
+ (() local-packages)
+ ((module modules ...)
+ (let* ((pom (get-pom module))
+ (version (pom-version pom))
+ (artifactid (pom-artifactid pom))
+ (groupid (pom-groupid pom)))
+ (loop modules
+ (add-local-package local-packages groupid artifactid version)))))))
+
(define (group->dir group)
"Convert a group ID to a directory path."
(string-join (string-split group #\.) "/"))
--
2.31.1
next prev parent reply other threads:[~2021-05-31 22:45 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-31 22:41 [bug#48766] [PATCH] gnu: java-jmh: Switch to maven-build-system Julien Lepiller
2021-05-31 22:44 ` [bug#48766] [PATCH 01/14] guix: java-utils: Factorize pom.xml generation Julien Lepiller
2021-05-31 22:44 ` [bug#48766] [PATCH 02/14] guix: maven: Simplify finding version and group information Julien Lepiller
2021-05-31 22:44 ` Julien Lepiller [this message]
2021-05-31 22:44 ` [bug#48766] [PATCH 04/14] guix: maven: Support fixing extensions Julien Lepiller
2021-05-31 22:44 ` [bug#48766] [PATCH 05/14] guix: maven: Support fixing modules Julien Lepiller
2021-05-31 22:44 ` [bug#48766] [PATCH 06/14] guix: maven: Look in local packages when searching for package version Julien Lepiller
2021-05-31 22:44 ` [bug#48766] [PATCH 07/14] guix: maven: Use a temporary file to fix pom files Julien Lepiller
2021-05-31 22:44 ` [bug#48766] [PATCH 08/14] guix: java-utils: Look for actual jar files Julien Lepiller
2021-05-31 22:44 ` [bug#48766] [PATCH 09/14] gnu: Add java-jopt-simple-4 Julien Lepiller
2021-05-31 22:44 ` [bug#48766] [PATCH 10/14] gnu: java-commons-math3: Install to maven repository Julien Lepiller
2021-05-31 22:44 ` [bug#48766] [PATCH 11/14] gnu: maven-core: Hardcode versions we have in Guix Julien Lepiller
2021-05-31 22:44 ` [bug#48766] [PATCH 12/14] gnu: maven-enforcer-parent-pom: Fix pom Julien Lepiller
2021-05-31 22:44 ` [bug#48766] [PATCH 13/14] gnu: java-jmh: Update to 1.32 Julien Lepiller
2021-05-31 22:44 ` [bug#48766] [PATCH 14/14] gnu: java-jmh: Switch to maven-build-system Julien Lepiller
2021-06-22 11:13 ` bug#48766: [PATCH] " Julien Lepiller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210531224427.13300-3-julien@lepiller.eu \
--to=julien@lepiller.eu \
--cc=48766@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).