u-boot.lists.denx.de archive mirror
 help / color / mirror / Atom feed
From: Masahiro Yamada <yamada.m@jp.panasonic.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v3 6/7] tools/genboardscfg.py: check if the boards.cfg is up to date
Date: Mon, 25 Aug 2014 12:39:47 +0900	[thread overview]
Message-ID: <1408937988-19923-7-git-send-email-yamada.m@jp.panasonic.com> (raw)
In-Reply-To: <1408937988-19923-1-git-send-email-yamada.m@jp.panasonic.com>

It looks silly to regenerate the boards.cfg even when it is
already up to date.

The tool should exit with doing nothing if the boards.cfg is newer
than any of defconfig, Kconfig and MAINTAINERS files.

Specify -f (--force) option to get the boards.cfg regenerated
regardless its time stamp.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Acked-by: Simon Glass <sjg@chromium.org>
---

Changes in v3:
  - Use "with ... as ..." and "except ... as ..."

Changes in v2: None

 tools/genboardscfg.py | 58 +++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 56 insertions(+), 2 deletions(-)

diff --git a/tools/genboardscfg.py b/tools/genboardscfg.py
index b4620d9..7142567 100755
--- a/tools/genboardscfg.py
+++ b/tools/genboardscfg.py
@@ -85,6 +85,52 @@ def get_make_cmd():
         sys.exit('GNU Make not found')
     return ret[0].rstrip()
 
+def output_is_new():
+    """Check if the boards.cfg file is up to date.
+
+    Returns:
+      True if the boards.cfg file exists and is newer than any of
+      *_defconfig, MAINTAINERS and Kconfig*.  False otherwise.
+    """
+    try:
+        ctime = os.path.getctime(BOARD_FILE)
+    except OSError as exception:
+        if exception.errno == errno.ENOENT:
+            # return False on 'No such file or directory' error
+            return False
+        else:
+            raise
+
+    for (dirpath, dirnames, filenames) in os.walk(CONFIG_DIR):
+        for filename in fnmatch.filter(filenames, '*_defconfig'):
+            if fnmatch.fnmatch(filename, '.*'):
+                continue
+            filepath = os.path.join(dirpath, filename)
+            if ctime < os.path.getctime(filepath):
+                return False
+
+    for (dirpath, dirnames, filenames) in os.walk('.'):
+        for filename in filenames:
+            if (fnmatch.fnmatch(filename, '*~') or
+                not fnmatch.fnmatch(filename, 'Kconfig*') and
+                not filename == 'MAINTAINERS'):
+                continue
+            filepath = os.path.join(dirpath, filename)
+            if ctime < os.path.getctime(filepath):
+                return False
+
+    # Detect a board that has been removed since the current boards.cfg
+    # was generated
+    with open(BOARD_FILE) as f:
+        for line in f:
+            if line[0] == '#' or line == '\n':
+                continue
+            defconfig = line.split()[6] + '_defconfig'
+            if not os.path.exists(os.path.join(CONFIG_DIR, defconfig)):
+                return False
+
+    return True
+
 ### classes ###
 class MaintainersDatabase:
 
@@ -503,7 +549,7 @@ class BoardsFileGenerator:
 
         self.in_progress = False
 
-def gen_boards_cfg(jobs):
+def gen_boards_cfg(jobs=1, force=False):
     """Generate boards.cfg file.
 
     The incomplete boards.cfg is deleted if an error (including
@@ -513,6 +559,10 @@ def gen_boards_cfg(jobs):
       jobs: The number of jobs to run simultaneously
     """
     check_top_directory()
+    if not force and output_is_new():
+        print "%s is up to date. Nothing to do." % BOARD_FILE
+        sys.exit(0)
+
     generator = BoardsFileGenerator()
     generator.generate(jobs)
 
@@ -521,7 +571,10 @@ def main():
     # Add options here
     parser.add_option('-j', '--jobs',
                       help='the number of jobs to run simultaneously')
+    parser.add_option('-f', '--force', action="store_true", default=False,
+                      help='regenerate the output even if it is new')
     (options, args) = parser.parse_args()
+
     if options.jobs:
         try:
             jobs = int(options.jobs)
@@ -534,7 +587,8 @@ def main():
         except (OSError, ValueError):
             print 'info: failed to get the number of CPUs. Set jobs to 1'
             jobs = 1
-    gen_boards_cfg(jobs)
+
+    gen_boards_cfg(jobs, force=options.force)
 
 if __name__ == '__main__':
     main()
-- 
1.9.1

  parent reply	other threads:[~2014-08-25  3:39 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-25  3:39 [U-Boot] [PATCH v3 0/7] tools/genboardscfg.py: various fixes and performance improvement Masahiro Yamada
2014-08-25  3:39 ` [U-Boot] [PATCH v3 1/7] tools/genboardscfg.py: ignore defconfigs starting with a dot Masahiro Yamada
2014-08-29 14:41   ` [U-Boot] [U-Boot, v3, " Tom Rini
2014-08-25  3:39 ` [U-Boot] [PATCH v3 2/7] tools/genboardscfg.py: be tolerant of missing MAINTAINERS Masahiro Yamada
2014-08-29 14:41   ` [U-Boot] [U-Boot, v3, " Tom Rini
2014-08-25  3:39 ` [U-Boot] [PATCH v3 3/7] tools/genboardscfg.py: be tolerant of insane Kconfig Masahiro Yamada
2014-08-29 14:41   ` [U-Boot] [U-Boot, v3, " Tom Rini
2014-08-25  3:39 ` [U-Boot] [PATCH v3 4/7] tools/genboardscfg.py: wait for unfinished subprocesses before error-out Masahiro Yamada
2014-08-29 14:41   ` [U-Boot] [U-Boot, v3, " Tom Rini
2014-08-25  3:39 ` [U-Boot] [PATCH v3 5/7] tools/genboardscfg.py: fix minor problems on termination Masahiro Yamada
2014-08-29 14:41   ` [U-Boot] [U-Boot, v3, " Tom Rini
2014-08-25  3:39 ` Masahiro Yamada [this message]
2014-08-29 14:41   ` [U-Boot] [U-Boot, v3, 6/7] tools/genboardscfg.py: check if the boards.cfg is up to date Tom Rini
2014-08-25  3:39 ` [U-Boot] [PATCH v3 7/7] tools/genboardscfg.py: improve performance Masahiro Yamada
2014-08-29 14:41   ` [U-Boot] [U-Boot, v3, " Tom Rini

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1408937988-19923-7-git-send-email-yamada.m@jp.panasonic.com \
    --to=yamada.m@jp.panasonic.com \
    --cc=u-boot@lists.denx.de \
    /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.
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 NNTP newsgroup(s).