Skip to content

PCbuild/regen.targets contains invalid newlines in XML attribute #116472

Closed
@DanAlbert

Description

@DanAlbert

Bug report

Bug description:

PCbuild/regen.targets encodes a multi-line batch script in an XML attribute using literal newlines:

<Exec Command='setlocal
set PYTHONPATH=$(PySourcePath)Lib
"$(PythonExe)" Programs\freeze_test_frozenmain.py Programs\test_frozenmain.h'
WorkingDirectory="$(PySourcePath)" />

https://www.w3.org/TR/2006/REC-xml11-20060816/#AVNormalize says that newlines in XML attributes will be normalized to spaces when parsed. It appears that MSBuild (that's the consumer of that file, right?) doesn't perform that normalization so this typically doesn't cause any problems, but any programmatic rewriting of that file (which we do in Android, to append additional license sources for the dependencies we use) will break the script if done using a compliant XML parser (such as minidom).

Not really sure what to provide as a reproducer here. A trivial read/rewrite of PCbuild/regen.targets done with minidom will cause the problem to happen:

from xml.dom import minidom

xml = minidom.parse("PCbuild/regen.targets)
with open("PCbuild/regen.targets", "w", encoding="utf-8") as output:
    xml.writexml(output)

Then build on Windows, and it'll fail with something like:

  Regenerate test_frozenmain.h
  Invalid parameter to SETLOCAL command
C:\tmpfs\src\git\external\python\cpython3\PCbuild\regen.targets(82,5): error MSB3073: The command "setlocal set PYTHONPATH=C:\tmpfs\src\git\external\python\cpython3\Lib "C:\tmpfs\src\git\external\python\cpython3\PCbuild\amd64\python.exe" Programs\freeze_test_frozenmain.py Programs\test_frozenmain.h" exited with code 1. [C:\tmpfs\src\git\external\python\cpython3\PCbuild\python.vcxproj]

The fix is trivial: replace the literal newlines with %0D%0A as is done in other places (Tools/nuget/make_pkg.proj, for example). Only filing this because the PR template told me to :)

CPython versions tested on:

3.11

Operating systems tested on:

Windows

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions