Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DOC] improve description of CPPDEFINES #4235

Closed
wants to merge 9 commits into from

Conversation

mwichmann
Copy link
Collaborator

The CPPDEFINES entry and the Append method entry has some additional clarification added, about ways cpp macros can be specified. Added a couple more examples to illustrate.

Doc-only change.

Signed-off-by: Mats Wichmann mats@linux.com

Contributor Checklist:

  • I have created a new test or updated the unit tests to cover the new/changed functionality.
  • I have updated CHANGES.txt (and read the README.rst)
  • I have updated the appropriate documentation

@mwichmann mwichmann changed the title [DOC] improve description of CPPDEFINES [skip appveyor] [DOC] improve description of CPPDEFINES Sep 16, 2022
@mwichmann
Copy link
Collaborator Author

As part of this work, I added another example, intending to show the use of a (list, tuple) of tuples and/or a dictionary to pass multiple values to CPPDEFINES. This blows up the doc build, with an unhelpful error (the message is "string", it's something in lxml). Since we're not worse off by doing so - the example was not included before - I've commented it out in the latest commit, maybe can revisit some time to try to find out why this kills it.

@mwichmann mwichmann mentioned this pull request Sep 25, 2022
3 tasks

<example_commands>
# SPACED will just get the string 'spaced', arg will be a separate arg
env = Environment(CPPDEFINES={'SPACED': 'spaced arg'})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that the current functionality? Hmm. not what I'd expect.

Copy link
Collaborator Author

@mwichmann mwichmann Oct 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revisited this. At the core, this is not an SCons limitation (although it becomes one because we always invoke a shell to run the compile command), but the fact that the definition is already in a Python string makes it really hard to get right. Here's what the cpp manpage says:

If you are invoking the preprocessor from a shell or shell-like program you may need to use the shell's quoting syntax to protect characters such as spaces that have a meaning in the shell syntax.

As additional fun, GCC's cpp supports function-like macros on the command line, MSVC does not. They have the extra problem of using parens, which matter to the shell also.

On the whole, we'd need to emit options this way:

gcc -D"FOO=thing with strings"

That is, quoting the whole definition rather than the right-hand-side, which I think there is no way to do with current syntax - we'd have to hack on _defines I assume. Open to suggestions on how to describe this, if we should at all. I'm pushing a new revision which removes the example, because the example (just invented by me, not tested at the time) doesn't actually work - take a look at whether that wording covers the case or if we should just "remain silent" on this topic and figure people will only use simple replacement in CPPDEFINES.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding MSVC's manpage on the function-like macro topic for completeness:

The /D option doesn't support function-like macro definitions. To insert definitions that can't be defined on the command line, consider the /FI (Name forced include file) compiler option.

and cpp's:

If you wish to define a function-like macro on the command line, write its argument list with surrounding parentheses before the equals sign (if any). Parentheses are meaningful to most shells, so you should quote the option. With sh and csh, -D'name(args...)=definition' works.

@jcbrill
Copy link
Contributor

jcbrill commented Sep 27, 2022

@mwichmann When working on #4174, I ran into docbook issues that were related to a internal lxml global limit that resulted in docbook failures without particularly helpful messages. The root cause took more time that it should have to figure out what was going awry.

That particular issue was solved by added the ability to increase the global limit and hard-coding a new constant.

As part of #4174, the following snippet was added to SCons\Tool\docbook\__init__.py:

#
# lxml etree XSLT global max traversal depth
#

lmxl_xslt_global_max_depth = 3100

if has_lxml and lmxl_xslt_global_max_depth:
    def __lxml_xslt_set_global_max_depth(max_depth):
        from lxml import etree
        etree.XSLT.set_global_max_depth(max_depth)
    __lxml_xslt_set_global_max_depth(lmxl_xslt_global_max_depth)

At the time, the hard-coded constant 3100 was larger than what was necessary to build the documentation. Perhaps not so anymore.

Could be worth a try to bump up the global max depth to see if that is the problem. For all I know, there may be more limits hard-coded into lxml as well.

EDIT ADDITION:

https://lxml.de/api/lxml.etree.XSLT-class.html

set_global_max_depth(max_depth)
Static Method

The maximum traversal depth that the stylesheet engine will allow. This does not only count the template recursion
depth but also takes the number of variables/parameters into account. The required setting for a run depends on
both the stylesheet and the input data.

Example:

XSLT.set_global_max_depth(5000)
Note that this is currently a global, module-wide setting because libxslt does not support it at a per-stylesheet
level.

@mwichmann
Copy link
Collaborator Author

Thanks! I remember reading about this in your PR now you mention it, and it clearly didn't sink in because I in no way made the connection. Your guess is probably on target - bumping the limit made one build work out, but then something else blew up (in Sphinx, so it's past the phase where lxml is involved).

The CPPDEFINES entry and the Append method entry has some additonal
clarification added, about ways cpp macros can be specified.
Added a couple more examples to illustrate.

Signed-off-by: Mats Wichmann <mats@linux.com>
Signed-off-by: Mats Wichmann <mats@linux.com>
At the moment, not sure why including the (new) example blows up the build,
so leave it commented out.

scons: *** [scons.1] XSLTApplyError : string
Traceback (most recent call last):
  File "/home/mats/github/scons/scripts/../SCons/Action.py", line 1318, in execute
    result = self.execfunction(target=target, source=rsources, env=env)
  File "/home/mats/github/scons/build/SCons/Tool/docbook/__init__.py", line 353, in __build_lxml_noresult
    result = transform(doc)
  File "src/lxml/xslt.pxi", line 602, in lxml.etree.XSLT.__call__
lxml.etree.XSLTApplyError: string

Signed-off-by: Mats Wichmann <mats@linux.com>
In the initial version of PR 4235, an added example was left
commented out because it triggered an lxml failure. Thanks to
@jcbrill, reminded that there's a global limit for lxml,
which SCons can set in the docbook module. This is being
bumped a bit, allowing the build to work.

Rebased at the same time, so force-pushing.

Signed-off-by: Mats Wichmann <mats@linux.com>
Signed-off-by: Mats Wichmann <mats@linux.com>
Signed-off-by: Mats Wichmann <mats@linux.com>
Signed-off-by: Mats Wichmann <mats@linux.com>
Signed-off-by: Mats Wichmann <mats@linux.com>
Avoid implying (as previous example did) it's a good idea to Append a
lone tuple to get the -DFOO=BAR effect, as results will differ beween
empty CPPDEFINES and a CPPDEFINES that already contains values - if
empty you get:

CPPDEFINES will expand to  -D('OTHER', 2)

Signed-off-by: Mats Wichmann <mats@linux.com>
@mwichmann mwichmann closed this Nov 14, 2022
@mwichmann
Copy link
Collaborator Author

Closed in favor of #4263

@mwichmann mwichmann removed this from the NextRelease milestone Jan 18, 2023
@mwichmann mwichmann deleted the doc/CPPDEFINES-Append branch January 18, 2023 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants