Refactor Python wrapper creation in build script

This commit is contained in:
deepend-tildeclub
2026-02-01 17:19:34 -07:00
committed by GitHub
parent 2723d49b3a
commit 2bbe9dccc6

View File

@@ -151,17 +151,17 @@ jobs:
$genTarget = Join-Path $gtkBin "glib-genmarshal" # what your vcxproj calls via python.exe $genTarget = Join-Path $gtkBin "glib-genmarshal" # what your vcxproj calls via python.exe
if ($genAny) { if ($genAny) {
# Create wrapper that runs either the .exe or .py we found.
$genPath = $genAny.FullName.Replace('\','\\') $genPath = $genAny.FullName.Replace('\','\\')
@" $pyWrapper = @(
import os, subprocess, sys 'import os, subprocess, sys',
tool = r"$genPath" "tool = r`"$genPath`"",
if tool.lower().endswith(".py"): 'if tool.lower().endswith(".py"):',
sys.exit(subprocess.call([sys.executable, tool] + sys.argv[1:])) ' sys.exit(subprocess.call([sys.executable, tool] + sys.argv[1:]))',
else: 'else:',
sys.exit(subprocess.call([tool] + sys.argv[1:])) ' sys.exit(subprocess.call([tool] + sys.argv[1:]))'
"@ | Set-Content -Path $genTarget -Encoding ASCII ) -join "`r`n"
} else { Set-Content -Path $genTarget -Value $pyWrapper -Encoding ASCII
} else {
# Fallback: install MSYS2 glib2 tools and run their glib-genmarshal with PATH set. # Fallback: install MSYS2 glib2 tools and run their glib-genmarshal with PATH set.
Write-Host "glib-genmarshal not found in GTK3 bundle. Installing MSYS2 glib2 tools as a fallback." Write-Host "glib-genmarshal not found in GTK3 bundle. Installing MSYS2 glib2 tools as a fallback."
@@ -178,17 +178,17 @@ jobs:
$msysGen = "C:\msys64\$mingw\bin\glib-genmarshal.exe" $msysGen = "C:\msys64\$mingw\bin\glib-genmarshal.exe"
if (-not (Test-Path $msysGen)) { throw "MSYS2 glib-genmarshal.exe not found at expected path: $msysGen" } if (-not (Test-Path $msysGen)) { throw "MSYS2 glib-genmarshal.exe not found at expected path: $msysGen" }
$msysBin = Split-Path $msysGen -Parent $msysBin = (Split-Path $msysGen -Parent).Replace('\','\\')
$msysGenEsc = $msysGen.Replace('\','\\') $msysGenEsc = $msysGen.Replace('\','\\')
$msysBinEsc = $msysBin.Replace('\','\\')
@" $pyWrapper = @(
import os, subprocess, sys 'import os, subprocess, sys',
exe = r"$msysGenEsc" "exe = r`"$msysGenEsc`"",
env = os.environ.copy() 'env = os.environ.copy()',
env["PATH"] = r"$msysBinEsc" + ";" + env.get("PATH","") "env[`"PATH`"] = r`"$msysBin`" + `";`" + env.get(`"PATH`",`"`")",
sys.exit(subprocess.call([exe] + sys.argv[1:], env=env)) 'sys.exit(subprocess.call([exe] + sys.argv[1:], env=env))'
"@ | Set-Content -Path $genTarget -Encoding ASCII ) -join "`r`n"
Set-Content -Path $genTarget -Value $pyWrapper -Encoding ASCII
} }
# Compatibility aliases while vcxproj still names GTK2 libs. # Compatibility aliases while vcxproj still names GTK2 libs.