plugindev: generate go.mod without local absolute replace; auto-download SDK module on first build

- init 生成的 go.mod 只 require SDK 线上版本(gitcode.com/JianFeeeee/homeagent-sdk v0.8.0),不再写本地绝对路径 replace
- build 仅在显式指定(plg.json sdk_path 或 --sdk-path)时写入 replace
- 首次构建自动执行 go mod download <sdk_module> 生成 go.sum(修复无 go.sum 构建失败)
- 修正 ensureGoMod 模块名解析(支持 require 行与 require 块)
This commit is contained in:
root
2026-07-31 13:12:32 +08:00
parent bc1a005885
commit 62447e3952
4 changed files with 51 additions and 33 deletions

View File

@ -61,7 +61,6 @@ type TemplateData struct {
GoVersion string
SDKModule string
SDKVersion string
SDKReplace string
// C ABI
CABIVersion int
@ -118,19 +117,15 @@ func cmdInit(args []string) {
CABIHeader: tmplCABIHeader,
}
// Detect SDK info for Go plugin go.mod
// Detect SDK info for Go plugin go.mod.
// 生成的 go.mod 只 require SDK 线上模块版本,不写本地路径 replace
// 本地调试请用 `plugindev build --sdk-path <path>` 或手动加 replace。
if !isLua {
sdkMod, goVer, sdkPath, sdkVer := detectSDKInfo()
sdkReplace := sdkPath
// Make replace path absolute and use forward slashes
if abs, err := filepath.Abs(sdkPath); err == nil {
sdkReplace = strings.ReplaceAll(abs, "\\", "/")
}
sdkMod, goVer, _, sdkVer := detectSDKInfo()
data.ModulePath = name
data.GoVersion = goVer
data.SDKModule = sdkMod
data.SDKVersion = "v" + sdkVer
data.SDKReplace = sdkReplace
}
if err := os.MkdirAll(dir, 0755); err != nil {