From 7d4563a271fda000dca2845b068658b467c7e91d Mon Sep 17 00:00:00 2001 From: Maxime Devos Date: Fri, 30 Apr 2021 15:02:20 +0200 Subject: [PATCH 04/11] etc: committer: Automatically generate a first line in more cases. * etc/committer.scm.in (, make-patch-summary, patch-summary?) (patch-summary:cc-for-target, patch-summary:cxx-for-target) (set-patch-summary:cc-for-target!, set-patch-summary:cxx-for-target!) (set-patch-summary:respect-tests?!, patch-summary:respect-tests?): Define record type for keeping track of what the current patch is doing. (change-commit-message): Rename to ... (change-commit-message/one-pass): ... this, record information about the current patch in a record, and use that information for creating the first line of the commit message. (change-commit-message): New procedure, with the same calling convention as the old change-commit-message. (change-commit-message)[explain-make-flags/change]: Populate the patch summary. (change-commit-message)[explain-phases/change]: Likewise. --- etc/committer.scm.in | 50 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/etc/committer.scm.in b/etc/committer.scm.in index 02f7817bde..231f27fe4e 100755 --- a/etc/committer.scm.in +++ b/etc/committer.scm.in @@ -276,8 +276,29 @@ Return false if all changes could be explained and truth otherwise." ((symbol? argument-list) #f) (#t (error "the argument list seems to be incorrect!"))))) -(define* (change-commit-message file-name old new #:optional (port (current-output-port))) - "Print ChangeLog commit message for changes between OLD and NEW." +;; A machine-readable summary of changes made, +;; that are required for deciding on the first line +;; of the commit message. +(define-record-type + (%make-patch-summary cc-for-target cxx-for-target respect-tests?) + patch-summary? + ;; #f | created | corrected + (cc-for-target patch-summary:cc-for-target set-patch-summary:cc-for-target!) + (cxx-for-target patch-summary:cxx-for-target set-patch-summary:cxx-for-target!) + ;; #f | #t + (respect-tests? patch-summary:respect-tests? set-patch-summary:respect-tests?!)) + +(define (make-patch-summary) + (%make-patch-summary #f #f #f)) + +(define* (change-commit-message/one-pass + file-name old new summary + #:optional (port (current-output-port))) + "Print ChangeLog commit message for changes between OLD and NEW. +Record information for deciding on the first line in SUMMARY. +As the information is only recorded after the first line has been written +to PORT, you should probably run this procedure twice, but with the same +SUMMARY: first using a ‘void port’, then with the ‘real’ output port." (define (get-values expr field) (match ((sxpath `(// ,field quasiquote *)) expr) (() '()) @@ -309,6 +330,19 @@ Return false if all changes could be explained and truth otherwise." (cond ((not (equal? old-version new-version)) (format port "gnu: ~a: Update to ~a.~%~%* ~a (~a): Update to ~a.~%" variable-name new-version file-name variable-name new-version)) + ((and (patch-summary:cc-for-target summary) + (patch-summary:cxx-for-target summary)) + (format port "gnu: ~a: Use 'cc-for-target' and friends.~%~%* ~a (~a)~%" + variable-name file-name variable-name)) + ((patch-summary:cc-for-target summary) + (format port "gnu: ~a: Use the C cross-compiler.~%~%* ~a (~a)~%" + variable-name file-name variable-name)) + ((patch-summary:cxx-for-target summary) + (format port "gnu: ~a: Use the C cross-compiler.~%~%* ~a (~a)~%" + variable-name file-name variable-name)) + ((patch-summary:respect-tests? summary) + (format port "gnu: ~a: Only run tests when requested.~%~% ~a (~a)~%" + variable-name file-name variable-name)) (#t (format port "gnu: ~a: ~%~%* ~a (~a): FIXME!.~%" variable-name file-name variable-name))) @@ -337,10 +371,12 @@ Return false if all changes could be explained and truth otherwise." (define (explain-make-flags/change x y) (match (cons x y) (("CC=gcc" . ',(string-append "CC=" (cc-for-target))) + (set-patch-summary:cc-for-target! summary 'changed) (format port " Use the C cross-compiler, instead of hardcoding \"gcc\".") #t) (("CXX=g++" . ',(string-append "CXX=" (cxx-for-target))) + (set-patch-summary:cxx-for-target! summary 'changed) (format port " Use the C++ cross-compiler, instead of hardcoding \"g++\".") #t) @@ -356,6 +392,7 @@ Return false if all changes could be explained and truth otherwise." . ('replace ''check ((or 'lambda* 'lambda) args/y . exps/y))) (when (and (not (has-explicit-argument? 'tests? args/x)) (has-explicit-argument? 'tests? args/y)) + (set-patch-summary:respect-tests?! summary #t) (format port "[arguments]<#:phases>{check}: Only run tests when not requested.~%") #t)) @@ -389,6 +426,15 @@ Return false if all changes could be explained and truth otherwise." (pairwise-foreach-keyword explain-argument old-arguments new-arguments))) +(define* (change-commit-message file-name old new + #:optional (port (current-output-port))) + "Like change-commit-message/one-pass, but without requiring to be run twice +for a correct header." + (let ((summary (make-patch-summary))) + (change-commit-message/one-pass file-name old new summary + (%make-void-port "w")) + (change-commit-message/one-pass file-name old new summary port))) + (define* (add-commit-message file-name variable-name #:optional (port (current-output-port))) "Print ChangeLog commit message for a change to FILE-NAME adding a definition." (format port -- 2.31.1