Skip to content

[OPT] 改进 install_deps_windows.ps1:自动读取 vcpkg.json 安装依赖 - #19

Open
OFFMN-SHARP wants to merge 1 commit into
Ethernos-Studio:mainfrom
OFFMN-SHARP:opt/offmn-sharp/update-install-script
Open

[OPT] 改进 install_deps_windows.ps1:自动读取 vcpkg.json 安装依赖#19
OFFMN-SHARP wants to merge 1 commit into
Ethernos-Studio:mainfrom
OFFMN-SHARP:opt/offmn-sharp/update-install-script

Conversation

@OFFMN-SHARP

@OFFMN-SHARP OFFMN-SHARP commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

我修复了Install-VCPKG-Dependency函数无法使用的问题
顺带一提
接下来我会找时间精简脚本

Summary by Sourcery

增强功能:

  • 更新 Install-VCPKG-Dependency PowerShell 函数,以解析 vcpkg.json 并自动安装其中列出的依赖项,同时在配置缺失、依赖列表为空以及安装失败时输出相应提示信息。
Original summary in English

Summary by Sourcery

Enhancements:

  • Update the Install-VCPKG-Dependency PowerShell function to parse vcpkg.json and install listed dependencies automatically, with messages for missing configs, empty dependency lists, and failed installs.

@arknightsautomachine-ai-reviewer

arknightsautomachine-ai-reviewer Bot commented Apr 6, 2026

Copy link
Copy Markdown

Review Complete!

The code review has been posted. View Review →

@sourcery-ai

sourcery-ai Bot commented Apr 6, 2026

Copy link
Copy Markdown

审阅者指南

重构 Windows 依赖安装脚本,使其直接从 vcpkg.json 读取依赖项,并从共享的 vcpkgPath 调用 vcpkg.exe,同时在依赖安装流程中增加基础的校验与错误处理。

更新后的 Install-VCPKG-Dependency PowerShell 函数流程图

flowchart TD
    A[Start Install-VCPKG-Dependency] --> B[Set vcpkgExe from script:vcpkgPath]
    B --> C[Build jsonPath to vcpkg.json relative to script root]
    C --> D{Does vcpkg.json exist at jsonPath?}
    D -- No --> E[Write-Error: vcpkg.json not found]
    E --> F[Return]
    D -- Yes --> G[Read vcpkg.json and ConvertFrom-Json]
    G --> H[Set depsList to json.dependencies]
    H --> I{Is depsList.Count equal to 0?}
    I -- Yes --> J[Write-Output: No dependencies listed]
    J --> F
    I -- No --> K[Iterate over each dep in depsList]
    K --> L[Write-Output: Installing dep via vcpkg]
    L --> M[Invoke vcpkgExe install dep]
    M --> N{LASTEXITCODE not equal to 0?}
    N -- Yes --> O[Write-Warning: Failed to install dep]
    N -- No --> P[Proceed to next dep]
    O --> P
    P --> Q{More deps?}
    Q -- Yes --> K
    Q -- No --> R[End Install-VCPKG-Dependency]
Loading

文件级变更

Change Details Files
让 Install-VCPKG-Dependency 从 vcpkg.json 读取依赖列表,而不是使用硬编码数组,并在调用 vcpkg 时改进错误处理。
  • 使用脚本级共享变量 vcpkgPath 构造 vcpkg.exe 路径,替代硬编码的绝对路径。
  • 基于脚本根目录解析 vcpkg.json,若文件缺失则以错误中止执行。
  • 使用 ConvertFrom-Json 解析 vcpkg.json,并将其 dependencies 属性作为包列表;如果列表为空则提前退出。
  • 对每个依赖调用 vcpkg.exe install(使用未加引号的参数),如果任一安装命令返回非零退出码,则输出警告。
scripts/setup/install_deps_windows.ps1

可能关联的 Issue

  • #[OPT] scripts/setup/install_deps_windows.ps1 一键安装脚本:二者都改进了 install_deps_windows.ps1;此 PR 修复了 Install-VCPKG-Dependency 并通过 vcpkg.json 实现依赖的自动化安装。

技巧与命令

与 Sourcery 交互

  • 触发新的审阅: 在 Pull Request 中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审阅评论。
  • 根据审阅评论生成 GitHub Issue: 在审阅评论下回复,让 Sourcery 根据该评论创建 Issue。也可以直接回复 @sourcery-ai issue,从该评论创建 Issue。
  • 生成 Pull Request 标题: 在 Pull Request 标题的任意位置写入 @sourcery-ai,即可随时生成标题。也可以在 Pull Request 中评论 @sourcery-ai title 来(重新)生成标题。
  • 生成 Pull Request 总结: 在 Pull Request 正文的任意位置写入 @sourcery-ai summary,即可在该位置生成 PR 总结。也可以在 Pull Request 中评论 @sourcery-ai summary 来(重新)生成总结。
  • 生成审阅者指南: 在 Pull Request 中评论 @sourcery-ai guide,即可随时(重新)生成审阅者指南。
  • 一次性解决所有 Sourcery 评论: 在 Pull Request 中评论 @sourcery-ai resolve,将所有 Sourcery 评论标记为已解决。如果你已经处理完所有评论且不想再看到它们,这会很有用。
  • 一次性驳回所有 Sourcery 审阅: 在 Pull Request 中评论 @sourcery-ai dismiss,即可驳回所有现有的 Sourcery 审阅。若你希望从头开始一次新的审阅,这尤其有用——别忘了再评论 @sourcery-ai review 来触发新的审阅!

自定义你的使用体验

访问你的 控制面板 以:

  • 启用或禁用审阅功能,例如 Sourcery 自动生成的 Pull Request 总结、审阅者指南等。
  • 修改审阅语言。
  • 添加、删除或编辑自定义审阅指令。
  • 调整其他审阅设置。

获取帮助

Original review guide in English

Reviewer's Guide

Refactors the Windows dependency installation script to read dependencies directly from vcpkg.json and invoke vcpkg.exe from a shared vcpkgPath, adding basic validation and error handling around dependency installation.

Flow diagram for updated Install-VCPKG-Dependency PowerShell function

flowchart TD
    A[Start Install-VCPKG-Dependency] --> B[Set vcpkgExe from script:vcpkgPath]
    B --> C[Build jsonPath to vcpkg.json relative to script root]
    C --> D{Does vcpkg.json exist at jsonPath?}
    D -- No --> E[Write-Error: vcpkg.json not found]
    E --> F[Return]
    D -- Yes --> G[Read vcpkg.json and ConvertFrom-Json]
    G --> H[Set depsList to json.dependencies]
    H --> I{Is depsList.Count equal to 0?}
    I -- Yes --> J[Write-Output: No dependencies listed]
    J --> F
    I -- No --> K[Iterate over each dep in depsList]
    K --> L[Write-Output: Installing dep via vcpkg]
    L --> M[Invoke vcpkgExe install dep]
    M --> N{LASTEXITCODE not equal to 0?}
    N -- Yes --> O[Write-Warning: Failed to install dep]
    N -- No --> P[Proceed to next dep]
    O --> P
    P --> Q{More deps?}
    Q -- Yes --> K
    Q -- No --> R[End Install-VCPKG-Dependency]
Loading

File-Level Changes

Change Details Files
Make Install-VCPKG-Dependency read dependency list from vcpkg.json instead of a hard-coded array and improve error handling when invoking vcpkg.
  • Use the shared script-level vcpkgPath variable to construct the vcpkg.exe path instead of a hard-coded absolute path.
  • Resolve vcpkg.json relative to the script root and abort with an error if the file is missing.
  • Parse vcpkg.json with ConvertFrom-Json and use its dependencies property as the package list, exiting early if the list is empty.
  • Invoke vcpkg.exe install for each dependency using unquoted arguments and emit a warning if any install command returns a non-zero exit code.
scripts/setup/install_deps_windows.ps1

Possibly linked issues

  • #[OPT] scripts/setup/install_deps_windows.ps1 一键安装脚本: They both improve install_deps_windows.ps1; the PR fixes Install-VCPKG-Dependency and automates deps via vcpkg.json.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你好——我给了一些整体性的反馈:

  • 现在 Install-VCPKG-Dependency 依赖 $script:vcpkgPath 已被设置;建议将 vcpkg 路径作为参数传入,或者在使用前先校验它,以避免在函数被单独调用时发生失败。
  • vcpkg.json 的 dependencies 字段可以是字符串数组也可以是对象数组;建议对 $depsList 做规范化处理(例如在需要时提取 .name),并在访问 .Count 之前先防御性地检查 $depsList 是否为 $null
  • 在调用 vcpkg 时,你可能希望更明确地暴露失败信息(例如,当任意安装失败时抛出异常或返回非零退出码),而不是只记录警告日志,这样调用方才能对依赖安装错误做出响应。
供 AI 代理使用的提示
Please address the comments from this code review:

## Overall Comments
- Install-VCPKG-Dependency now depends on `$script:vcpkgPath` being set; consider passing the vcpkg path as a parameter or validating it before use to avoid failures when the function is called in isolation.
- The vcpkg.json `dependencies` field can be either an array of strings or objects; consider normalizing `$depsList` (e.g., extracting `.name` when needed) and guarding against `$depsList` being `$null` before accessing `.Count`.
- When invoking vcpkg, you may want to surface failures more explicitly (e.g., throwing or returning a non-zero exit code when any install fails) instead of only logging a warning, so callers can react to dependency installation errors.

Sourcery 对开源项目免费——如果你觉得我们的评审有帮助,欢迎分享给更多人 ✨
帮我变得更有用!请在每条评论上点一下 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English

Hey - I've left some high level feedback:

  • Install-VCPKG-Dependency now depends on $script:vcpkgPath being set; consider passing the vcpkg path as a parameter or validating it before use to avoid failures when the function is called in isolation.
  • The vcpkg.json dependencies field can be either an array of strings or objects; consider normalizing $depsList (e.g., extracting .name when needed) and guarding against $depsList being $null before accessing .Count.
  • When invoking vcpkg, you may want to surface failures more explicitly (e.g., throwing or returning a non-zero exit code when any install fails) instead of only logging a warning, so callers can react to dependency installation errors.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Install-VCPKG-Dependency now depends on `$script:vcpkgPath` being set; consider passing the vcpkg path as a parameter or validating it before use to avoid failures when the function is called in isolation.
- The vcpkg.json `dependencies` field can be either an array of strings or objects; consider normalizing `$depsList` (e.g., extracting `.name` when needed) and guarding against `$depsList` being `$null` before accessing `.Count`.
- When invoking vcpkg, you may want to surface failures more explicitly (e.g., throwing or returning a non-zero exit code when any install fails) instead of only logging a warning, so callers can react to dependency installation errors.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 Summary

本次 PR 改进了 Windows 依赖安装脚本,将原本硬编码且空缺的依赖列表(含 TODO 注释)改为从 vcpkg.json 动态读取,并添加了基本的错误处理和退出码检查。这是一个有价值的修复,使脚本真正可用。

File Changes Risk Level Status
scripts/setup/install_deps_windows.ps1 +22/-6 🟢 Low Modified

⚠️ Warnings

  • 文件头信息:由于修改了文件,请确认文件头是否包含 @author OFFMN-SHARP 和 AGPL-3.0 许可证声明(如原文件缺失,建议补全)。

💡 Suggestions

  1. JSON 解析容错:建议添加 try-catch 块处理 ConvertFrom-Json,防止 JSON 格式错误时脚本崩溃。
  2. 变量存在性检查:使用 $script:vcpkgPath 前建议验证该变量是否存在(如 if (-not $script:vcpkgPath)),避免在 Install-VCPKG 未执行时调用此函数导致空路径错误。
  3. 路径健壮性:相对路径 ..\.. 依赖脚本存放位置,建议使用 (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent) 显式获取项目根目录。

📍 Inline Comments

Open Questions

  • 请确认 scripts/setup/install_deps_windows.ps1 文件头部是否已包含 AGPL-3.0 许可证声明和 @author OFFMN-SHARP 标记?如缺失,建议在本 PR 中补全。
  • $script:vcpkgPath 变量是否在脚本的其他位置(如 Install-VCPKG 函数)中定义?建议确认该变量的作用域和存在性检查。

统计: 0 🚨 | 2 ⚠️ | 3 💡

This review was generated by ArknightsAutoMachine AI Reviewer

)
function Install-VCPKG-Dependency {
$vcpkgExe = "$script:vcpkgPath\vcpkg.exe"
$jsonPath = Join-Path $PSScriptRoot "..\..\vcpkg.json"

Copy link
Copy Markdown

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) 显式获取仓库根目录,避免因脚本调用位置不同导致路径解析失败。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emmm,如果需求健壮性,我其实比较喜欢C#,并且……这玩意是内置在用户手册里的,so……如果用户根本看不懂文件放在哪里,到时候咱俩都得遭殃

}


$json = Get-Content $jsonPath -Raw | ConvertFrom-Json

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emmm,对哦,OK,下个版本改

foreach ($dep in $depsList) {
Write-Output "Installing $dep via vcpkg..."
& "$vcpkgPath" install "$dep"
& $vcpkgExe install $dep

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 [安全性] 建议验证 $dep 格式后再执行,防止潜在的命令注入(尽管 vcpkg 包名通常受限):

if ($dep -notmatch '^[\w\-\.]+$') {
    Write-Warning "Invalid dependency name format: $dep"
    continue
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你的意思是不信任Coredev们喽,你这是指桑骂槐,有反叛之心啊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant