Files
build_toochain/install_script/ccache/set_cache_env.ps1
T
2026-07-07 15:23:39 +08:00

31 lines
1.3 KiB
PowerShell

$ErrorActionPreference = "Stop"
$installDir = "D:\ae\tools\ccache"
$cacheDir = "D:\ae\tools\ccache-cache"
$tmpDir = "D:\ae\tools\ccache-tmp"
New-Item -ItemType Directory -Force -Path $installDir | Out-Null
New-Item -ItemType Directory -Force -Path $cacheDir | Out-Null
New-Item -ItemType Directory -Force -Path $tmpDir | Out-Null
[Environment]::SetEnvironmentVariable("CCACHE_DIR", $cacheDir, "User")
[Environment]::SetEnvironmentVariable("CCACHE_MAXSIZE", "20G", "User")
[Environment]::SetEnvironmentVariable("CCACHE_TEMPDIR", $tmpDir, "User")
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
$paths = $userPath -split ";"
if($paths -notcontains $installDir) {
if([string]::IsNullOrWhiteSpace($userPath)) {
$newPath = $installDir
} else {
$newPath = "$userPath;$installDir"
}
[Environment]::SetEnvironmentVariable("Path", $newPath, "User")
}
$env:Path = "$installDir;$env:Path"
$env:CCACHE_DIR = $cacheDir
$env:CCACHE_MAXSIZE = "20G"
$env:CCACHE_TEMPDIR = $tmpDir
& "$installDir\ccache.exe" --show-config
& "$installDir\ccache.exe" --show-stats
Write-Host "ccache 环境变量已设置"
Write-Host "ccache 安装目录: $installDir"
Write-Host "ccache 缓存目录: $cacheDir"
Write-Host "ccache 临时目录: $tmpDir"
Write-Host "已经写入用户 PATH,新开的 PowerShell 窗口可直接使用 ccache"