Author: manu
Date: Tue Apr 16 20:08:19 2019
New Revision: 346298
URL: https://svnweb.freebsd.org/changeset/base/346298

Log:
  config: Only warn if duplicate option/device comes from the same file
  
  This is useful for arm (possibly other arches too) where we want to have
  a GENERIC kernel that only include files for the different SoC. Since
  multiple SoCs/Board needs the same device we would need to do either :
  
      Include the device in a generic file
      Include the device in each file that really needs it
  
  Option 1 works but if someone wants to create a specific kernel config
  (which isn't uncommon for embedded system), he will need to add a lots
  of nodevice to it.
  
  Option 2 also works but produce a lots of warnings.
  
  Reviewed by:  kevans
  MFC after:    2 weeks
  Differential Revision:        https://reviews.freebsd.org/D19424

Modified:
  head/usr.sbin/config/config.h
  head/usr.sbin/config/config.y

Modified: head/usr.sbin/config/config.h
==============================================================================
--- head/usr.sbin/config/config.h       Tue Apr 16 20:06:39 2019        
(r346297)
+++ head/usr.sbin/config/config.h       Tue Apr 16 20:08:19 2019        
(r346298)
@@ -86,6 +86,7 @@ struct files_name {
 struct device {
        int     d_done;                 /* processed */
        char    *d_name;                /* name of device (e.g. rk11) */
+       char    *yyfile;                /* name of the file that first include 
the device */
 #define        UNKNOWN -2      /* -2 means not set yet */
        STAILQ_ENTRY(device) d_next;    /* Next one in list */
 };
@@ -125,6 +126,7 @@ struct opt {
        char    *op_name;
        char    *op_value;
        int     op_ownfile;     /* true = own file, false = makefile */
+       char    *yyfile;        /* name of the file that first include the 
option */
        SLIST_ENTRY(opt) op_next;
        SLIST_ENTRY(opt) op_append;
 };

Modified: head/usr.sbin/config/config.y
==============================================================================
--- head/usr.sbin/config/config.y       Tue Apr 16 20:06:39 2019        
(r346297)
+++ head/usr.sbin/config/config.y       Tue Apr 16 20:08:19 2019        
(r346298)
@@ -382,11 +382,13 @@ finddev(struct device_head *dlist, char *name)
 static void
 newdev(char *name)
 {
-       struct device *np;
+       struct device *np, *dp;
 
-       if (finddev(&dtab, name)) {
-               fprintf(stderr,
-                   "WARNING: duplicate device `%s' encountered.\n", name);
+       if ((dp = finddev(&dtab, name)) != NULL) {
+               if (strcmp(dp->yyfile, yyfile) == 0)
+                       fprintf(stderr,
+                           "WARNING: duplicate device `%s' encountered in 
%s\n",
+                           name, yyfile);
                return;
        }
 
@@ -394,6 +396,7 @@ newdev(char *name)
        if (np == NULL)
                err(EXIT_FAILURE, "calloc");
        np->d_name = name;
+       np->yyfile = strdup(yyfile);
        STAILQ_INSERT_TAIL(&dtab, np, d_next);
 }
 
@@ -408,6 +411,7 @@ rmdev_schedule(struct device_head *dh, char *name)
        dp = finddev(dh, name);
        if (dp != NULL) {
                STAILQ_REMOVE(dh, dp, device, d_next);
+               free(dp->yyfile);
                free(dp->d_name);
                free(dp);
        }
@@ -446,8 +450,9 @@ newopt(struct opt_head *list, char *name, char *value,
 
        op2 = findopt(list, name);
        if (op2 != NULL && !append && !dupe) {
-               fprintf(stderr,
-                   "WARNING: duplicate option `%s' encountered.\n", name);
+               if (strcmp(op2->yyfile, yyfile) == 0)
+                       fprintf(stderr,
+                           "WARNING: duplicate option `%s' encountered.\n", 
name);
                return;
        }
 
@@ -457,6 +462,7 @@ newopt(struct opt_head *list, char *name, char *value,
        op->op_name = name;
        op->op_ownfile = 0;
        op->op_value = value;
+       op->yyfile = strdup(yyfile);
        if (op2 != NULL) {
                if (append) {
                        while (SLIST_NEXT(op2, op_append) != NULL)
@@ -481,6 +487,7 @@ rmopt_schedule(struct opt_head *list, char *name)
 
        while ((op = findopt(list, name)) != NULL) {
                SLIST_REMOVE(list, op, opt, op_next);
+               free(op->yyfile);
                free(op->op_name);
                free(op);
        }
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to