unbound variable problem.

498 views
Skip to first unread message

Francis Hitchens

unread,
Apr 3, 2017, 1:44:32 PM4/3/17
to bazel-discuss
Hi.

I have a pre-processor that requires an absolute path in the parameters that need to be passed to it for include directories.

I used the bazel info --show_make_env command
ABI: local
ABI_GLIBC_VERSION: local
ANDROID_CPU: armeabi
AR: /usr/bin/ar
BINDIR: bazel-out/local-fastbuild/bin
CC: /usr/bin/gcc
.
.
.
workspace: /xyz

and saw that workspace was defined. However $(workspace) did not bring it into my genrule rule and I kept getting the unbound variable error.

So I used a .bazelrc setting, also changing to UPPERCASE to avoid any confusion...
build --action_env=WORKSPACE=/xyz

And that worked when I built the cc_library that depended upon the genrule that created the .c files from the .pc files.

All very nice.

Now I tried to build another generated file that required another tool that was built from a cc_binary that required the cc_library. For some reason the first genrule to pre-process the .pc files to .c got triggered, but with a different generated output directory and the "unbound variable" problem came back.

The difference I could see was the output directory changed, the first filename from the genrule finds the $WORKSPACE variable

bazel-out/local-fastbuild/genfiles/xyz/src/prog.c

the second one which gets generated doesn't find the $WORKSPACE variable and throws an unbound variable error.

bazel-out/host/genfiles/xyz/src/prog.c

The bazel-out/host/ directory only has a bin sub-directory after the unbound variable error.

So I hard coded the "export WORKSPACE=/xyz" into my genrule command and it all works, except that I get two prog.c files generated in the different genfiles directories.

I suspect I have some error in my Bazel rules but don't know where to go to figure it out.

Has anyone experienced something similar or knows what query I could run to work out what is wrong?

regards, Francis.




Reply all
Reply to author
Forward
0 new messages