<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugzilla.yoctoproject.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugzilla.yoctoproject.org/"
          
          maintainer="it-coreprojects-helpdesk@linuxfoundation.org"
>

    <bug>
          <bug_id>10748</bug_id>
          
          <creation_ts>2016-11-30 20:01:41 +0000</creation_ts>
          <short_desc>Means of querying history for a single variable</short_desc>
          <delta_ts>2021-05-06 18:48:42 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>7</classification_id>
          <classification>Build System, Metadata &amp; Runtime</classification>
          <product>BitBake</product>
          <component>bitbake</component>
          <version>2.2</version>
          <rep_platform>x86</rep_platform>
          <op_sys>Multiple</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>Medium+</priority>
          <bug_severity>enhancement</bug_severity>
          <target_milestone>3.4 M1</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Paul Eggleton">bluelightning</reporter>
          <assigned_to name="Richard Purdie">richard.purdie</assigned_to>
          <cc>kergoth</cc>
    
    <cc>mariano.lopez</cc>
    
    <cc>poky.bs.watcher</cc>
    
    <cc>poky.watcher</cc>
    
    <cc>tvgamblin</cc>
          
          
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>Yes (doc changes required)</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>68754</commentid>
    <comment_count>0</comment_count>
    <who name="Paul Eggleton">bluelightning</who>
    <bug_when>2016-11-30 20:01:41 +0000</bug_when>
    <thetext>bitbake -e is very useful, but it has a couple of drawbacks:

1) It lists absolutely everything, when most of the time what you want is the history for a single variable. People are used to piping the output through grep but that is only useful for a single variable, and sometimes not even that (see below). Usually I tell people to do what I do which is to pipe it through less and search for the variable, but then many people aren&apos;t even aware that less has search capabilities.

2) The final values of some commonly used variables such as DISTRO and MACHINE are excluded. I understand why that is - bitbake is showing you what the environment will look like and these variables are marked &quot;unexport&quot; so that is expected. However, that&apos;s not what most people want to see and it also makes it harder to search for the variable in the output.

It would be nice if we had a dedicated means (perhaps a separate tool) for querying the history / value of a variable. This would be trivial to implement with tinfoil.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>68755</commentid>
    <comment_count>1</comment_count>
    <who name="Paul Eggleton">bluelightning</who>
    <bug_when>2016-11-30 20:02:31 +0000</bug_when>
    <thetext>s/only useful for a single variable/only useful in order to see the final value/</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>69302</commentid>
    <comment_count>2</comment_count>
    <who name="Paul Eggleton">bluelightning</who>
    <bug_when>2016-12-22 02:39:00 +0000</bug_when>
    <thetext>*** Bug 10830 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>69303</commentid>
    <comment_count>3</comment_count>
    <who name="Paul Eggleton">bluelightning</who>
    <bug_when>2016-12-22 02:40:14 +0000</bug_when>
    <thetext>A specific additional requirement derived from bug 10830 - have a mode that just prints the value of the variable or &quot;&quot; if there is no value.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>74865</commentid>
    <comment_count>4</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2017-07-07 15:04:49 +0000</bug_when>
    <thetext>https://gist.github.com/kergoth/4133101

(15:02:57) RP: kergoth: I&apos;m tempted to add that to bitbake itself, maybe as &quot;bitbake-var&quot; as users probably see this as variables, not an environment. Any thoughts on that?

kergoth: zero_note: bitbake-env went away in favor of a subcommand (show) of the &apos;bb&apos; experimental sub-command based utility, which is currently broken and not yet fixed due to changes in tinfoil (bitbake&apos;s library used for external utilities). also neither of them supported the new variable tracking mechanism. but yes, i think
(16:10:59) kergoth: RP: it&apos;s not a bad idea. I&apos;d still like to prototype integration of a sub-command based cli ui, but that can always be a future step, it&apos;s clear bitbake-env/bb-show provides value on its own, bitbake -e | grep is common and quite ugly
(16:17:57) RP: kergoth: agreed on a cli, I still have shell.py around as a partial inspiration for that and this wouldn&apos;t preclude that
(16:19:24) kergoth: zero_note, RP: I was never 100% happy with the interface of that tool, for what it&apos;s worth. for scripting, you really also want the ability to see *just the value* of the variable, rather than having to sed out the quotes and whatnot, but then what&apos;s the behavior if you set that and pass multiple variables? could just error, but that doesn&apos;t seem super clean.. also it would need variable tracking support added, and desperately needs the ability to
(16:19:24) kergoth:  accept FOO[bar] syntax to see specific flags rather than having to look at all flags for a specified variable..
(16:20:30) zero_note: imho, bitbake -e recipe | grep become usable only after several times of usage, when one knows how to customize the grep reg expression
(16:20:31) RP: kergoth: some kind of stripped output or value only shouldn&apos;t be too difficult and yes, those other things are valid issues
(16:21:06) kergoth: zero_note: yeah. you can write a shell function to semi-automate it, but only for the common case, it doesn&apos;t scale well, and is rather brittle
(16:25:34) kergoth: would also be nice to be able to get the unexpanded value without having to grep out the commented section, and a better way to extract the varaible tracking data for a particular variable in a more script-friendly format..
(16:25:54) kergoth: being limited to the shell-like output bitbake -e provides isn&apos;t ideal — there&apos;s a reason we did it that way, but..
(16:26:13) kergoth: at any rate, i do think we should integrate such a script, but i&apos;d like to see a discussion about the details
(16:27:46) kergoth: the upside to the current behavior is the output is nearly in bitbake metadata format. that&apos;s a possibility, too, for the variable tracking — it could optionally emit the multiple bitbake format lines that led to the final value, rather than the final assignment itself</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>89970</commentid>
    <comment_count>5</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2021-04-16 15:03:07 +0000</bug_when>
    <thetext>A quick hacky implementation (which needs a fix to the tinfoil variable history emit function):

#! /usr/bin/env python3

import argparse
import io
import os
import sys

scripts_path = os.path.dirname(os.path.realpath(__file__))
lib_path = scripts_path + &quot;/lib&quot;
sys.path.insert(0, lib_path)
import scriptpath
scriptpath.add_bitbake_lib_path()
scriptpath.add_oe_lib_path()

import bb.tinfoil

if __name__ == &quot;__main__&quot;:
    parser = argparse.ArgumentParser(description=&quot;Bitbake Get Variable&quot;)
    parser.add_argument(&quot;variable&quot;, help=&quot;variable name to query&quot;)
    parser.add_argument(&quot;-r&quot;, &quot;--recipe&quot;, help=&quot;recipe name&quot;, default=None, required=False)
    args = parser.parse_args()

    with bb.tinfoil.Tinfoil(tracking=True) as tinfoil:
        if not args.recipe:
            tinfoil.prepare(quiet=2, config_only=True)
            bb.data.emit_var(args.variable, d=tinfoil.config_data, all=True)
        else:
            tinfoil.prepare(quiet=2)
            d = tinfoil.parse_recipe(args.recipe)
            bb.data.emit_var(args.variable, d=d, all=True)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>89974</commentid>
    <comment_count>6</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2021-04-16 17:12:01 +0000</bug_when>
    <thetext>I&apos;ve sent out patches for this with a bit more cleanup</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>90310</commentid>
    <comment_count>7</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2021-05-06 18:48:42 +0000</bug_when>
    <thetext>http://git.yoctoproject.org/cgit.cgi/poky/commit/?id=7bbeddeee1992d8c8fb71ba2dd49b03d0ae1ce86</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>