Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Python variables defined in scripts sourced by include_defs() are not known any more #221

Closed
davido opened this issue Nov 21, 2014 · 3 comments

Comments

@davido
Copy link
Contributor

davido commented Nov 21, 2014

Gerrit Code Review supports two different modes for building plugins: in Gerrit tree and standalone modes. For this to work, we defined __standalone_mode__ variable and setting it differently in different modes. I am sure it worked already, but stopped working in recent Buck version:

Given the following BUCK file:

include_defs('//foo')
baz = 'qux' if __bar__ else 'quux'

def custom(
    name,
    dest):
  genrule(
    name = name,
    cmd = 'cd $TMP;' +
      ('mkdir -p `dirname %s`;' % '$OUT') +
       'echo %s >$OUT' % baz,
    out = dest,
  )

custom(
  name = 'foo',
  dest = 'bar/baz/qux.txt',
)

and this definition of foo:

__bar__ = True

__bar__ is not visible any more in root BUCK file, where the include file was sourced from:

$ buck build :foo
Using buckd.
Traceback (most recent call last):
[...]
  File "/home/davido/projects/buck_include_problem/BUCK", line 3, in <module>
    baz = 'qux' if __bar__ else 'quux'
NameError: name '__bar__' is not defined

Expected: it should just work and produce:

$ buck build :foo
Using buckd.
[-] PROCESSING BUCK FILES...FINISHED 0,0s
[-] BUILDING...FINISHED 0,0s (1/1 JOBS)

$ cat buck-out/gen/bar/baz/qux.txt
qux
@sdwilsh
Copy link
Contributor

sdwilsh commented Nov 21, 2014

@andrewjcg, I suspect this is related to your import changes, yeah?

@andrewjcg
Copy link
Contributor

Ah yeah, this was caused by 6064096, which made "include_defs()" behave more like "from ___ import *", which doesn't import variables with leading underscores. In this case, is it ok to change the name of the variable to not use leading underscores. Sorry for the churn here.

@davido
Copy link
Contributor Author

davido commented Nov 22, 2014

Thanks. Will rename it then.

@davido davido closed this as completed Nov 22, 2014
openstack-gerrit pushed a commit to openstack-infra/gerrit that referenced this issue Nov 25, 2014
The fix for [1] prevents from importing python variables __foo__,
as explained in [2]. Rename standalone mode flag correspondingly.

[1] facebook/buck#182
[2] facebook/buck#221

Change-Id: If8682278e7c91df3fc18b3d623eb43950e839448
davido added a commit to davido/bucklets that referenced this issue Mar 21, 2015
The fix for [1] prevents from importing python variables __foo__,
as explained in [2]. Rename standalone mode flag correspondingly.

[1] facebook/buck#182
[2] facebook/buck#221

Change-Id: I0ac05c80a1d5fc1b8f8bd2c5ca5dabdfeeecbe52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants