226 lines
7.8 KiB
PowerShell
226 lines
7.8 KiB
PowerShell
param(
|
|
[string]$Version = "",
|
|
[switch]$SkipInstall,
|
|
[switch]$NoCythonForDevOnly,
|
|
[switch]$UsePyArmor,
|
|
[switch]$NoObfuscateForDevOnly,
|
|
[switch]$PackExe,
|
|
[switch]$PackExeForce,
|
|
[switch]$IncludeLicense,
|
|
[string]$UpxDir = ""
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
$Root = Resolve-Path (Join-Path $PSScriptRoot "..\..")
|
|
Set-Location $Root
|
|
|
|
$env:DISABLE_MODEL_SOURCE_CHECK = "True"
|
|
$env:PADDLE_PDX_DISABLE_MODEL_SOURCE_CHECK = "1"
|
|
$env:SKIP_OCR_INIT = "1"
|
|
$env:GLOG_minloglevel = "2"
|
|
$env:FLAGS_use_mkldnn = "false"
|
|
$env:FLAGS_call_stack_level = "0"
|
|
|
|
if (-not $Version) {
|
|
$Version = (python -c "from douyin.core.version import APP_VERSION; print(str(APP_VERSION).lstrip('Vv'))").Trim()
|
|
}
|
|
|
|
if (-not $SkipInstall) {
|
|
python -m pip install --upgrade pip
|
|
python -m pip install -r requirements.txt
|
|
python -m pip install pyinstaller
|
|
if ($UsePyArmor) {
|
|
python -m pip install pyarmor
|
|
} elseif (-not $NoCythonForDevOnly -and -not $NoObfuscateForDevOnly) {
|
|
python -m pip install cython setuptools wheel
|
|
}
|
|
}
|
|
|
|
$DistRoot = Join-Path $Root "dist\DouyinGuaji-$Version"
|
|
if (Test-Path $DistRoot) {
|
|
Remove-Item -LiteralPath $DistRoot -Recurse -Force
|
|
}
|
|
New-Item -ItemType Directory -Force $DistRoot | Out-Null
|
|
|
|
$BuildSourceRoot = $Root
|
|
$HiddenImportsFile = Join-Path $Root "build\obfuscation-hidden-imports.json"
|
|
if ($UsePyArmor -and -not $NoObfuscateForDevOnly) {
|
|
$BuildSourceRoot = Join-Path $Root "build\obfuscated-src"
|
|
python -m tools.obfuscation_staging --source-root $Root --staging-root $BuildSourceRoot --hidden-imports-output $HiddenImportsFile
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "PyArmor obfuscation failed with exit code $LASTEXITCODE"
|
|
}
|
|
} elseif (-not $NoCythonForDevOnly -and -not $NoObfuscateForDevOnly) {
|
|
$BuildSourceRoot = Join-Path $Root "build\cythonized-src"
|
|
python -m tools.cython_staging --source-root $Root --staging-root $BuildSourceRoot --hidden-imports-output $HiddenImportsFile
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "Cython core compile failed with exit code $LASTEXITCODE"
|
|
}
|
|
} else {
|
|
Write-Warning "Development plaintext build requested. Do not distribute this package."
|
|
}
|
|
|
|
$CommonArgs = @(
|
|
"--clean",
|
|
"--noconfirm",
|
|
"--distpath", $DistRoot,
|
|
"--workpath", (Join-Path $Root "build\pyinstaller"),
|
|
"--paths", $BuildSourceRoot,
|
|
"--add-data", "config\README.md;config",
|
|
"--hidden-import", "PIL._tkinter_finder",
|
|
"--hidden-import", "ttkbootstrap",
|
|
"--hidden-import", "logging.handlers",
|
|
"--hidden-import", "cryptography.hazmat.primitives.serialization"
|
|
)
|
|
|
|
$GuiArgs = @(
|
|
"--collect-submodules", "gui"
|
|
)
|
|
|
|
$CliArgs = @(
|
|
"--collect-submodules", "douyin",
|
|
"--collect-submodules", "operations"
|
|
)
|
|
|
|
$ExcludedOptionalModules = @(
|
|
"easyocr",
|
|
"matplotlib",
|
|
"modelscope",
|
|
"pandas",
|
|
"pytest",
|
|
"scipy",
|
|
"skimage",
|
|
"tensorflow",
|
|
"torch",
|
|
"torchvision"
|
|
)
|
|
foreach ($name in $ExcludedOptionalModules) {
|
|
$CommonArgs += @("--exclude-module", $name)
|
|
}
|
|
|
|
if ((-not $NoObfuscateForDevOnly) -and (-not $NoCythonForDevOnly -or $UsePyArmor) -and (Test-Path $HiddenImportsFile)) {
|
|
$HiddenImports = Get-Content -LiteralPath $HiddenImportsFile -Raw | ConvertFrom-Json
|
|
$CliOnlyHiddenImportRoots = @("cv2", "numpy", "paddleocr", "paddle")
|
|
foreach ($name in $HiddenImports) {
|
|
$nameText = [string]$name
|
|
$rootName = ($nameText -split "\.")[0]
|
|
if ($CliOnlyHiddenImportRoots -contains $rootName) {
|
|
$CliArgs += @("--hidden-import", $nameText)
|
|
} else {
|
|
$CommonArgs += @("--hidden-import", $nameText)
|
|
}
|
|
}
|
|
}
|
|
|
|
python -m PyInstaller @CommonArgs @GuiArgs --name DouyinGuajiGUI --windowed (Join-Path $BuildSourceRoot "gui\gui_dashboard_app_entry.py")
|
|
python -m PyInstaller @CommonArgs @GuiArgs --name web_gui --console (Join-Path $BuildSourceRoot "gui\web_gui_entry.py")
|
|
python -m PyInstaller @CommonArgs @CliArgs --name run_cli --console (Join-Path $BuildSourceRoot "bin\run_cli_entry.py")
|
|
|
|
foreach ($name in @("DouyinGuajiGUI", "web_gui", "run_cli")) {
|
|
$srcDir = Join-Path $DistRoot $name
|
|
Copy-Item -LiteralPath (Join-Path $srcDir "$name.exe") -Destination (Join-Path $DistRoot "$name.exe") -Force
|
|
$srcInternal = Join-Path $srcDir "_internal"
|
|
$dstInternal = Join-Path $DistRoot "_internal"
|
|
if (Test-Path $srcInternal) {
|
|
New-Item -ItemType Directory -Force $dstInternal | Out-Null
|
|
Get-ChildItem -LiteralPath $srcInternal -Force | Copy-Item -Destination $dstInternal -Recurse -Force
|
|
}
|
|
Remove-Item -LiteralPath $srcDir -Recurse -Force
|
|
}
|
|
|
|
$RuntimeAssets = @(
|
|
"coupon.png",
|
|
"fav.png",
|
|
"fudai.png",
|
|
"fudai_icon_countdown_v20260618.png",
|
|
"fudai_icon_pending_v20260618.png",
|
|
"fudai_icon_purple_left_v20260618.png",
|
|
"fudai_icon_red_left_v20260618.png",
|
|
"fudai_task_status_dacheng_shape.png",
|
|
"like.png",
|
|
"x.png",
|
|
"xin.png"
|
|
)
|
|
$AssetsTarget = Join-Path $DistRoot "assets"
|
|
if (Test-Path $AssetsTarget) {
|
|
Remove-Item -LiteralPath $AssetsTarget -Recurse -Force
|
|
}
|
|
New-Item -ItemType Directory -Force $AssetsTarget | Out-Null
|
|
foreach ($name in $RuntimeAssets) {
|
|
$src = Join-Path $Root "assets\$name"
|
|
if (-not (Test-Path $src)) {
|
|
throw "Missing runtime asset: assets\$name"
|
|
}
|
|
Copy-Item -LiteralPath $src -Destination (Join-Path $AssetsTarget $name) -Force
|
|
}
|
|
|
|
$WebuiTarget = Join-Path $DistRoot "webui"
|
|
if (Test-Path $WebuiTarget) {
|
|
Remove-Item -LiteralPath $WebuiTarget -Recurse -Force
|
|
}
|
|
New-Item -ItemType Directory -Force $WebuiTarget | Out-Null
|
|
Copy-Item -LiteralPath (Join-Path $Root "webui\index.html") -Destination (Join-Path $WebuiTarget "index.html") -Force
|
|
Copy-Item -LiteralPath (Join-Path $Root "webui\styles.css") -Destination (Join-Path $WebuiTarget "styles.css") -Force
|
|
Copy-Item -LiteralPath (Join-Path $Root "webui\app.js") -Destination (Join-Path $WebuiTarget "app.js") -Force
|
|
foreach ($dir in @("css", "js", "partials")) {
|
|
$srcDir = Join-Path $Root "webui\$dir"
|
|
if (-not (Test-Path $srcDir)) {
|
|
continue
|
|
}
|
|
$dstDir = Join-Path $WebuiTarget $dir
|
|
New-Item -ItemType Directory -Force $dstDir | Out-Null
|
|
Get-ChildItem -LiteralPath $srcDir -File | Where-Object {
|
|
$_.Name -notlike "README*"
|
|
} | Copy-Item -Destination $dstDir -Force
|
|
}
|
|
|
|
New-Item -ItemType Directory -Force (Join-Path $DistRoot "config") | Out-Null
|
|
Copy-Item -LiteralPath (Join-Path $Root "config\README.md") -Destination (Join-Path $DistRoot "config\README.md") -Force
|
|
foreach ($dir in @("logs", "pic", "state")) {
|
|
$runtimeDir = Join-Path $DistRoot $dir
|
|
New-Item -ItemType Directory -Force $runtimeDir | Out-Null
|
|
New-Item -ItemType File -Force (Join-Path $runtimeDir ".keep") | Out-Null
|
|
}
|
|
|
|
$licensePath = Join-Path $Root "license.dat"
|
|
if ($IncludeLicense -and (Test-Path $licensePath)) {
|
|
Copy-Item -LiteralPath $licensePath -Destination (Join-Path $DistRoot "license.dat") -Force
|
|
}
|
|
|
|
if ($PackExe) {
|
|
$PackArgs = @($DistRoot)
|
|
if ($UpxDir) {
|
|
$PackArgs += @("--upx-dir", $UpxDir)
|
|
}
|
|
if ($PackExeForce) {
|
|
$PackArgs += "--force"
|
|
}
|
|
python -m tools.exe_packing @PackArgs
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "UPX packing failed with exit code $LASTEXITCODE"
|
|
}
|
|
}
|
|
|
|
$ManifestArgs = @($DistRoot)
|
|
if ($IncludeLicense) {
|
|
$ManifestArgs += "--allow-license"
|
|
}
|
|
|
|
python -m tools.distribution_manifest @ManifestArgs
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "Distribution manifest check failed with exit code $LASTEXITCODE"
|
|
}
|
|
|
|
python -m tools.exe_packing $DistRoot --smoke-only
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "Executable smoke check failed with exit code $LASTEXITCODE"
|
|
}
|
|
|
|
python -m tools.distribution_manifest @ManifestArgs
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "Post-smoke distribution manifest check failed with exit code $LASTEXITCODE"
|
|
}
|
|
|
|
Write-Host "[OK] Portable package: $DistRoot"
|
|
Write-Host "[NEXT] If Inno Setup is installed: iscc packaging\inno\douyin_guaji.iss /DMyAppVersion=$Version"
|