diff mbox series

[layerindex-web,1/3] update: don't print the initial layer.conf values

Message ID 20261114022637.60789-2-tim.orling@konsulko.com
State Under Review
Delegated to: Tim Orling
Headers show
Series Report problems with the first parse of a layer | expand

Commit Message

Tim Orling Nov. 14, 2026, 2:26 a.m. UTC
update.py gets BBFILE_COLLECTIONS, LAYERVERSION, LAYERDEPENDS and
LAYERRECOMMENDS for each layer by running update_layer.py --initial,
which printed them, so they appeared on the console and in the update
log of every layer. Have update_layer.py write them to a file that
update.py names instead; errors are still shown as before.

[YOCTO #12130]

AI-Generated: Claude Opus 5.5
Signed-off-by: Tim Orling <tim.orling@konsulko.com>
---
 layerindex/update.py       | 23 +++++++++++++++--------
 layerindex/update_layer.py | 12 +++++++-----
 tests/test_update.py       | 11 +++++++++++
 3 files changed, 33 insertions(+), 13 deletions(-)
diff mbox series

Patch

diff --git a/layerindex/update.py b/layerindex/update.py
index ca68e3e..ccf44a3 100755
--- a/layerindex/update.py
+++ b/layerindex/update.py
@@ -16,6 +16,8 @@  import optparse
 import codecs
 import logging
 import subprocess
+import shlex
+import tempfile
 from datetime import datetime, timedelta
 from packaging_legacy.version import parse as parse_version
 import utils
@@ -36,7 +38,7 @@  except ImportError:
     sys.exit(1)
 
 
-def prepare_update_layer_command(options, branch, layer, initial=False):
+def prepare_update_layer_command(options, branch, layer, initial=None):
     """Prepare the update_layer.py command line"""
     if branch.update_environment:
         cmdprefix = branch.update_environment.get_command()
@@ -54,7 +56,7 @@  def prepare_update_layer_command(options, branch, layer, initial=False):
     if options.dryrun:
         cmd += ' -n'
     if initial:
-        cmd += ' -i'
+        cmd += ' -i %s' % shlex.quote(initial)
     if options.loglevel == logging.DEBUG:
         cmd += ' -d'
     elif options.loglevel == logging.ERROR:
@@ -448,10 +450,15 @@  def main():
                             logger.error("conf/layer.conf not found for layer %s (branch %s) - is subdirectory set correctly?" % (layer.name, branch))
                             continue
 
-                    cmd = prepare_update_layer_command(options, branchobj, layer, initial=True)
+                    fd, initial_fn = tempfile.mkstemp(prefix='layerindex-initial-')
+                    os.close(fd)
+                    cmd = prepare_update_layer_command(options, branchobj, layer, initial=initial_fn)
                     logger.debug('Running layer update command: %s' % cmd)
                     ret, output = utils.run_command_interruptible(cmd)
                     logger.debug('output: %s' % output)
+                    with open(initial_fn) as f:
+                        initial_values = f.read()
+                    os.remove(initial_fn)
                     if ret == 254:
                         # Interrupted by user, break out of loop
                         logger.info('Update interrupted, exiting')
@@ -470,14 +477,14 @@  def main():
                             layerupdate.save()
                         continue
 
-                    col = extract_value('BBFILE_COLLECTIONS', output)
+                    col = extract_value('BBFILE_COLLECTIONS', initial_values)
                     if not col:
-                        logger.error('Unable to find BBFILE_COLLECTIONS value in initial output')
+                        logger.error('Unable to find BBFILE_COLLECTIONS value in initial values')
                         # Assume (perhaps naively) that it's an error specific to the layer
                         continue
-                    ver = extract_value('LAYERVERSION', output)
-                    deps = extract_value('LAYERDEPENDS', output)
-                    recs = extract_value('LAYERRECOMMENDS', output)
+                    ver = extract_value('LAYERVERSION', initial_values)
+                    deps = extract_value('LAYERDEPENDS', initial_values)
+                    recs = extract_value('LAYERRECOMMENDS', initial_values)
 
                     if not options.nocheckout:
                         # We need to check this out because we're using stuff from bb.utils
diff --git a/layerindex/update_layer.py b/layerindex/update_layer.py
index 0f49371..c11c002 100644
--- a/layerindex/update_layer.py
+++ b/layerindex/update_layer.py
@@ -290,8 +290,8 @@  def main():
             help = "Stop on first parsing error",
             action="store_true", default=False, dest="stop_on_error")
     parser.add_option("-i", "--initial",
-            help = "Print initial values parsed from layer.conf only",
-            action="store_true")
+            help = "Write the initial values parsed from layer.conf to FILE, and do nothing else",
+            action="store", metavar="FILE")
     parser.add_option("-a", "--actual-branch",
             help = "Specify actual_branch for git checkout",
             action="store", dest="actual_branch", default=None)
@@ -454,9 +454,11 @@  def main():
                     sys.exit(1)
                 utils.set_layerbranch_collection_version(layerbranch, layer_config_data, logger=logger)
                 if options.initial:
-                    # Use print() rather than logger.info() since "-q" makes it print nothing.
-                    for i in ["BBFILE_COLLECTIONS", "LAYERVERSION", "LAYERDEPENDS", "LAYERRECOMMENDS"]:
-                        print('%s = "%s"' % (i, utils.get_layer_var(layer_config_data, i, logger)))
+                    # Write these to a file rather than the output, which is
+                    # shown on the console and in the update log
+                    with open(options.initial, 'w') as f:
+                        for i in ["BBFILE_COLLECTIONS", "LAYERVERSION", "LAYERDEPENDS", "LAYERRECOMMENDS"]:
+                            f.write('%s = "%s"\n' % (i, utils.get_layer_var(layer_config_data, i, logger)))
                     sys.exit(0)
 
                 # Set up for recording patch info
diff --git a/tests/test_update.py b/tests/test_update.py
index a0ac897..1e1db0d 100644
--- a/tests/test_update.py
+++ b/tests/test_update.py
@@ -163,6 +163,17 @@  def test_add_recipe(import_layer, repo, db_access_without_rollback_and_truncate)
     assert recipe.summary == "Brand new recipe"
     assert recipe.license == "MIT"
 
+def test_initial_values_not_in_output(import_layer):
+    # [YOCTO #12130] update.py gets the values it needs from the first parse
+    # of conf/layer.conf through a file, not from the output it shows
+    result = subprocess.run("layerindex/update.py -r -n -l meta-layerindex-test --nofetch --nocheckout",
+                            shell=True, cwd=basepath, stdout=subprocess.PIPE,
+                            stderr=subprocess.STDOUT, text=True)
+    assert result.returncode == 0, result.stdout
+    assert 'BBFILE_COLLECTIONS = ' not in result.stdout
+    assert 'Unable to find BBFILE_COLLECTIONS' not in result.stdout
+
+
 
 
 # FIXME test recipe modify