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:
@@ -782,10 +782,7 @@ func linkMainPkg(ctx *context, pkg *packages.Package, pkgs []*aPackage, outputPa
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
// Generate main module file (needed for global variables even in library modes)
|
// Generate main module file (needed for global variables even in library modes)
|
||||||
entryPkg, err := genMainModule(ctx, llssa.PkgRuntime, pkg, needRuntime, needPyInit)
|
entryPkg := genMainModule(ctx, llssa.PkgRuntime, pkg, needRuntime, needPyInit)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
entryObjFile, err := exportObject(ctx, entryPkg.PkgPath, entryPkg.ExportFile, []byte(entryPkg.LPkg.String()))
|
entryObjFile, err := exportObject(ctx, entryPkg.PkgPath, entryPkg.ExportFile, []byte(entryPkg.LPkg.String()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import (
|
|||||||
llssa "github.com/goplus/llgo/ssa"
|
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
|
prog := ctx.prog
|
||||||
mainPkg := prog.NewPackage("", pkg.PkgPath+".main")
|
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 {
|
if ctx.buildConf.BuildMode != BuildModeExe {
|
||||||
return mainAPkg, nil
|
return mainAPkg
|
||||||
}
|
}
|
||||||
|
|
||||||
runtimeStub := defineWeakNoArgStub(mainPkg, "runtime.init")
|
runtimeStub := defineWeakNoArgStub(mainPkg, "runtime.init")
|
||||||
@@ -80,7 +80,7 @@ func genMainModule(ctx *context, rtPkgPath string, pkg *packages.Package, needRu
|
|||||||
defineStart(mainPkg, entryFn, argvValueType)
|
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 {
|
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 {
|
||||||
|
|||||||
@@ -29,10 +29,7 @@ func TestGenMainModuleExecutable(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
pkg := &packages.Package{PkgPath: "example.com/foo", ExportFile: "foo.a"}
|
pkg := &packages.Package{PkgPath: "example.com/foo", ExportFile: "foo.a"}
|
||||||
mod, err := genMainModule(ctx, llssa.PkgRuntime, pkg, true, true)
|
mod := genMainModule(ctx, llssa.PkgRuntime, pkg, true, true)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("genMainModule() error = %v", err)
|
|
||||||
}
|
|
||||||
if mod.ExportFile != "foo.a-main" {
|
if mod.ExportFile != "foo.a-main" {
|
||||||
t.Fatalf("unexpected export file: %s", mod.ExportFile)
|
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"}
|
pkg := &packages.Package{PkgPath: "example.com/foo", ExportFile: "foo.a"}
|
||||||
mod, err := genMainModule(ctx, llssa.PkgRuntime, pkg, false, false)
|
mod := genMainModule(ctx, llssa.PkgRuntime, pkg, false, false)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("genMainModule() error = %v", err)
|
|
||||||
}
|
|
||||||
ir := mod.LPkg.String()
|
ir := mod.LPkg.String()
|
||||||
if strings.Contains(ir, "define i32 @main") {
|
if strings.Contains(ir, "define i32 @main") {
|
||||||
t.Fatalf("library mode should not emit main function:\n%s", ir)
|
t.Fatalf("library mode should not emit main function:\n%s", ir)
|
||||||
|
|||||||
Reference in New Issue
Block a user