Exposing makefile variables to GN

Skip to first unread message

Matthew Spelman

Nov 28, 2022, 1:12:26 PM11/28/22
to gn-dev
Hi all,

I'm trying to use GN to build Crashpad by calling it from a makefile, which contains information about the directory structure the build is taking place in. For example, I am calling gn from the makefile via a command which looks like this:

GN_OPTIONS := --root=$(PROD_SOURCES) --script-executable=$(PYTHON3)

I've discovered that I need to express a dependency on curl on Linux, i.e. I need "-I[relative path]/curl/include" on the compile line.

However, this path information is contained in a value stored in $CHANGE_NUMBER, which exists in the makefile context, but not in GN's. If I try to do something like:

include_dirs = [ "$CHANGE_NUMBER/curl/include" ]

in the relevant BUILD.gn file, GN can't parse that. Is there a way to access these variables from inside GN's context? Could I pass them as an argument to GN in some way (like how I'm doing with --root and --script-executable)?


K. Moon

Nov 28, 2022, 1:25:38 PM11/28/22
to Matthew Spelman, gn-dev
As you've discovered, Makefile variables have no impact on commands called from the Makefile, so you need to plumb this information through yourself.

For GN, the typical way to do this is to use --args to configure GN args on the command line; see "gn help --args" for examples.

Another option would be to pass ordinary environment variables using the typical shell syntax, and then use the getenv() function, but I wouldn't recommend this over GN args, which are designed for this purpose.

Matthew Spelman

Nov 28, 2022, 1:44:56 PM11/28/22
to gn-dev, km...@chromium.org, gn-dev, Matthew Spelman
Thanks, I'll take a look at using --args.


Matthew Spelman

Nov 28, 2022, 3:26:56 PM11/28/22
to gn-dev, Matthew Spelman, km...@chromium.org, gn-dev
So I've got something like this:

--args="curl_include=$(PATH_TO_CURL_INCLUDE_DIRECTORY)" which expands out to /[path to curl inclue directory], but it looks like gn doesn't know how to parse it:

ERROR at the command-line "--args":1:14: Invalid token.
curl_include=/[path to curl include directory]
I have no idea what this is.

All the examples using --args seem to show that the args are either bool flags (true/false) or are string with escaped quotes (os=\"android\""). Are paths with a leading / not allowed?


Brett Wilson

Nov 28, 2022, 3:31:03 PM11/28/22
to Matthew Spelman, gn-dev, km...@chromium.org
If you want a string, GN needs to see the literal quotes around it for it to be parsed. This is why you see escaped quotes (to avoid the shell parsing the quotes) in the examples, and you will need something similar in your code. I don't know exactly what escaping you need in this context for it to make it to GN, though, you will need to do some experimentation.


Matthew Spelman

Nov 28, 2022, 3:39:40 PM11/28/22
to gn-dev, Brett Wilson, gn-dev, km...@chromium.org, Matthew Spelman
Thanks Brett, I realized I needed the following format:



Reply all
Reply to author
0 new messages