-
Notifications
You must be signed in to change notification settings - Fork 2
[OPT] 改进 install_deps_windows.ps1:自动读取 vcpkg.json 安装依赖 #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,14 +35,30 @@ function Install-VCPKG { | |
| & "$vcpkgPath\bootstrap-vcpkg.bat" | ||
| } | ||
| } | ||
| function Install-VCPKG-Dependency { | ||
| $vcpkgPath = "C:\Dev\vcpkg\vcpkg.exe" | ||
| $depsList = @( | ||
| # ToDo: Add dependencies here | ||
| ) | ||
| function Install-VCPKG-Dependency { | ||
| $vcpkgExe = "$script:vcpkgPath\vcpkg.exe" | ||
| $jsonPath = Join-Path $PSScriptRoot "..\..\vcpkg.json" | ||
|
|
||
| if (-not (Test-Path $jsonPath)) { | ||
| Write-Error "vcpkg.json not found at $jsonPath" | ||
| return | ||
| } | ||
|
|
||
|
|
||
| $json = Get-Content $jsonPath -Raw | ConvertFrom-Json | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 [错误处理] 建议添加 try-catch 块包裹 JSON 解析,防止文件格式错误时抛出未处理异常: try {
$json = Get-Content $jsonPath -Raw | ConvertFrom-Json
} catch {
Write-Error "Failed to parse vcpkg.json: $_"
return
}
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. emmm,对哦,OK,下个版本改 |
||
| $depsList = $json.dependencies | ||
|
|
||
| if ($depsList.Count -eq 0) { | ||
| Write-Output "No dependencies listed in vcpkg.json" | ||
| return | ||
| } | ||
|
|
||
| foreach ($dep in $depsList) { | ||
| Write-Output "Installing $dep via vcpkg..." | ||
| & "$vcpkgPath" install "$dep" | ||
| & $vcpkgExe install $dep | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 [安全性] 建议验证 if ($dep -notmatch '^[\w\-\.]+$') {
Write-Warning "Invalid dependency name format: $dep"
continue
}
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 你的意思是不信任Coredev们喽,你这是指桑骂槐,有反叛之心啊 |
||
| if ($LASTEXITCODE -ne 0) { | ||
| Write-Warning "Failed to install $dep" | ||
| } | ||
| } | ||
| } | ||
| function Get-Admin{ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
..\..\vcpkg.json假设脚本始终位于scripts/setup/目录。建议使用(Split-Path (Split-Path $PSScriptRoot -Parent) -Parent)显式获取仓库根目录,避免因脚本调用位置不同导致路径解析失败。There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
emmm,如果需求健壮性,我其实比较喜欢C#,并且……这玩意是内置在用户手册里的,so……如果用户根本看不懂文件放在哪里,到时候咱俩都得遭殃