From d8576f60af14ea39d9cc2138cbd0310b6975b055 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Sat, 3 Mar 2018 22:27:54 +0100 Subject: Simplify initial auto.conf setup Instead of creating an empty initial auto.conf and immediately loading it, look for a missing auto.conf in _load_old_vals() and treat that the same as an empty auto.conf (by returning after clearing the old values). The initial auto.conf will then be written as normal by _write_old_vals(). Also flesh out the sync_deps() docstring a bit: - Make it clear that sync_deps() should be run at each build - Be more explicit about what it means for a symbol to have changed (different output in autoconf.h) --- kconfiglib.py | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/kconfiglib.py b/kconfiglib.py index 9b83070..ae0b376 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -967,6 +967,9 @@ class Kconfig(object): doing a full rebuild whenever the configuration is changed, mirroring include/config/ in the kernel. + This function is intended to be called during each build, before + compiling source files that depend on configuration symbols. + path: Path to directory @@ -974,16 +977,16 @@ class Kconfig(object): 1. If the directory does not exist, it is created. - 2. If no /auto.conf file exists, an initially empty auto.conf - is created. - - auto.conf keeps track of the old symbol values from the previous - build. The format mirrors .config. + 2. If /auto.conf exists, old symbol values are loaded from it, + which are then compared against the current symbol values. If a + symbol has changed value (would generate different output in + autoconf.h compared to before), the change is signaled by + touch'ing a file corresponding to the symbol. - 3. auto.conf is loaded, and the old symbol values in it are compared - against the current symbol values. If a symbol has changed value, - the change is signaled by touch'ing a file corresponding to the - symbol. + The first time sync_deps() is run on a directory, /auto.conf + won't exist, and no old symbol values will be available. This + logically has the same effect as updating the entire + configuration. The path to a symbol's file is calculated from the symbol's name by replacing all '_' with '/' and appending '.h'. For example, the @@ -994,8 +997,8 @@ class Kconfig(object): single directory with a huge number of files, which the underlying filesystem might not handle well. - 4. A new auto.conf is written to keep track of the current symbol - values for the next build. + 3. A new auto.conf with the current symbol values is written, to keep + track of them for the next build. The last piece of the puzzle is knowing what symbols each source file @@ -1014,10 +1017,6 @@ class Kconfig(object): if not os.path.exists(path): os.mkdir(path, 0o755) - auto_conf = os.path.join(path, "auto.conf") - if not os.path.exists(auto_conf): - open(auto_conf, "w").close() - # This setup makes sure that at least the current working directory # gets reset if things fail prev_dir = os.getcwd() @@ -1030,7 +1029,7 @@ class Kconfig(object): os.chdir(prev_dir) def _sync_deps(self): - # Load old values from auto.conf + # Load old values from auto.conf, if any self._load_old_vals() for sym in self.defined_syms: @@ -1103,10 +1102,15 @@ class Kconfig(object): # The extra field could be avoided with some trickery involving dumping # symbol values and restoring them later, but this is simpler and # faster. The C tools also use a dedicated field for this purpose. - with open("auto.conf", _UNIVERSAL_NEWLINES_MODE) as f: - for sym in self.defined_syms: - sym._old_val = None + for sym in self.defined_syms: + sym._old_val = None + + if not os.path.exists("auto.conf"): + # No old values + return + + with open("auto.conf", _UNIVERSAL_NEWLINES_MODE) as f: for line in f: set_match = self._set_re_match(line) if not set_match: -- cgit v1.2.3