Skip to contentSkip to conversation

bitbake: data.py: convert "__" to "-" for PREFERRED_VERSION

PATCH In review Robert Yang 3 participants 7 messages Jan 13, 2014 – Jan 14, 2014

lore
Share & tools
lore
#0 lore raw

cover bitbake: data.py: convert "__" to "-" for PREFERRED_VERSION

The following changes since commit 6ee5d95317de77c1cfb6db6f1ab2de77f5fa085e:

bitbake: fetch2/gitannex: Fix function arguments to match bitbake master (2014-01-08 15:27:37 +0000)

are available in the git repository at:

git://git.pokylinux.org/poky-contrib rbt/pv
http://git.pokylinux.org/cgit.cgi/poky-contrib/log/?h=rbt/pv

Robert Yang (1):
bitbake: data.py: convert "__" to "-" for PREFERRED_VERSION

 bitbake/lib/bb/data.py |   11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 1/1 bitbake: data.py: convert "__" to "-" for PREFERRED_VERSION

We can set the PREFERRED_VERSION from the command line:

$ export BB_PRESERVE_ENV=1
$ PREFERRED_VERSION_recipe="pv" bitbake recipe

But it doesn't work if the recipe name contain the "-" since we can't use "-" in shell's variable name, use '__' instead of '-' in the env will make it work.

We also need update the doc, I will mark the bug as "doc changes required".

[YOCTO #4965]

---
 bitbake/lib/bb/data.py |   11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
bitbake/lib/bb/data.py +10 -1
index 5840803..666cdcb 100644
@@ -171,11 +171,20 @@ def expandKeys(alterdata, readdata = None):
 
 def inheritFromOS(d, savedenv, permitted):
     """Inherit variables from the initial environment."""
+    # We can set the PREFERRED_VERSION_recipe from the shell env, but we
+    # can't use "-" in shell's variable name, so we use '__' instead of
+    # '-' in the env, and translate it back here.
+    preferred_version_re = re.compile('PREFERRED_VERSION_.*__')
+
     exportlist = bb.utils.preserved_envvars_exported()
     for s in savedenv.keys():
         if s in permitted:
             try:
-                d.setVar(s, getVar(s, savedenv, True), op = 'from env')
+                if preferred_version_re.match(s):
+                    s_new = s.replace('__', '-')
+                    d.setVar(s_new, getVar(s, savedenv, True), op = 'from env')
+                else:
+                    d.setVar(s, getVar(s, savedenv, True), op = 'from env')
                 if s in exportlist:
                     d.setVarFlag(s, "export", True, op = 'auto env export')
             except TypeError:
Signature · 1 line
1.7.10.4
#2 lore raw
Quoted 36 lines · Robert Yang

We can set the PREFERRED_VERSION from the command line:

$ export BB_PRESERVE_ENV=1
$ PREFERRED_VERSION_recipe="pv" bitbake recipe

But it doesn't work if the recipe name contain the "-" since we can't use "-" in shell's variable name, use '__' instead of '-' in the env will make it work.

We also need update the doc, I will mark the bug as "doc changes required".

[YOCTO #4965]

---
  bitbake/lib/bb/data.py |   11 ++++++++++-
  1 file changed, 10 insertions(+), 1 deletion(-)
bitbake/lib/bb/data.py +5 -0
index 5840803..666cdcb 100644
@@ -171,11 +171,20 @@ def expandKeys(alterdata, readdata = None):
 
  def inheritFromOS(d, savedenv, permitted):
      """Inherit variables from the initial environment."""
+    # We can set the PREFERRED_VERSION_recipe from the shell env, but we
+    # can't use "-" in shell's variable name, so we use '__' instead of
+    # '-' in the env, and translate it back here.
+    preferred_version_re = re.compile('PREFERRED_VERSION_.*__')
+
      exportlist = bb.utils.preserved_envvars_exported()
      for s in savedenv.keys():
          if s in permitted:

bitbake/lib/bb/data.py def expandKeys(alterdata, readdata = None): · line 190

Quoted 10 lines
bitbake/lib/bb/data.py +5 -1
              try:
-                d.setVar(s, getVar(s, savedenv, True), op = 'from env')
+                if preferred_version_re.match(s):
+                    s_new = s.replace('__', '-')
+                    d.setVar(s_new, getVar(s, savedenv, True), op = 'from env')
+                else:
+                    d.setVar(s, getVar(s, savedenv, True), op = 'from env')
                  if s in exportlist:
                      d.setVarFlag(s, "export", True, op = 'auto env export')
              except TypeError:

Are you sure this is correct for the 's in exportlist' case?

Perhaps the change should look like this (which is also easier to read):
@@ -175,6 +175,8 @@ def inheritFromOS(d, savedenv, permitted):
for s in savedenv.keys():
if s in permitted:
try:
+ if preferred_version_re.match(s):
+ s = s.replace('__', '-')
d.setVar(s, getVar(s, savedenv, True), op = 'from env') if s in exportlist:
d.setVarFlag(s, "export", True, op = 'auto env export')

Signature · 4 lines
------------------------------------------------------------
Gary Thomas                 |  Consulting for the
MLB Associates              |    Embedded world
------------------------------------------------------------
#3 lore raw
Quoted 41 lines · Gary Thomas
Quoted 40 lines · Robert Yang

We can set the PREFERRED_VERSION from the command line:

$ export BB_PRESERVE_ENV=1
$ PREFERRED_VERSION_recipe="pv" bitbake recipe

But it doesn't work if the recipe name contain the "-" since we can't use "-" in shell's variable name, use '__' instead of '-' in the env will make it work.

We also need update the doc, I will mark the bug as "doc changes required".

[YOCTO #4965]

---
  bitbake/lib/bb/data.py |   11 ++++++++++-
  1 file changed, 10 insertions(+), 1 deletion(-)
bitbake/lib/bb/data.py +8 -1
index 5840803..666cdcb 100644
@@ -171,11 +171,20 @@ def expandKeys(alterdata, readdata = None):
 
  def inheritFromOS(d, savedenv, permitted):
      """Inherit variables from the initial environment."""
+    # We can set the PREFERRED_VERSION_recipe from the shell env, but we
+    # can't use "-" in shell's variable name, so we use '__' instead of
+    # '-' in the env, and translate it back here.
+    preferred_version_re = re.compile('PREFERRED_VERSION_.*__')
+
      exportlist = bb.utils.preserved_envvars_exported()
      for s in savedenv.keys():
          if s in permitted:
              try:
-                d.setVar(s, getVar(s, savedenv, True), op = 'from env')
+                if preferred_version_re.match(s):
+                    s_new = s.replace('__', '-')
+                    d.setVar(s_new, getVar(s, savedenv, True), op = 'from env')
Quoted 9 lines

bitbake/lib/bb/data.py def expandKeys(alterdata, readdata = None): · line 190

Quoted 6 lines
bitbake/lib/bb/data.py +2 -0
+                else:
+                    d.setVar(s, getVar(s, savedenv, True), op = 'from env')
                  if s in exportlist:
                      d.setVarFlag(s, "export", True, op = 'auto env export')
              except TypeError:

Are you sure this is correct for the 's in exportlist' case?

Yes, I think so, the exportlist contains constant:

['BB_TASKHASH', 'HOME', 'LOGNAME', 'PATH', 'PWD', 'SHELL', 'TERM', 'USER']

So we don't have to worry about it.

bitbake/lib/bb/data.py def inheritFromOS(d, savedenv, permitted): · line 180

Quoted 8 lines

Perhaps the change should look like this (which is also easier to read):

bitbake/lib/bb/data.py +2 -0
@@ -175,6 +175,8 @@ def inheritFromOS(d, savedenv, permitted):
      for s in savedenv.keys():
          if s in permitted:
              try:
+                if preferred_version_re.match(s):
+                    s = s.replace('__', '-')
                  d.setVar(s, getVar(s, savedenv, True), op = 'from env')

We must need the s_new (or s_to) here, because:

d.setVar(s_to, getVar(s_from, savedenv, True), xxx)

the s_to and s_from are different.

// Robert

Quoted 3 lines
bitbake/lib/bb/data.py +0 -0
                  if s in exportlist:
                      d.setVarFlag(s, "export", True, op = 'auto env export')
#4 lore raw
In reply to Robert Yang
Quoted 12 lines · Robert Yang

We can set the PREFERRED_VERSION from the command line:

$ export BB_PRESERVE_ENV=1
$ PREFERRED_VERSION_recipe="pv" bitbake recipe

But it doesn't work if the recipe name contain the "-" since we can't use "-" in shell's variable name, use '__' instead of '-' in the env will make it work.

We also need update the doc, I will mark the bug as "doc changes required".

Quoted 6 lines

[YOCTO #4965]

---
 bitbake/lib/bb/data.py |   11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

Should we do this just for PREFERRED_VERSION or all environment variables? I can't think of a case we'd use __ currently but I can think of other variable names where this mapping would help...

Any strong opinions?

Cheers,

Richard

Quoted 26 lines
bitbake/lib/bb/data.py +10 -1
index 5840803..666cdcb 100644
@@ -171,11 +171,20 @@ def expandKeys(alterdata, readdata = None):
 
 def inheritFromOS(d, savedenv, permitted):
     """Inherit variables from the initial environment."""
+    # We can set the PREFERRED_VERSION_recipe from the shell env, but we
+    # can't use "-" in shell's variable name, so we use '__' instead of
+    # '-' in the env, and translate it back here.
+    preferred_version_re = re.compile('PREFERRED_VERSION_.*__')
+
     exportlist = bb.utils.preserved_envvars_exported()
     for s in savedenv.keys():
         if s in permitted:
             try:
-                d.setVar(s, getVar(s, savedenv, True), op = 'from env')
+                if preferred_version_re.match(s):
+                    s_new = s.replace('__', '-')
+                    d.setVar(s_new, getVar(s, savedenv, True), op = 'from env')
+                else:
+                    d.setVar(s, getVar(s, savedenv, True), op = 'from env')
                 if s in exportlist:
                     d.setVarFlag(s, "export", True, op = 'auto env export')
             except TypeError:
#5 lore raw
Quoted 20 lines · Richard Purdie
Quoted 12 lines · Robert Yang

We can set the PREFERRED_VERSION from the command line:

$ export BB_PRESERVE_ENV=1
$ PREFERRED_VERSION_recipe="pv" bitbake recipe

But it doesn't work if the recipe name contain the "-" since we can't use "-" in shell's variable name, use '__' instead of '-' in the env will make it work.

We also need update the doc, I will mark the bug as "doc changes required".

Quoted 6 lines

[YOCTO #4965]

---
  bitbake/lib/bb/data.py |   11 ++++++++++-
  1 file changed, 10 insertions(+), 1 deletion(-)
Quoted 6 lines

Should we do this just for PREFERRED_VERSION or all environment variables? I can't think of a case we'd use __ currently but I can think of other variable names where this mapping would help...

Any strong opinions?

Sounds good, I will send a V2.

// Robert

Quoted 34 lines

Cheers,

Richard

Quoted 26 lines
bitbake/lib/bb/data.py +10 -1
index 5840803..666cdcb 100644
@@ -171,11 +171,20 @@ def expandKeys(alterdata, readdata = None):
 
  def inheritFromOS(d, savedenv, permitted):
      """Inherit variables from the initial environment."""
+    # We can set the PREFERRED_VERSION_recipe from the shell env, but we
+    # can't use "-" in shell's variable name, so we use '__' instead of
+    # '-' in the env, and translate it back here.
+    preferred_version_re = re.compile('PREFERRED_VERSION_.*__')
+
      exportlist = bb.utils.preserved_envvars_exported()
      for s in savedenv.keys():
          if s in permitted:
              try:
-                d.setVar(s, getVar(s, savedenv, True), op = 'from env')
+                if preferred_version_re.match(s):
+                    s_new = s.replace('__', '-')
+                    d.setVar(s_new, getVar(s, savedenv, True), op = 'from env')
+                else:
+                    d.setVar(s, getVar(s, savedenv, True), op = 'from env')
                  if s in exportlist:
                      d.setVarFlag(s, "export", True, op = 'auto env export')
              except TypeError:
#6 lore raw
In reply to Richard Purdie

I've update the PULL, changes:

1) Not only for the PREFERRED_VERSION, but for all env vars.
2) Also take care of the exportlist, though we don't have to care about it currently, but maybe in the future.

git://git.pokylinux.org/poky-contrib rbt/pv

// Robert

Quoted 60 lines · Richard Purdie
Quoted 12 lines · Robert Yang

We can set the PREFERRED_VERSION from the command line:

$ export BB_PRESERVE_ENV=1
$ PREFERRED_VERSION_recipe="pv" bitbake recipe

But it doesn't work if the recipe name contain the "-" since we can't use "-" in shell's variable name, use '__' instead of '-' in the env will make it work.

We also need update the doc, I will mark the bug as "doc changes required".

Quoted 6 lines

[YOCTO #4965]

---
  bitbake/lib/bb/data.py |   11 ++++++++++-
  1 file changed, 10 insertions(+), 1 deletion(-)

Should we do this just for PREFERRED_VERSION or all environment variables? I can't think of a case we'd use __ currently but I can think of other variable names where this mapping would help...

Any strong opinions?

Cheers,

Richard

Quoted 26 lines
bitbake/lib/bb/data.py +10 -1
index 5840803..666cdcb 100644
@@ -171,11 +171,20 @@ def expandKeys(alterdata, readdata = None):
 
  def inheritFromOS(d, savedenv, permitted):
      """Inherit variables from the initial environment."""
+    # We can set the PREFERRED_VERSION_recipe from the shell env, but we
+    # can't use "-" in shell's variable name, so we use '__' instead of
+    # '-' in the env, and translate it back here.
+    preferred_version_re = re.compile('PREFERRED_VERSION_.*__')
+
      exportlist = bb.utils.preserved_envvars_exported()
      for s in savedenv.keys():
          if s in permitted:
              try:
-                d.setVar(s, getVar(s, savedenv, True), op = 'from env')
+                if preferred_version_re.match(s):
+                    s_new = s.replace('__', '-')
+                    d.setVar(s_new, getVar(s, savedenv, True), op = 'from env')
+                else:
+                    d.setVar(s, getVar(s, savedenv, True), op = 'from env')
                  if s in exportlist:
                      d.setVarFlag(s, "export", True, op = 'auto env export')
              except TypeError: