build: patch package with ID

This commit is contained in:
Li Jie
2025-01-10 18:16:42 +08:00
parent 227f6a4ed7
commit d5d2d6826f

View File

@@ -288,11 +288,11 @@ func buildAllPkgs(ctx *context, initial []*packages.Package, verbose bool) (pkgs
built := ctx.built built := ctx.built
for _, aPkg := range pkgs { for _, aPkg := range pkgs {
pkg := aPkg.Package pkg := aPkg.Package
if _, ok := built[pkg.PkgPath]; ok { if _, ok := built[pkg.ID]; ok {
pkg.ExportFile = "" pkg.ExportFile = ""
continue continue
} }
built[pkg.PkgPath] = none{} built[pkg.ID] = none{}
switch kind, param := cl.PkgKindOf(pkg.Types); kind { switch kind, param := cl.PkgKindOf(pkg.Types); kind {
case cl.PkgDeclOnly: case cl.PkgDeclOnly:
// skip packages that only contain declarations // skip packages that only contain declarations
@@ -620,8 +620,8 @@ const (
func altPkgs(initial []*packages.Package, alts ...string) []string { func altPkgs(initial []*packages.Package, alts ...string) []string {
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 {
if _, ok := hasAltPkg[p.PkgPath]; ok { if _, ok := hasAltPkg[p.ID]; ok {
alts = append(alts, altPkgPathPrefix+p.PkgPath) alts = append(alts, altPkgPathPrefix+p.ID)
} }
} }
}) })
@@ -632,11 +632,11 @@ func altSSAPkgs(prog *ssa.Program, patches cl.Patches, alts []*packages.Package,
packages.Visit(alts, nil, func(p *packages.Package) { packages.Visit(alts, nil, func(p *packages.Package) {
if typs := p.Types; typs != nil && !p.IllTyped { if typs := p.Types; typs != nil && !p.IllTyped {
if debugBuild || verbose { if debugBuild || verbose {
log.Println("==> BuildSSA", p.PkgPath) log.Println("==> BuildSSA", p.ID)
} }
pkgSSA := prog.CreatePackage(typs, p.Syntax, p.TypesInfo, true) pkgSSA := prog.CreatePackage(typs, p.Syntax, p.TypesInfo, true)
if strings.HasPrefix(p.PkgPath, altPkgPathPrefix) { if strings.HasPrefix(p.ID, altPkgPathPrefix) {
path := p.PkgPath[len(altPkgPathPrefix):] path := p.ID[len(altPkgPathPrefix):]
patches[path] = cl.Patch{Alt: pkgSSA, Types: typepatch.Clone(typs)} patches[path] = cl.Patch{Alt: pkgSSA, Types: typepatch.Clone(typs)}
if debugBuild || verbose { if debugBuild || verbose {
log.Println("==> Patching", path) log.Println("==> Patching", path)
@@ -683,10 +683,10 @@ func allPkgs(ctx *context, initial []*packages.Package, verbose bool) (all []*aP
} }
func createSSAPkg(prog *ssa.Program, p *packages.Package, verbose bool) *ssa.Package { func createSSAPkg(prog *ssa.Program, p *packages.Package, verbose bool) *ssa.Package {
pkgSSA := prog.ImportedPackage(p.PkgPath) pkgSSA := prog.ImportedPackage(p.ID)
if pkgSSA == nil { if pkgSSA == nil {
if debugBuild || verbose { if debugBuild || verbose {
log.Println("==> BuildSSA", p.PkgPath) log.Println("==> BuildSSA", p.ID)
} }
pkgSSA = prog.CreatePackage(p.Types, p.Syntax, p.TypesInfo, true) pkgSSA = prog.CreatePackage(p.Types, p.Syntax, p.TypesInfo, true)
pkgSSA.Build() // TODO(xsw): build concurrently pkgSSA.Build() // TODO(xsw): build concurrently