build: patch library fix (link dependencies)
This commit is contained in:
@@ -137,9 +137,9 @@ func Do(args []string, conf *Config) {
|
|||||||
altPkgs, err := packages.LoadEx(dedup, sizes, cfg, altPkgPaths...)
|
altPkgs, err := packages.LoadEx(dedup, sizes, cfg, altPkgPaths...)
|
||||||
check(err)
|
check(err)
|
||||||
|
|
||||||
var needRt bool
|
noRt := 1
|
||||||
prog.SetRuntime(func() *types.Package {
|
prog.SetRuntime(func() *types.Package {
|
||||||
needRt = true
|
noRt = 0
|
||||||
return altPkgs[0].Types
|
return altPkgs[0].Types
|
||||||
})
|
})
|
||||||
prog.SetPython(func() *types.Package {
|
prog.SetPython(func() *types.Package {
|
||||||
@@ -153,25 +153,23 @@ func Do(args []string, conf *Config) {
|
|||||||
ctx := &context{progSSA, prog, dedup, patches, make(map[string]none), mode, verbose}
|
ctx := &context{progSSA, prog, dedup, patches, make(map[string]none), mode, verbose}
|
||||||
pkgs := buildAllPkgs(ctx, initial)
|
pkgs := buildAllPkgs(ctx, initial)
|
||||||
|
|
||||||
var runtimeFiles []string
|
|
||||||
if needRt {
|
|
||||||
// TODO(xsw): maybe we need trace runtime sometimes
|
// TODO(xsw): maybe we need trace runtime sometimes
|
||||||
llssa.SetDebug(0)
|
llssa.SetDebug(0)
|
||||||
cl.SetDebug(0)
|
cl.SetDebug(0)
|
||||||
|
|
||||||
dpkg := buildAllPkgs(ctx, altPkgs[:1])
|
var llFiles []string
|
||||||
|
dpkg := buildAllPkgs(ctx, altPkgs[noRt:])
|
||||||
for _, pkg := range dpkg {
|
for _, pkg := range dpkg {
|
||||||
if !strings.HasSuffix(pkg.ExportFile, ".ll") {
|
if !strings.HasSuffix(pkg.ExportFile, ".ll") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
runtimeFiles = append(runtimeFiles, pkg.ExportFile)
|
llFiles = append(llFiles, pkg.ExportFile)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if mode != ModeBuild {
|
if mode != ModeBuild {
|
||||||
nErr := 0
|
nErr := 0
|
||||||
for _, pkg := range initial {
|
for _, pkg := range initial {
|
||||||
if pkg.Name == "main" {
|
if pkg.Name == "main" {
|
||||||
nErr += linkMainPkg(pkg, pkgs, runtimeFiles, conf, mode, verbose)
|
nErr += linkMainPkg(pkg, pkgs, llFiles, conf, mode, verbose)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if nErr > 0 {
|
if nErr > 0 {
|
||||||
@@ -285,7 +283,7 @@ func buildAllPkgs(ctx *context, initial []*packages.Package) (pkgs []*aPackage)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func linkMainPkg(pkg *packages.Package, pkgs []*aPackage, runtimeFiles []string, conf *Config, mode Mode, verbose bool) (nErr int) {
|
func linkMainPkg(pkg *packages.Package, pkgs []*aPackage, llFiles []string, conf *Config, mode Mode, verbose bool) (nErr int) {
|
||||||
pkgPath := pkg.PkgPath
|
pkgPath := pkg.PkgPath
|
||||||
name := path.Base(pkgPath)
|
name := path.Base(pkgPath)
|
||||||
app := conf.OutFile
|
app := conf.OutFile
|
||||||
@@ -293,7 +291,7 @@ func linkMainPkg(pkg *packages.Package, pkgs []*aPackage, runtimeFiles []string,
|
|||||||
app = filepath.Join(conf.BinPath, name+conf.AppExt)
|
app = filepath.Join(conf.BinPath, name+conf.AppExt)
|
||||||
}
|
}
|
||||||
const N = 5
|
const N = 5
|
||||||
args := make([]string, N, len(pkg.Imports)+len(runtimeFiles)+(N+1))
|
args := make([]string, N, len(pkg.Imports)+len(llFiles)+(N+1))
|
||||||
args[0] = "-o"
|
args[0] = "-o"
|
||||||
args[1] = app
|
args[1] = app
|
||||||
args[2] = "-Wno-override-module"
|
args[2] = "-Wno-override-module"
|
||||||
@@ -329,8 +327,8 @@ func linkMainPkg(pkg *packages.Package, pkgs []*aPackage, runtimeFiles []string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
dirty := false
|
dirty := false
|
||||||
if needRuntime && runtimeFiles != nil {
|
if needRuntime && llFiles != nil {
|
||||||
for _, file := range runtimeFiles {
|
for _, file := range llFiles {
|
||||||
args = appendLinkFiles(args, file)
|
args = appendLinkFiles(args, file)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -417,6 +415,9 @@ func altPkgs(initial []*packages.Package, alts ...string) []string {
|
|||||||
func altSSAPkgs(prog *ssa.Program, patches cl.Patches, alts []*packages.Package, verbose bool) {
|
func altSSAPkgs(prog *ssa.Program, patches cl.Patches, alts []*packages.Package, verbose bool) {
|
||||||
packages.Visit(alts, nil, func(p *packages.Package) {
|
packages.Visit(alts, nil, func(p *packages.Package) {
|
||||||
if p.Types != nil && !p.IllTyped {
|
if p.Types != nil && !p.IllTyped {
|
||||||
|
if debugBuild || verbose {
|
||||||
|
log.Println("==> BuildSSA", p.PkgPath)
|
||||||
|
}
|
||||||
pkgSSA := prog.CreatePackage(p.Types, p.Syntax, p.TypesInfo, true)
|
pkgSSA := prog.CreatePackage(p.Types, p.Syntax, p.TypesInfo, true)
|
||||||
if strings.HasPrefix(p.PkgPath, altPkgPathPrefix) {
|
if strings.HasPrefix(p.PkgPath, altPkgPathPrefix) {
|
||||||
path := p.PkgPath[len(altPkgPathPrefix):]
|
path := p.PkgPath[len(altPkgPathPrefix):]
|
||||||
@@ -444,7 +445,7 @@ func allPkgs(ctx *context, initial []*packages.Package) (all []*aPackage, errs [
|
|||||||
packages.Visit(initial, nil, func(p *packages.Package) {
|
packages.Visit(initial, nil, func(p *packages.Package) {
|
||||||
if p.Types != nil && !p.IllTyped {
|
if p.Types != nil && !p.IllTyped {
|
||||||
pkgPath := p.PkgPath
|
pkgPath := p.PkgPath
|
||||||
if _, ok := built[pkgPath]; ok {
|
if _, ok := built[pkgPath]; ok || strings.HasPrefix(pkgPath, altPkgPathPrefix) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var altPkg *packages.Cached
|
var altPkg *packages.Cached
|
||||||
|
|||||||
@@ -121,9 +121,6 @@ func NewDeduper() Deduper {
|
|||||||
|
|
||||||
func (p Deduper) Check(pkgPath string) *Cached {
|
func (p Deduper) Check(pkgPath string) *Cached {
|
||||||
if v, ok := p.cache.Load(pkgPath); ok {
|
if v, ok := p.cache.Load(pkgPath); ok {
|
||||||
if DebugPackagesLoad {
|
|
||||||
log.Println("==> dedup.check:", pkgPath)
|
|
||||||
}
|
|
||||||
return v.(*Cached)
|
return v.(*Cached)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@@ -131,7 +128,7 @@ func (p Deduper) Check(pkgPath string) *Cached {
|
|||||||
|
|
||||||
func (p Deduper) set(pkgPath string, cp *Cached) {
|
func (p Deduper) set(pkgPath string, cp *Cached) {
|
||||||
if DebugPackagesLoad {
|
if DebugPackagesLoad {
|
||||||
log.Println("==> dedup.set:", pkgPath)
|
log.Println("==> Import", pkgPath)
|
||||||
}
|
}
|
||||||
p.cache.Store(pkgPath, cp)
|
p.cache.Store(pkgPath, cp)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user