Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
afd8ff9
CI:改为 PR 检查并加入隐私与作者扫描
qiyinxi Oct 30, 2026
eda2ad5
发版:加入 0.1.0 独立包和可复现校验
qiyinxi Oct 30, 2026
c5f8d75
修复开机竞态、执行桥状态和客体挂载时机
qiyinxi Oct 30, 2026
09bf632
Merge branch 'release/0.1.0' into fix/0.2.0
qiyinxi Oct 31, 2026
44dfb74
发版附件使用固定的 SHA256SUMS 文件名
qiyinxi Oct 31, 2026
9ab66d3
清理公开代码中的本机路径和私有说明
qiyinxi Oct 31, 2026
ac54012
清理测试夹具里的本机路径示例
qiyinxi Oct 31, 2026
0fe4117
CI:脚本测试在隔离模式下也能导入被测模块
qiyinxi Oct 31, 2026
da8edd6
Merge branch 'ci/checks' into release/0.1.0
qiyinxi Oct 31, 2026
7dc8948
发版:草稿前的重复检查放到带令牌的那一步
qiyinxi Oct 31, 2026
04d53f1
Merge branch 'release/0.1.0' into fix/0.2.0
qiyinxi Oct 31, 2026
80c7903
修好 bridge install 的回归,执行桥状态只问开完机的客体
qiyinxi Oct 31, 2026
e26c3f1
start 返回前确认 /sdcard 能写进文件
qiyinxi Oct 31, 2026
88248bf
发版说明不再预告 0.2.0 的自更新
qiyinxi Oct 31, 2026
f7e45fa
Merge branch 'release/0.1.0' into fix/0.2.0
qiyinxi Oct 31, 2026
4ceca4b
CI:setup-go 装 go.mod 里 toolchain 行的确切版本
qiyinxi Oct 31, 2026
5164aa5
Merge branch 'ci/checks' into release/0.1.0
qiyinxi Oct 31, 2026
ea495f7
发版:setup-go 装 go.mod 里 toolchain 行的确切版本
qiyinxi Oct 31, 2026
2b0cf9a
Merge branch 'release/0.1.0' into fix/0.2.0
qiyinxi Oct 31, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: ci

on:
pull_request:
workflow_dispatch:

permissions:
contents: read

env:
GOTOOLCHAIN: local

jobs:
checks:
runs-on: windows-2025
timeout-minutes: 20
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
fetch-depth: 0
# go.mod's go line is "go 1.26", which setup-go resolves to the newest 1.26.x; build.ps1 wants the exact
# toolchain line.
- name: go version
id: go
shell: pwsh
run: |
$v = (Select-String -LiteralPath go.mod -Pattern '^toolchain\s+go(\S+)' | Select-Object -First 1).Matches.Groups[1].Value
if (-not $v) { throw 'go.mod has no toolchain line' }
"version=$v" >> $env:GITHUB_OUTPUT
- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version: ${{ steps.go.outputs.version }}
cache: false
- name: gofmt
shell: pwsh
run: |
$bad = gofmt -l .
if ($bad) { $bad; throw 'gofmt required' }
- name: go vet
run: go vet ./...
- name: go test
run: go test ./...
- name: build
shell: pwsh
run: |
pwsh -NoProfile -File build.ps1
Get-FileHash out\tools\modavd.exe -Algorithm SHA256
Get-FileHash out\ModAVD.exe -Algorithm SHA256
- name: privacy scan
run: python -B -I -X utf8 scripts/privacy.py . --allowlist scripts/privacy-allowlist.json
- name: author check
shell: pwsh
env:
REPO_CHECK_BASE: ${{ github.event.pull_request.base.sha }}
REPO_CHECK_HEAD: ${{ github.event.pull_request.head.sha }}
REPO_CHECK_EVENT: ${{ github.event_name }}
run: |
if ($env:REPO_CHECK_EVENT -eq 'workflow_dispatch') {
Remove-Item Env:REPO_CHECK_BASE -ErrorAction SilentlyContinue
Remove-Item Env:REPO_CHECK_HEAD -ErrorAction SilentlyContinue
}
python -B -I -X utf8 scripts/repo_checks.py
- name: script tests
run: python -B -I -X utf8 scripts/test_repo_checks.py
123 changes: 123 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
name: release

on:
push:
tags: ["v*"]

permissions: {}

concurrency:
group: release-${{ github.ref_name }}
cancel-in-progress: false

env:
GOTOOLCHAIN: local

jobs:
build:
if: github.repository == 'ModAVD/ModAVDManager'
runs-on: windows-2025
timeout-minutes: 20
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
fetch-depth: 0
# the exact toolchain line, as in ci.yml (setup-go would resolve "go 1.26" to the newest 1.26.x)
- name: go version
id: go
shell: pwsh
run: |
$v = (Select-String -LiteralPath go.mod -Pattern '^toolchain\s+go(\S+)' | Select-Object -First 1).Matches.Groups[1].Value
if (-not $v) { throw 'go.mod has no toolchain line' }
"version=$v" >> $env:GITHUB_OUTPUT
- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version: ${{ steps.go.outputs.version }}
cache: false
- name: verify tag and ancestry
shell: pwsh
env:
TAG: ${{ github.ref_name }}
SHA: ${{ github.sha }}
run: |
if ($env:TAG -notmatch '^v\d+\.\d+\.\d+$') { throw "invalid tag: $env:TAG" }
git merge-base --is-ancestor $env:SHA origin/main
if ($LASTEXITCODE -ne 0) { throw 'tag is not on origin/main' }
- name: build and verify
shell: pwsh
env:
TAG: ${{ github.ref_name }}
run: |
$version = $env:TAG.Substring(1)
$want = (Select-String -LiteralPath 'internal/buildinfo/buildinfo.go' -Pattern 'Version = "([^"]+)"').Matches.Groups[1].Value
if ($want -ne $version) { throw "buildinfo.Version=$want, tag=$version" }
pwsh -NoProfile -File build.ps1 -Out out
if ($LASTEXITCODE -ne 0) { throw 'build.ps1 failed' }
$sums = @{}
foreach ($line in Get-Content "release/$version.SHA256SUMS.txt") { if ($line -match '^([0-9a-f]{64}) (.+)$') { $sums[$Matches[2]] = $Matches[1] } }
foreach ($name in @('ModAVD.exe', 'tools/modavd.exe')) {
$got = (Get-FileHash "out/$name" -Algorithm SHA256).Hash.ToLowerInvariant()
if ($got -ne $sums[$name]) { throw "$name hash mismatch" }
}
$zip = "ModAVDManager-$version-win-x64.zip"
go run ./internal/tools/mkzip -dir out -version $version -out $zip
if ($LASTEXITCODE -ne 0) { throw 'mkzip failed' }
$gotZip = (Get-FileHash $zip -Algorithm SHA256).Hash.ToLowerInvariant()
if ($gotZip -ne $sums[$zip]) { throw 'zip hash mismatch' }
New-Item -ItemType Directory -Force artifacts | Out-Null
Copy-Item $zip artifacts
Copy-Item "release/$version.SHA256SUMS.txt" "artifacts/SHA256SUMS.txt"
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: release-assets
path: artifacts
if-no-files-found: error

draft:
needs: build
runs-on: windows-2025
timeout-minutes: 10
permissions:
contents: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
fetch-depth: 1
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: release-assets
path: artifacts
- name: verify artifact
shell: pwsh
env:
TAG: ${{ github.ref_name }}
run: |
# Checked against the tag's own list, not only the copy that travelled with the artifact.
$version = $env:TAG.Substring(1)
$zip = "ModAVDManager-$version-win-x64.zip"
$sums = Get-Content -Raw "release/$version.SHA256SUMS.txt"
if ((Get-Content -Raw artifacts/SHA256SUMS.txt) -cne $sums) { throw 'artifact SHA256SUMS.txt differs from the tag' }
$have = (Get-ChildItem artifacts -File | ForEach-Object Name | Sort-Object) -join ','
$expect = (@($zip, 'SHA256SUMS.txt') | Sort-Object) -join ','
if ($have -cne $expect) { throw "unexpected artifact files: $have" }
$want = [regex]::Match($sums, "(?m)^([0-9a-f]{64}) $([regex]::Escape($zip))$").Groups[1].Value
$got = (Get-FileHash "artifacts/$zip" -Algorithm SHA256).Hash.ToLowerInvariant()
if (-not $want -or $got -ne $want) { throw 'downloaded zip hash mismatch' }
- name: create draft
shell: pwsh
env:
TAG: ${{ github.ref_name }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
run: |
$version = $env:TAG.Substring(1)
# Drafts are not bound to their tag, so one tag can collect several: list every release, drafts included.
$tags = gh api "repos/$env:GH_REPO/releases?per_page=100" --paginate --jq '.[].tag_name'
if ($LASTEXITCODE -ne 0) { throw 'cannot list releases' }
if ($tags -contains $env:TAG) { throw "a release for $env:TAG already exists (draft or published)" }
gh release create $env:TAG --draft --verify-tag --notes-file "release/$version.md" "artifacts/ModAVDManager-$version-win-x64.zip" artifacts/SHA256SUMS.txt
if ($LASTEXITCODE -ne 0) { throw 'gh release create failed' }
27 changes: 0 additions & 27 deletions .github/workflows/test.yml

This file was deleted.

23 changes: 18 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@

## 和 ModAVD 的关系

- 两个程序随 [ModAVD](https://github.com/ModAVD/ModAVD) 的 Release 包发布:包根目录的 `ModAVD.exe`(管理器)和 `tools\modavd.exe`(命令行、MCP)。只是使用的话,下载 ModAVD 的 Release 就行,不用自己编译。
- 本仓库只有这两个程序的源码。模拟器本身的补丁、安装说明和发版在 ModAVD 仓库。
- 本公开仓库是管理器和命令行程序的开发与发版依据,版本号独立维护,并单独提供 GitHub Release。
- ModAVD 整包仍会带着 `ModAVD.exe` 和 `tools\modavd.exe`,每次 ModAVD 发版会钉住使用的管理器版本与哈希。
- 单独下载包可在任意目录使用;给 `--root` 或设置 `MODAVD_ROOT` 指向 ModAVD 根目录,并按下面的哈希核对下载内容。不要把它解压到 ModAVD 根目录覆盖整包里的文件。

| 产物 | 源码 | 做什么 |
| --- | --- | --- |
Expand Down Expand Up @@ -58,7 +59,7 @@ modavd [--root <目录>] [--json] [--quiet] [--verbose] <命令> [参数]
| `create [--index N] [--title T] [--memory 6G] [--cpu N] [--data-gb N] [--fps 30\|60] [--no-bridge]` | 新建。默认带 arm64 执行桥,第一次开机时装上;`--no-bridge` 记下这台不要桥,以后开机也不装 |
| `set <i> [--title T] [--memory M] [--cpu N] [--fps F] [--data-gb N]` | 修改,下次开机生效。`--data-gb` 只能改大,游戏数据不动:模拟器(0.36 起)开机时扩磁盘镜像,开机后在线扩文件系统。0.36 之前按 16 GB 及以下建的盘只能扩到下一个备份组之前(16 GB 约到 30 GB) |
| `delete <i> --yes` | 删除已关机的实例,连同游戏数据 |
| `start <i> [--window] [--timeout 300] [--no-bridge]` | 开机,等开完并做完开机后的设置;实例还没有执行桥时接着装上,`--no-bridge` 这次不装 |
| `start <i> [--window] [--timeout 300] [--no-bridge]` | 开机,等开完并做完开机后的设置,返回前确认 `/sdcard` 能写进文件(一般这时早已就绪;最多再等 60 秒,到点只警告);实例还没有执行桥时接着装上,`--no-bridge` 这次不装 |
| `stop <i> [--force]`、`stop --all` | 关机:先让安卓正常关机,不成再 sync + kill;`--force` 是 sync + 强杀 |
| `restart <i> [--window] [--timeout 300] [--force] [--no-bridge]` | 关机再开机,选项同 `stop`、`start` |
| `bridge <i> install\|uninstall\|verify` | 装、卸、检查 arm64 执行桥;开机时会自动装,一般不用手动跑(见下) |
Expand All @@ -75,13 +76,16 @@ modavd [--root <目录>] [--json] [--quiet] [--verbose] <命令> [参数]
- modavd(命令行、MCP)和管理器每次开机都会看一眼:实例还没有桥,就在开机后的设置做完后装上,中间关机再冷启动一两次。只在这次是它拉起的模拟器时装;接管已经在运行的实例时不装。装不上只是警告,实例照常运行,下次开机再试。
- 不要桥的实例:新建时带 `--no-bridge`,或者之后跑 `bridge <i> uninstall`。两种都会在 `mas-avd.json` 里记下 `instances.<i>.bridge` 为 `false`,以后开机不再自动装;再 `bridge <i> install` 就恢复。`start` / `restart` 的 `--no-bridge` 只管这一次。
- `bridge` 调用 ModAVD 包里的 `tools\modavd-bridge.ps1`。`install`:需要时关机再开机,装上;已经装了的只在载荷有变时更新。`uninstall`:卸掉桥、开机标记和装桥时改成的 GL 传输方式(asg);退回更早的版本之前要先卸。实例原来关着的,做完再关掉。`verify`:只读核对,实例要开着。
- `info` / `list` / `status` 的 `bridge`:`off`(记了不要桥)、`pending`(下次由 modavd 拉起的开机会装)、`installed`(开着的客体里桥在)、`unknown`。只问已经开完机的客体;关着或还在开机的实例,开机标记在桥装好后一直留着,装失败时也在,所以首次开机做过、标记也在时是 `unknown`,要知道确切结果就开机后再查。
- 装桥期间(含其中的关机、冷启动)`busy` 为 `bridging`;这时 `delete`、再次 `bridge` 返回实例忙(退出码 5)。调用方不认识的 `busy` 取值一律当忙处理。
- 不经 modavd 或管理器开机的实例(别的程序直接拉起模拟器)不会自动装,要装就跑一次 `bridge <i> install`。

**机读输出**(`--json`):

- stdout 只有一行:`{"ok":true,"data":…}` 或 `{"ok":false,"error":{"code","message","advice"}}`。`data` 的字段见 `internal/emu/types.go`,snake_case,所有字段一直出现。
- 进度日志写 stderr,一行一个 JSON:`{"time","level","msg"}`。调用方不要把 stderr 并进 stdout。
- `version --json` 的 `protocol` 是契约版本,字段改了含义或删了才加一。
- 运行中的实例增加 `started_at_ms`(Unix 毫秒),原来的 `started_at` 保留。`stop --all` 即使部分失败也返回 `ok:true` 和结果列表,同时以第一个失败的退出码结束。

**退出码**:0 成功,1 内部错误,2 用法或参数不对,3 实例不存在,4 根目录没就绪 / 检查没通过 / 不支持,5 实例忙 / 已存在 / 端口被占,6 超时,7 启动失败,8 已取消。`shell` 不带 `--json` 时是客体命令的退出码,`adb` 是 adb 的退出码;`bridge` 不带 `--json` 时,`install` 后没装上、`uninstall` 后还在都是 1,`verify` 是脚本的退出码。

Expand Down Expand Up @@ -155,8 +159,17 @@ go test ./...
| `MODAVD_TEST_LIVE` | 设成 `1` 才跑碰真实环境的测试:看本机正在运行的模拟器、起真的 adb server。会碰到本机正在用的实例,平时不要设。 |

- `internal/avd`、`internal/root`、`internal/jsonord` 有一部分测试用 Python 3 运行 AUTO-MAS 的原始逻辑(如 `internal/avd/testdata/instances_ref.py`),和 Go 的输出逐字节对照,所以要装 Python 3。
- 有几项测试只读本机 `D:\ModAVD` 下的现成文件(`mas-avd.json`、实例配置、组件 APK),没有就跳过;`MODAVD_TEST_METADATA` 可以另指一份 `mas-avd.json`。
- CI(`.github/workflows/test.yml`)在 `windows-latest` 上跑 `go vet`、`go test` 和 `build.ps1`。
- 有几项测试只读本机 `D:\ModAVD` 下的现成文件(`mas-avd.json`、实例配置、组件 APK),没有就跳过;`MODAVD_TEST_METADATA` 可以另指一份 `mas-avd.json`,`MODAVD_TEST_SDK` 另指一个带 `platform-tools\adb.exe` 的 SDK,`MODAVD_TEST_VKLIBS` 指向放着原版和打过补丁的 `libvulkan_enc.so` 的目录(Vulkan 修复的逐字节对照)。
- CI(`.github/workflows/ci.yml`)在 `windows-2025` 上跑格式检查、`go vet`、`go test`、`build.ps1`、隐私扫描和作者检查;只在 PR 或手动触发时运行。

## 单独下载与哈希

- 每个版本的 GitHub Release 附 `ModAVDManager-<版本>-win-x64.zip` 和 `SHA256SUMS.txt`,后者和仓库里的 `release/<版本>.SHA256SUMS.txt` 是同一份。v0.1.0 是第一个独立版本,两个 exe 和 ModAVD 0.36.0 包里的逐字节相同。
- zip 没有顶层目录,里面是 `ModAVD.exe`、`tools\modavd.exe`、`LICENSE`、`NOTICE`、`LICENSES\Go-LICENSE.txt`,以及单独下载包的标记 `modavd-manager.json`(版本号和其余各文件的 SHA-256)。
- 核对:`Get-FileHash .\ModAVDManager-0.1.0-win-x64.zip -Algorithm SHA256`,和 `SHA256SUMS.txt` 里那一行比;解压出的两个 exe 也一样比。
- 自己编出同样的字节:Go 1.26.5、`GOTOOLCHAIN=local`,`pwsh -NoProfile -File build.ps1 -Out out`,再 `go run ./internal/tools/mkzip -dir out -version <版本>` 打 zip。
- 单独使用时给 `--root` 或设 `MODAVD_ROOT`,否则会提示找不到 ModAVD 根目录。不要把 zip 解压到 ModAVD 根目录里覆盖包里的那份。
- 单独下载的管理器不会自己更新,新版本要手动下载替换;ModAVD 包里的那份随 ModAVD 整包一起更新。

## 参与

Expand Down
8 changes: 4 additions & 4 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Build tools\modavd.exe reproducibly: the same source and Go version give the same bytes on any machine and path.
#
# pwsh -NoProfile -File tools\modavd\build.ps1 # -> tools\modavd\out\tools\modavd.exe, out\ModAVD.exe
# pwsh -NoProfile -File tools\modavd\build.ps1 -Out <dir> -Go <go1.26.5>\bin\go.exe
# pwsh -NoProfile -File tools\modavd\build.ps1 -Test # go vet + go test first
# pwsh -NoProfile -File build.ps1 # -> out\tools\modavd.exe, out\ModAVD.exe
# pwsh -NoProfile -File build.ps1 -Out <dir> -Go <go1.26.5>\bin\go.exe
# pwsh -NoProfile -File build.ps1 -Test # go vet + go test first
#
# modavd.exe is the console program (CLI, MCP); ModAVD.exe is the manager, a GUI-subsystem exe (-H=windowsgui, no
# console window when double-clicked) built from cmd/modavd-gui. In the package: <root>\tools\modavd.exe and
# <root>\ModAVD.exe.
#
# -trimpath keeps local paths (GOROOT under C:\Users, the source dir) out of the binary, which the release privacy scan
# would flag; -buildvcs=false keeps the private repo's commit and dirty flag out. GOTOOLCHAIN=local plus the check
# would flag; -buildvcs=false keeps repository metadata and dirty flags out. GOTOOLCHAIN=local plus the check
# against go.mod's toolchain line makes sure no other Go version builds it silently. No -X version stamp (see
# internal/buildinfo).

Expand Down
2 changes: 1 addition & 1 deletion cmd/modavd-gui/winres/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// the application manifest (RT_MANIFEST), as a COFF object with a single .rsrc section. The Go linker merges a
// package's .syso files into the executable, so the icon shows in Explorer and the taskbar with no extra tool.
//
// cd tools\modavd\cmd\modavd-gui && go run ./winres (or: go generate ./cmd/modavd-gui)
// go run ./cmd/modavd-gui/winres
//
// The output is deterministic (no timestamps), so the same icon gives the same bytes and release builds stay
// reproducible. Run it again only when modavd.ico or the manifest changes, and commit the .syso.
Expand Down
2 changes: 1 addition & 1 deletion internal/adb/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func hasDirPrefix(path, dir string) bool {

// resolvedPath is path with its links resolved, cleaned; the cleaned path itself when it cannot be resolved (it does
// not exist, access denied). filepath.EvalSymlinks alone is not enough: since Go 1.23 it leaves mount points unresolved
// on Windows, and a directory junction (C:\emu-src) is one.
// on Windows, and a directory junction (C:\sdk-src) is one.
func resolvedPath(path string) string {
if s, ok := finalPath(path); ok {
return filepath.Clean(s)
Expand Down
9 changes: 6 additions & 3 deletions internal/adb/real_adb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ const (
testScriptPort = 20076
)

// testSDK is an SDK whose adb.exe the test may run (only run, never modified).
// testSDK is an SDK whose adb.exe the test may run (only run, never modified): $MODAVD_TEST_SDK, else the package's.
func testSDK() string {
for _, sdk := range []string{`C:\emu-src\sdk-mas35`, `D:\ModAVD\sdk`} {
for _, sdk := range []string{os.Getenv("MODAVD_TEST_SDK"), `D:\ModAVD\sdk`} {
if sdk == "" {
continue
}
if st, err := os.Stat(filepath.Join(sdk, "platform-tools", "adb.exe")); err == nil && !st.IsDir() {
return sdk
}
Expand All @@ -47,7 +50,7 @@ func realRoot(t *testing.T) (*root.Root, string) {
t.Helper()
sdk := testSDK()
if sdk == "" {
t.Skip("没有可用的 adb.exe(C:\\emu-src\\sdk-mas35 / D:\\ModAVD\\sdk)")
t.Skip("没有可用的 adb.exe(MODAVD_TEST_SDK / D:\\ModAVD\\sdk)")
}
dir := tempDir(t)
meta, _ := json.Marshal(map[string]any{
Expand Down
Loading