Skip to content

Commit

Permalink
Merge pull request #386 from xushiwei/q
Browse files Browse the repository at this point in the history
build: disable verbose info for deps
  • Loading branch information
xushiwei authored Jun 21, 2024
2 parents 364b693 + be0ce57 commit c1185a3
Showing 1 changed file with 30 additions and 21 deletions.
51 changes: 30 additions & 21 deletions internal/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,6 @@ func Do(args []string, conf *Config) {
}

llssa.Initialize(llssa.InitAll)
if verbose {
llssa.SetDebug(llssa.DbgFlagAll)
cl.SetDebug(cl.DbgFlagAll)
}

prog := llssa.NewProgram(nil)
sizes := prog.TypeSizes
Expand Down Expand Up @@ -175,15 +171,11 @@ func Do(args []string, conf *Config) {
patches := make(cl.Patches, len(altPkgPaths))
altSSAPkgs(progSSA, patches, altPkgs[1:], verbose)

ctx := &context{progSSA, prog, dedup, patches, make(map[string]none), mode, verbose}
pkgs := buildAllPkgs(ctx, initial)

// TODO(xsw): maybe we need trace runtime sometimes
llssa.SetDebug(0)
cl.SetDebug(0)
ctx := &context{progSSA, prog, dedup, patches, make(map[string]none), initial, mode}
pkgs := buildAllPkgs(ctx, initial, verbose)

var llFiles []string
dpkg := buildAllPkgs(ctx, altPkgs[noRt:])
dpkg := buildAllPkgs(ctx, altPkgs[noRt:], verbose)
for _, pkg := range dpkg {
if !strings.HasSuffix(pkg.ExportFile, ".ll") {
continue
Expand Down Expand Up @@ -231,13 +223,13 @@ type context struct {
dedup packages.Deduper
patches cl.Patches
built map[string]none
initial []*packages.Package
mode Mode
verbose bool
}

func buildAllPkgs(ctx *context, initial []*packages.Package) (pkgs []*aPackage) {
func buildAllPkgs(ctx *context, initial []*packages.Package, verbose bool) (pkgs []*aPackage) {
prog := ctx.prog
pkgs, errPkgs := allPkgs(ctx, initial)
pkgs, errPkgs := allPkgs(ctx, initial, verbose)
for _, errPkg := range errPkgs {
for _, err := range errPkg.Errors {
fmt.Fprintln(os.Stderr, err)
Expand All @@ -259,7 +251,7 @@ func buildAllPkgs(ctx *context, initial []*packages.Package) (pkgs []*aPackage)
pkg.ExportFile = ""
case cl.PkgLinkIR, cl.PkgLinkExtern, cl.PkgPyModule:
if isPkgInLLGo(pkg.PkgPath) {
pkg.ExportFile = concatPkgLinkFiles(pkg, ctx.verbose)
pkg.ExportFile = concatPkgLinkFiles(pkg, verbose)
} else {
// panic("todo")
// TODO(xsw): support packages out of llgo
Expand Down Expand Up @@ -301,7 +293,7 @@ func buildAllPkgs(ctx *context, initial []*packages.Package) (pkgs []*aPackage)
}
}
default:
buildPkg(ctx, aPkg)
buildPkg(ctx, aPkg, verbose)
setNeedRuntimeOrPyInit(pkg, prog.NeedRuntime, prog.NeedPyInit)
}
}
Expand Down Expand Up @@ -401,10 +393,10 @@ func linkMainPkg(pkg *packages.Package, pkgs []*aPackage, llFiles []string, conf
return
}

func buildPkg(ctx *context, aPkg *aPackage) {
func buildPkg(ctx *context, aPkg *aPackage, verbose bool) {
pkg := aPkg.Package
pkgPath := pkg.PkgPath
if debugBuild || ctx.verbose {
if debugBuild || verbose {
fmt.Fprintln(os.Stderr, pkgPath)
}
if canSkipToBuild(pkgPath) {
Expand All @@ -415,12 +407,21 @@ func buildPkg(ctx *context, aPkg *aPackage) {
if altPkg := aPkg.AltPkg; altPkg != nil {
syntax = append(syntax, altPkg.Syntax...)
}
showDetail := verbose && pkgExists(ctx.initial, pkg)
if showDetail {
llssa.SetDebug(llssa.DbgFlagAll)
cl.SetDebug(cl.DbgFlagAll)
}
ret, err := cl.NewPackageEx(ctx.prog, ctx.patches, aPkg.SSA, syntax)
if showDetail {
llssa.SetDebug(0)
cl.SetDebug(0)
}
check(err)
if needLLFile(ctx.mode) {
pkg.ExportFile += ".ll"
os.WriteFile(pkg.ExportFile, []byte(ret.String()), 0644)
if debugBuild || ctx.verbose {
if debugBuild || verbose {
fmt.Fprintf(os.Stderr, "==> Export %s: %s\n", aPkg.PkgPath, pkg.ExportFile)
}
}
Expand Down Expand Up @@ -468,9 +469,8 @@ type aPackage struct {
LPkg llssa.Package
}

func allPkgs(ctx *context, initial []*packages.Package) (all []*aPackage, errs []*packages.Package) {
func allPkgs(ctx *context, initial []*packages.Package, verbose bool) (all []*aPackage, errs []*packages.Package) {
prog := ctx.progSSA
verbose := ctx.verbose
built := ctx.built
packages.Visit(initial, nil, func(p *packages.Package) {
if p.Types != nil && !p.IllTyped {
Expand Down Expand Up @@ -732,6 +732,15 @@ func decodeFile(outFile string, zipf *zip.File) (err error) {
return
}

func pkgExists(initial []*packages.Package, pkg *packages.Package) bool {
for _, v := range initial {
if v == pkg {
return true
}
}
return false
}

func canSkipToBuild(pkgPath string) bool {
if _, ok := hasAltPkg[pkgPath]; ok {
return false
Expand Down

0 comments on commit c1185a3

Please sign in to comment.