From 9bd01769187523f2bb96d0de0c8b926a53dc28ed Mon Sep 17 00:00:00 2001 From: Jared Casper Date: Wed, 13 Jul 2011 22:55:03 -0700 Subject: [PATCH] gnetlist: bom/bom2 backend attribute list improvements - Checks for the existence of the attribute file, gives a helpful error message if none is found (no default) - Adds an attrib_file command line option to the backend for specifying an alternate attribute file - Adds an attribs command line option for specifying the attributes directly from the command line Closes-bug: lp-810202 --- gnetlist/scheme/gnet-bom.scm | 63 +++++++++++++++++++++++++++------------- gnetlist/scheme/gnet-bom2.scm | 56 +++++++++++++++++++++++++----------- 2 files changed, 81 insertions(+), 38 deletions(-) diff --git a/gnetlist/scheme/gnet-bom.scm b/gnetlist/scheme/gnet-bom.scm index 4ccd26f..05cb40a 100644 --- a/gnetlist/scheme/gnet-bom.scm +++ b/gnetlist/scheme/gnet-bom.scm @@ -30,17 +30,35 @@ ;;; Questions? Contact matt@ettus.com ;;; This software is released under the terms of the GNU GPL -(use-modules (ice-9 rdelim)) ;; guile-1.8 fix +(use-modules (ice-9 rdelim) ;; guile-1.8 fix + (gnetlist backend-getopt)) + +(define bom:open-input-file + (lambda (options) + (let ((filename (backend-option-ref options 'attrib_file "attribs"))) + (if (file-exists? filename) + (open-input-file filename) + (if (backend-option-ref options 'attribs) #f + (begin + (display (string-append "ERROR: Attribute file '" filename "' not found. You must do one of the following:\n")) + (display " - Create an 'attribs' file\n") + (display " - Specify an attribute file using -Oattrib_file=\n") + (display " - Specify which attributes to include using -Oattribs=attrib1,attrib2,... (no spaces)\n") + #f)))))) (define bom (lambda (output-filename) - (let ((port (if (string=? "-" output-filename) - (current-output-port) - (open-output-file output-filename))) - (attriblist (bom:parseconfig (open-input-file "attribs")))) - (bom:printlist (cons 'refdes attriblist) port) - (bom:components port packages attriblist) - (close-output-port port)))) + (let* ((options (backend-getopt + (gnetlist:get-backend-arguments) + '((attrib_file (value #t)) (attribs (value #t))))) + (port (if (string=? "-" output-filename) + (current-output-port) + (open-output-file output-filename))) + (attriblist (bom:parseconfig (bom:open-input-file options) options))) + (and attriblist + (begin (bom:printlist (cons 'refdes attriblist) port) + (bom:components port packages attriblist) + (close-output-port port)))))) (define bom:printlist (lambda (ls port) @@ -51,26 +69,29 @@ (write-char #\tab port) (bom:printlist (cdr ls) port))))) -; Parses attrib file. Returns a list of read attributes. +; Parses attrib file or argument. Returns a list of read attributes. (define bom:parseconfig - (lambda (port) - (let ((read-from-file (read-delimited " \n\t" port))) - (cond ((eof-object? read-from-file) - '()) - ((= 0 (string-length read-from-file)) - (bom:parseconfig port)) - (else - (cons read-from-file (bom:parseconfig port))))))) + (lambda (port options) + (let ((attribs (backend-option-ref options 'attribs))) + (if attribs (string-split attribs #\,) + (and port + (let ((read-from-file (read-delimited " \n\t" port))) + (cond ((eof-object? read-from-file) + '()) + ((= 0 (string-length read-from-file)) + (bom:parseconfig port options)) + (else + (cons read-from-file (bom:parseconfig port options)))))))))) (define bom:components (lambda (port ls attriblist) (if (not (null? ls)) (let ((package (car ls))) (if (not (string=? "1" (gnetlist:get-package-attribute package "nobom"))) - (begin - (display package port) - (write-char #\tab port) - (bom:printlist (bom:find-attribs package attriblist) port))) + (begin + (display package port) + (write-char #\tab port) + (bom:printlist (bom:find-attribs package attriblist) port))) (bom:components port (cdr ls) attriblist))))) (define bom:find-attribs diff --git a/gnetlist/scheme/gnet-bom2.scm b/gnetlist/scheme/gnet-bom2.scm index 128160d..a3c8549 100644 --- a/gnetlist/scheme/gnet-bom2.scm +++ b/gnetlist/scheme/gnet-bom2.scm @@ -30,18 +30,37 @@ ;;; Questions? Contact matt@ettus.com ;;; This software is released under the terms of the GNU GPL -(use-modules (ice-9 rdelim)) ;; guile-1.8 fix +(use-modules (ice-9 rdelim) ;; guile-1.8 fix + (gnetlist backend-getopt)) + +(define bom2:open-input-file + (lambda (options) + (let ((filename (backend-option-ref options 'attrib_file "attribs"))) + (if (file-exists? filename) + (open-input-file filename) + (if (backend-option-ref options 'attribs) #f + (begin + (display (string-append "ERROR: Attribute file '" filename "' not found. You must do one of the following:\n")) + (display " - Create an 'attribs' file\n") + (display " - Specify an attribute file using -Oattrib_file=\n") + (display " - Specify which attributes to include using -Oattribs=attrib1,attrib2,... (no spaces)\n") + #f)))))) (define bom2 (lambda (output-filename) - (let ((port (if (string=? "-" output-filename) - (current-output-port) - (open-output-file output-filename))) - (attriblist (bom2:parseconfig (open-input-file "attribs")))) - (bom2:printlist (append (cons 'refdes attriblist) (list "qty")) port #\:) - (newline port) - (bom2:printbom port (bom2:components packages attriblist) 0) - (close-output-port port)))) + (let* ((options (backend-getopt + (gnetlist:get-backend-arguments) + '((attrib_file (value #t)) (attribs (value #t))))) + (port (if (string=? "-" output-filename) + (current-output-port) + (open-output-file output-filename))) + (attriblist (bom2:parseconfig (bom2:open-input-file options) options))) + (and attriblist + (begin + (bom2:printlist (append (cons 'refdes attriblist) (list "qty")) port #\:) + (newline port) + (bom2:printbom port (bom2:components packages attriblist) 0) + (close-output-port port)))))) (define bom2:printbom (lambda (port bomlist count) @@ -74,14 +93,17 @@ ; Parses attrib file. Returns a list of read attributes. (define bom2:parseconfig - (lambda (port) - (let ((read-from-file (read-delimited " \n\t" port))) - (cond ((eof-object? read-from-file) - '()) - ((= 0 (string-length read-from-file)) - (bom2:parseconfig port)) - (else - (cons read-from-file (bom2:parseconfig port))))))) + (lambda (port options) + (let ((attribs (backend-option-ref options 'attribs))) + (if attribs (string-split attribs #\,) + (and port + (let ((read-from-file (read-delimited " \n\t" port))) + (cond ((eof-object? read-from-file) + '()) + ((= 0 (string-length read-from-file)) + (bom2:parseconfig port options)) + (else + (cons read-from-file (bom2:parseconfig port options)))))))))) (define bom2:match-list? (lambda (l1 l2) -- 1.7.6