@@ -1444,12 +1444,18 @@ def write_autoconf(self, filename=None, header=None):
1444
1444
KCONFIG_AUTOHEADER_HEADER had when the Kconfig instance was created
1445
1445
will be used if it was set, and no header otherwise. See the
1446
1446
Kconfig.header_header attribute.
1447
+
1448
+ Returns a string with a message saying that the header got saved, or
1449
+ that there were no changes to it. This is meant to reduce boilerplate
1450
+ in tools, which can do e.g. print(kconf.write_autoconf()).
1447
1451
"""
1448
1452
if filename is None :
1449
1453
filename = os .getenv ("KCONFIG_AUTOHEADER" ,
1450
1454
"include/generated/autoconf.h" )
1451
1455
1452
- self ._write_if_changed (filename , self ._autoconf_contents (header ))
1456
+ if self ._write_if_changed (filename , self ._autoconf_contents (header )):
1457
+ return "Kconfig header saved to '{}'" .format (filename )
1458
+ return "No change to Kconfig header in '{}'" .format (filename )
1453
1459
1454
1460
def _autoconf_contents (self , header ):
1455
1461
# write_autoconf() helper. Returns the contents to write as a string,
@@ -1564,7 +1570,7 @@ def write_config(self, filename=None, header=None, save_old=True,
1564
1570
1565
1571
contents = self ._config_contents (header )
1566
1572
if self ._contents_eq (filename , contents ):
1567
- return "No change to '{}'" .format (filename )
1573
+ return "No change to configuration in '{}'" .format (filename )
1568
1574
1569
1575
if save_old :
1570
1576
_save_old (filename )
@@ -1677,18 +1683,14 @@ def write_min_config(self, filename, header=None):
1677
1683
be used if it was set, and no header otherwise. See the
1678
1684
Kconfig.config_header attribute.
1679
1685
1680
- Returns a string with a message saying which file got saved. This is
1681
- meant to reduce boilerplate in tools, which can do e.g.
1686
+ Returns a string with a message saying the minimal configuration got
1687
+ saved, or that there were no changes to it. This is meant to reduce
1688
+ boilerplate in tools, which can do e.g.
1682
1689
print(kconf.write_min_config()).
1683
1690
"""
1684
- contents = self ._min_config_contents (header )
1685
- if self ._contents_eq (filename , contents ):
1686
- return "No change to '{}'" .format (filename )
1687
-
1688
- with self ._open (filename , "w" ) as f :
1689
- f .write (contents )
1690
-
1691
- return "Minimal configuration saved to '{}'" .format (filename )
1691
+ if self ._write_if_changed (filename , self ._min_config_contents (header )):
1692
+ return "Minimal configuration saved to '{}'" .format (filename )
1693
+ return "No change to minimal configuration in '{}'" .format (filename )
1692
1694
1693
1695
def _min_config_contents (self , header ):
1694
1696
# write_min_config() helper. Returns the contents to write as a string,
@@ -2264,10 +2266,15 @@ def _write_if_changed(self, filename, contents):
2264
2266
# differs, but it breaks stuff like write_config("/dev/null"), which is
2265
2267
# used out there to force evaluation-related warnings to be generated.
2266
2268
# This simple version is pretty failsafe and portable.
2269
+ #
2270
+ # Returns True if the file has changed and is updated, and False
2271
+ # otherwise.
2267
2272
2268
- if not self ._contents_eq (filename , contents ):
2269
- with self ._open (filename , "w" ) as f :
2270
- f .write (contents )
2273
+ if self ._contents_eq (filename , contents ):
2274
+ return False
2275
+ with self ._open (filename , "w" ) as f :
2276
+ f .write (contents )
2277
+ return True
2271
2278
2272
2279
def _contents_eq (self , filename , contents ):
2273
2280
# Returns True if the contents of 'filename' is 'contents' (a string),
0 commit comments