2024-03-15 21:21:48 +08:00
|
|
|
param(
|
2024-05-22 08:50:32 +08:00
|
|
|
$stage = 3
|
2024-03-15 21:21:48 +08:00
|
|
|
)
|
2023-09-26 10:32:53 +08:00
|
|
|
$myRoot = $PSScriptRoot
|
|
|
|
|
|
|
|
$AX_ROOT = (Resolve-Path $myRoot/../..).Path
|
|
|
|
|
2024-03-15 21:21:48 +08:00
|
|
|
$succeed = $true
|
|
|
|
if (($stage -band 1)) {
|
|
|
|
# ensure prebuilt lib downloaded
|
|
|
|
Push-Location $AX_ROOT
|
2024-04-24 01:48:22 +08:00
|
|
|
./setup.ps1
|
|
|
|
axmol -c
|
2024-03-15 21:21:48 +08:00
|
|
|
Pop-Location
|
2023-12-08 00:13:39 +08:00
|
|
|
|
2024-05-22 08:50:32 +08:00
|
|
|
$pip_cmd = @('pip3', 'pip')[$IsWin]
|
|
|
|
$python_cmd = @('python3', 'python')[$IsWin]
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2024-05-22 08:50:32 +08:00
|
|
|
&$pip_cmd install PyYAML Cheetah3
|
2024-03-15 21:21:48 +08:00
|
|
|
## setup ndk
|
|
|
|
$setup_script = (Resolve-Path $AX_ROOT/setup.ps1).Path
|
2023-09-26 10:32:53 +08:00
|
|
|
|
2024-03-15 21:21:48 +08:00
|
|
|
. $setup_script -p android
|
2024-05-22 08:50:32 +08:00
|
|
|
echo "after setup py_ver: $(&$python_cmd -V), PATH=$env:PATH"
|
2023-09-26 10:46:22 +08:00
|
|
|
|
2024-03-15 21:21:48 +08:00
|
|
|
echo "$ndk_root=$ndk_root"
|
2023-09-26 10:32:53 +08:00
|
|
|
|
2024-05-22 08:50:32 +08:00
|
|
|
## download win64 libclang.dll
|
|
|
|
$lib_name = @('libclang.dll', 'libclang.dylib', 'libclang.so')[$HOST_OS]
|
|
|
|
$lib_path = Join-Path $AX_ROOT "tools/bindings-generator/libclang/$lib_name"
|
|
|
|
if (!(Test-Path $lib_path -PathType Leaf)) {
|
|
|
|
$llvm_ver = '15.0.7'
|
|
|
|
$llvm_pkg = "llvm-$llvm_ver.zip"
|
|
|
|
|
|
|
|
$prefix = Join-Path $AX_ROOT "cache/devtools"
|
|
|
|
$llvm_url = devtool_url $llvm_pkg
|
|
|
|
$llvm_out = Join-Path $prefix $llvm_pkg
|
|
|
|
|
|
|
|
$1k.mkdirs($prefix)
|
|
|
|
download_and_expand -url $llvm_url -out $llvm_out -dest $prefix
|
|
|
|
$suffix = @('win32/x64/libclang.dll', 'mac/libclang.dylib', 'linux/libclang.so')[$HOST_OS]
|
|
|
|
Copy-Item "$prefix/llvm-$llvm_ver/lib/$suffix" -Destination $lib_path
|
|
|
|
}
|
2023-06-12 10:26:08 +08:00
|
|
|
|
2024-03-15 21:21:48 +08:00
|
|
|
## ensure $env:AX_ROOT/core/axmolver.h exists
|
|
|
|
echo "AX_ROOT=$AX_ROOT"
|
|
|
|
if (!(Test-Path "$AX_ROOT/core/axmolver.h" -PathType Leaf)) {
|
|
|
|
$content = [System.IO.File]::ReadAllText("$AX_ROOT/core/axmolver.h.in")
|
|
|
|
$content = $content.Replace('@AX_GIT_PRESENT@', '0')
|
|
|
|
[System.IO.File]::WriteAllText("$AX_ROOT/core/axmolver.h")
|
|
|
|
}
|
2023-02-14 23:30:44 +08:00
|
|
|
|
2024-03-15 21:21:48 +08:00
|
|
|
## run genbindings.py
|
|
|
|
Push-Location $AX_ROOT/tools/tolua
|
2022-01-01 21:56:55 +08:00
|
|
|
|
2024-05-22 08:50:32 +08:00
|
|
|
&$python_cmd genbindings.py --ndk_root "$ndk_root"
|
2024-03-15 21:21:48 +08:00
|
|
|
$succeed = $?
|
2024-01-22 21:46:55 +08:00
|
|
|
|
2024-03-15 21:21:48 +08:00
|
|
|
Pop-Location
|
|
|
|
}
|
2024-01-22 21:46:55 +08:00
|
|
|
|
2024-03-15 21:21:48 +08:00
|
|
|
# strip empty lines
|
|
|
|
if ($stage -band 2) {
|
|
|
|
echo 'Stripping header empty lines ...'
|
|
|
|
$UTF8Encoding = [System.Text.Encoding]::UTF8
|
2024-03-15 01:23:18 +08:00
|
|
|
$eol = $UTF8Encoding.GetBytes("`n")
|
2024-03-15 21:21:48 +08:00
|
|
|
$autogen_dir = Join-Path $AX_ROOT 'extensions/scripting/lua-bindings/auto/*.hpp'
|
|
|
|
$header_files = Get-ChildItem $autogen_dir
|
|
|
|
|
2024-05-22 08:50:32 +08:00
|
|
|
foreach ($file in $header_files) {
|
2024-03-15 21:21:48 +08:00
|
|
|
$file_path = "$file"
|
2024-05-22 08:50:32 +08:00
|
|
|
$code_lines = Get-Content $file_path
|
2024-03-15 21:21:48 +08:00
|
|
|
$fs = [System.IO.File]::Open($file_path, [System.IO.FileMode]::Truncate)
|
|
|
|
$empty_lines = 0
|
|
|
|
$write_lines = 0
|
2024-05-22 08:50:32 +08:00
|
|
|
foreach ($line in $code_lines) {
|
2024-03-15 21:21:48 +08:00
|
|
|
if ($line) {
|
|
|
|
++$write_lines
|
|
|
|
$buf = $UTF8Encoding.GetBytes($line)
|
|
|
|
$fs.Write($buf, 0, $buf.Length)
|
|
|
|
$fs.Write($eol, 0, $eol.Length)
|
2024-05-22 08:50:32 +08:00
|
|
|
}
|
|
|
|
else {
|
2024-03-15 21:21:48 +08:00
|
|
|
++$empty_lines
|
|
|
|
}
|
2024-03-15 01:23:18 +08:00
|
|
|
}
|
|
|
|
|
2024-03-15 21:21:48 +08:00
|
|
|
# $fs.Write($eol, 0, $eol.Length)
|
|
|
|
$fs.Dispose()
|
|
|
|
|
|
|
|
echo "Removed $empty_lines empty lines for file $file_path, valid lines: $write_lines"
|
|
|
|
}
|
2024-03-15 01:23:18 +08:00
|
|
|
}
|
|
|
|
|
2024-03-15 21:21:48 +08:00
|
|
|
# check modified files
|
|
|
|
Push-Location $AX_ROOT
|
2024-03-15 01:36:33 +08:00
|
|
|
if ($succeed -and $env:GITHUB_ACTIONS -eq 'true') {
|
|
|
|
$git_status = "$(git status)"
|
|
|
|
$no_changes = $git_status.IndexOf('modified:') -eq -1 # -and $git_status.IndexOf('deleted:') -eq -1 -and $git_status.IndexOf('Untracked', [StringComparison]::OrdinalIgnoreCase) -eq -1
|
|
|
|
if ($no_changes) {
|
|
|
|
echo "BINDING_NO_CHANGES=true" >> ${env:GITHUB_ENV}
|
2024-05-22 08:50:32 +08:00
|
|
|
}
|
|
|
|
else {
|
2024-03-15 01:36:33 +08:00
|
|
|
echo "LAST_COMMIT_HASH=$(git rev-parse --short=7 HEAD)" >> ${env:GITHUB_ENV}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Pop-Location
|
|
|
|
|
2024-05-22 08:50:32 +08:00
|
|
|
if (!$succeed) {
|
2024-02-02 00:15:06 +08:00
|
|
|
throw "Generating lua bindings fails"
|
|
|
|
}
|