style: Add '--dry-run'.
* guix/scripts/style.scm (edit-expression/dry-run): New procedure. (simplify-package-inputs): Add #:edit-expression parameter. (%options, show-help): Add '--dry-run'. (guix-style): Honor '--dry-run'.
This commit is contained in:
		
							parent
							
								
									0677443c45
								
							
						
					
					
						commit
						19dc16ce4b
					
				
					 2 changed files with 28 additions and 3 deletions
				
			
		| 
						 | 
					@ -12725,6 +12725,10 @@ comments and bailing out if it cannot make sense of the code that
 | 
				
			||||||
appears in an inputs field.  The available options are listed below.
 | 
					appears in an inputs field.  The available options are listed below.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@table @code
 | 
					@table @code
 | 
				
			||||||
 | 
					@item --dry-run
 | 
				
			||||||
 | 
					@itemx -n
 | 
				
			||||||
 | 
					Show source file locations that would be edited but do not modify them.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@item --load-path=@var{directory}
 | 
					@item --load-path=@var{directory}
 | 
				
			||||||
@itemx -L @var{directory}
 | 
					@itemx -L @var{directory}
 | 
				
			||||||
Add @var{directory} to the front of the package module search path
 | 
					Add @var{directory} to the front of the package module search path
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -382,13 +382,25 @@ bailing out~%")
 | 
				
			||||||
              package)
 | 
					              package)
 | 
				
			||||||
     str)))
 | 
					     str)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(define (edit-expression/dry-run properties rewrite-string)
 | 
				
			||||||
 | 
					  "Like 'edit-expression' but display what would be edited without actually
 | 
				
			||||||
 | 
					doing it."
 | 
				
			||||||
 | 
					  (edit-expression properties
 | 
				
			||||||
 | 
					                   (lambda (str)
 | 
				
			||||||
 | 
					                     (unless (string=? (rewrite-string str) str)
 | 
				
			||||||
 | 
					                       (info (source-properties->location properties)
 | 
				
			||||||
 | 
					                             (G_ "would be edited~%")))
 | 
				
			||||||
 | 
					                     str)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(define* (simplify-package-inputs package
 | 
					(define* (simplify-package-inputs package
 | 
				
			||||||
                                  #:key (policy 'silent))
 | 
					                                  #:key (policy 'silent)
 | 
				
			||||||
 | 
					                                  (edit-expression edit-expression))
 | 
				
			||||||
  "Edit the source code of PACKAGE to simplify its inputs field if needed.
 | 
					  "Edit the source code of PACKAGE to simplify its inputs field if needed.
 | 
				
			||||||
POLICY is a symbol that defines whether to simplify inputs; it can one of
 | 
					POLICY is a symbol that defines whether to simplify inputs; it can one of
 | 
				
			||||||
'silent (change only if the resulting derivation is the same), 'safe (change
 | 
					'silent (change only if the resulting derivation is the same), 'safe (change
 | 
				
			||||||
only if semantics are known to be unaffected), and 'always (fearlessly
 | 
					only if semantics are known to be unaffected), and 'always (fearlessly
 | 
				
			||||||
simplify inputs!)."
 | 
					simplify inputs!).  Call EDIT-EXPRESSION to actually edit the source of
 | 
				
			||||||
 | 
					PACKAGE."
 | 
				
			||||||
  (for-each (lambda (field-name field)
 | 
					  (for-each (lambda (field-name field)
 | 
				
			||||||
              (match (field package)
 | 
					              (match (field package)
 | 
				
			||||||
                (()
 | 
					                (()
 | 
				
			||||||
| 
						 | 
					@ -449,6 +461,9 @@ simplify inputs!)."
 | 
				
			||||||
                (member "load-path" (option-names option)))
 | 
					                (member "load-path" (option-names option)))
 | 
				
			||||||
              %standard-build-options)
 | 
					              %standard-build-options)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        (option '(#\n "dry-run") #f #f
 | 
				
			||||||
 | 
					                (lambda (opt name arg result)
 | 
				
			||||||
 | 
					                  (alist-cons 'dry-run? #t result)))
 | 
				
			||||||
        (option '(#\e "expression") #t #f
 | 
					        (option '(#\e "expression") #t #f
 | 
				
			||||||
                (lambda (opt name arg result)
 | 
					                (lambda (opt name arg result)
 | 
				
			||||||
                  (alist-cons 'expression arg result)))
 | 
					                  (alist-cons 'expression arg result)))
 | 
				
			||||||
| 
						 | 
					@ -472,6 +487,8 @@ simplify inputs!)."
 | 
				
			||||||
(define (show-help)
 | 
					(define (show-help)
 | 
				
			||||||
  (display (G_ "Usage: guix style [OPTION]... [PACKAGE]...
 | 
					  (display (G_ "Usage: guix style [OPTION]... [PACKAGE]...
 | 
				
			||||||
Update package definitions to the latest style.\n"))
 | 
					Update package definitions to the latest style.\n"))
 | 
				
			||||||
 | 
					  (display (G_ "
 | 
				
			||||||
 | 
					  -n, --dry-run          display files that would be edited but do nothing"))
 | 
				
			||||||
  (display (G_ "
 | 
					  (display (G_ "
 | 
				
			||||||
  -L, --load-path=DIR    prepend DIR to the package module search path"))
 | 
					  -L, --load-path=DIR    prepend DIR to the package module search path"))
 | 
				
			||||||
  (display (G_ "
 | 
					  (display (G_ "
 | 
				
			||||||
| 
						 | 
					@ -514,9 +531,13 @@ Update package definitions to the latest style.\n"))
 | 
				
			||||||
                                  (read/eval str))
 | 
					                                  (read/eval str))
 | 
				
			||||||
                                 (_ #f))
 | 
					                                 (_ #f))
 | 
				
			||||||
                               opts))
 | 
					                               opts))
 | 
				
			||||||
 | 
					         (edit     (if (assoc-ref opts 'dry-run?)
 | 
				
			||||||
 | 
					                       edit-expression/dry-run
 | 
				
			||||||
 | 
					                       edit-expression))
 | 
				
			||||||
         (policy   (assoc-ref opts 'input-simplification-policy)))
 | 
					         (policy   (assoc-ref opts 'input-simplification-policy)))
 | 
				
			||||||
    (for-each (lambda (package)
 | 
					    (for-each (lambda (package)
 | 
				
			||||||
                (simplify-package-inputs package #:policy policy))
 | 
					                (simplify-package-inputs package #:policy policy
 | 
				
			||||||
 | 
					                                         #:edit-expression edit))
 | 
				
			||||||
              ;; Sort package by source code location so that we start editing
 | 
					              ;; Sort package by source code location so that we start editing
 | 
				
			||||||
              ;; files from the bottom and going upward.  That way, the
 | 
					              ;; files from the bottom and going upward.  That way, the
 | 
				
			||||||
              ;; 'location' field of <package> records is not invalidated as
 | 
					              ;; 'location' field of <package> records is not invalidated as
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Reference in a new issue