forked from python/cpython
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pythongh-111650: Generate pyconfig.h on Windows
Prior to this change, the Py_NOGIL macro was not defined when building C API extensions with the `--disable-gil` build on Windows. `Py_NOGIL` was only defined as a pre-processor definition in pyproject.props, but that is not used by C-API extensions. This instead generates the `pyconfig.h` header on Windows as part of the build process. For now, `Py_NOGIL` is the only macro that may be conditionally defined in the generated file.
- Loading branch information
Showing
5 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# | ||
# Generates pyconfig.h from PC\pyconfig.h.in | ||
# | ||
|
||
param ( | ||
[string[]]$define, | ||
[string]$File | ||
) | ||
|
||
$definedValues = @{} | ||
|
||
foreach ($arg in $define) { | ||
$parts = $arg -split '=' | ||
|
||
if ($parts.Count -eq 1) { | ||
$key = $parts[0] | ||
$definedValues[$key] = "" | ||
} elseif ($parts.Count -eq 2) { | ||
$key = $parts[0] | ||
$value = $parts[1] | ||
$definedValues[$key] = $value | ||
} else { | ||
Write-Host "Invalid argument: $arg" | ||
exit 1 | ||
} | ||
} | ||
|
||
$cpythonRoot = Split-Path $PSScriptRoot -Parent | ||
$pyconfigPath = Join-Path $cpythonRoot "PC\pyconfig.h.in" | ||
|
||
$header = "/* pyconfig.h. Generated from PC\pyconfig.h.in by generate_pyconfig.ps1. */" | ||
|
||
$lines = Get-Content -Path $pyconfigPath | ||
$lines = @($header) + $lines | ||
|
||
foreach ($i in 0..($lines.Length - 1)) { | ||
if ($lines[$i] -match "^#undef (\w+)$") { | ||
$key = $Matches[1] | ||
if ($definedValues.ContainsKey($key)) { | ||
$value = $definedValues[$key] | ||
$lines[$i] = "#define $key $value".TrimEnd() | ||
} else { | ||
$lines[$i] = "/* #undef $key */" | ||
} | ||
} | ||
} | ||
|
||
$ParentDir = Split-Path -Path $File -Parent | ||
New-Item -ItemType Directory -Force -Path $ParentDir | Out-Null | ||
Set-Content -Path $File -Value $lines |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters