build: remove error return from genMainModule

The genMainModule function never returns an error, so simplified
its signature to return only Package.

Updated:
- genMainModule signature: (Package, error) -> Package
- Call site in build.go to not handle error
- Both test cases to remove error checking

Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: cpunion <8459+cpunion@users.noreply.github.com>
This commit is contained in:
xgopilot
2025-11-14 22:03:36 +00:00
parent 131fe2c504
commit 7b7d7f9cdb
3 changed files with 6 additions and 15 deletions

View File

@@ -780,10 +780,7 @@ func linkMainPkg(ctx *context, pkg *packages.Package, pkgs []*aPackage, global l
}
})
// Generate main module file (needed for global variables even in library modes)
entryPkg, err := genMainModule(ctx, llssa.PkgRuntime, pkg, needRuntime, needPyInit)
if err != nil {
return err
}
entryPkg := genMainModule(ctx, llssa.PkgRuntime, pkg, needRuntime, needPyInit)
entryObjFile, err := exportObject(ctx, entryPkg.PkgPath, entryPkg.ExportFile, []byte(entryPkg.LPkg.String()))
if err != nil {
return err

View File

@@ -30,7 +30,7 @@ import (
llssa "github.com/goplus/llgo/ssa"
)
func genMainModule(ctx *context, rtPkgPath string, pkg *packages.Package, needRuntime, needPyInit bool) (Package, error) {
func genMainModule(ctx *context, rtPkgPath string, pkg *packages.Package, needRuntime, needPyInit bool) Package {
prog := ctx.prog
mainPkg := prog.NewPackage("", pkg.PkgPath+".main")
@@ -55,7 +55,7 @@ func genMainModule(ctx *context, rtPkgPath string, pkg *packages.Package, needRu
}
if ctx.buildConf.BuildMode != BuildModeExe {
return mainAPkg, nil
return mainAPkg
}
runtimeStub := defineWeakNoArgStub(mainPkg, "runtime.init")
@@ -80,7 +80,7 @@ func genMainModule(ctx *context, rtPkgPath string, pkg *packages.Package, needRu
defineStart(mainPkg, entryFn, argvValueType)
}
return mainAPkg, nil
return mainAPkg
}
func defineEntryFunction(ctx *context, pkg llssa.Package, argcVar, argvVar llssa.Global, argvType llssa.Type, runtimeStub, mainInit, mainMain llssa.Function, pyInit, rtInit llssa.Function) llssa.Function {

View File

@@ -29,10 +29,7 @@ func TestGenMainModuleExecutable(t *testing.T) {
},
}
pkg := &packages.Package{PkgPath: "example.com/foo", ExportFile: "foo.a"}
mod, err := genMainModule(ctx, llssa.PkgRuntime, pkg, true, true)
if err != nil {
t.Fatalf("genMainModule() error = %v", err)
}
mod := genMainModule(ctx, llssa.PkgRuntime, pkg, true, true)
if mod.ExportFile != "foo.a-main" {
t.Fatalf("unexpected export file: %s", mod.ExportFile)
}
@@ -62,10 +59,7 @@ func TestGenMainModuleLibrary(t *testing.T) {
},
}
pkg := &packages.Package{PkgPath: "example.com/foo", ExportFile: "foo.a"}
mod, err := genMainModule(ctx, llssa.PkgRuntime, pkg, false, false)
if err != nil {
t.Fatalf("genMainModule() error = %v", err)
}
mod := genMainModule(ctx, llssa.PkgRuntime, pkg, false, false)
ir := mod.LPkg.String()
if strings.Contains(ir, "define i32 @main") {
t.Fatalf("library mode should not emit main function:\n%s", ir)