diff --git a/build_defs/go.build_defs b/build_defs/go.build_defs index 8de215f..d827277 100644 --- a/build_defs/go.build_defs +++ b/build_defs/go.build_defs @@ -1621,9 +1621,10 @@ def _go_pkg_info(name:str, srcs:list, visibility:list, importconfig:str=None, im install_flags = "" for i in install: install_flags += f" -p {i}" if i else " -p ." + target = canonicalise(":" + name) if module and not subrepo: - cmd = f'$TOOL m -m {module} {install_flags}' + cmd = f'$TOOL m -m {module} -t {target} {install_flags}' else: # The import path `go tool compile` expects for a binary target (i.e. `-p main`) doesn't match what we expect in # the driver response i.e. the package dir. We also don't want to set the package name, as that is something @@ -1633,7 +1634,7 @@ def _go_pkg_info(name:str, srcs:list, visibility:list, importconfig:str=None, im import_path = _get_import_path("", "") else: import_path = _get_import_path(package, import_path) - cmd = f'$TOOL p -i "{import_path}" -m "{import_path}:$PKG_DIR/{package}.a"' + cmd = f'$TOOL p -i "{import_path}" -t "{target}" -m "{import_path}:$PKG_DIR/{package}.a"' if subrepo: cmd = f"{cmd} -s {subrepo}" if module: diff --git a/tools/driver/packages/packages.go b/tools/driver/packages/packages.go index 6f7522b..619ba1b 100644 --- a/tools/driver/packages/packages.go +++ b/tools/driver/packages/packages.go @@ -214,7 +214,8 @@ func loadPackageInfo(files []string, mode packages.LoadMode) ([]*packages.Packag return nil, err } // N.B. deliberate not to close these here, they happen exactly when needed. - whatinputs := plz(append([]string{"query", "whatinputs", "--ignore_unknown" }, files...)...) + whatinputs := plz("query", "whatinputs", "--ignore_unknown", "-") + whatinputs.Stdin = strings.NewReader(strings.Join(files, "\n")) whatinputs.Stdout = w1 args := []string{"query", "deps", "-", "--hidden", "-i", "go_pkg_info", "-i", "go_src"} if (mode & packages.NeedExportFile) != 0 { @@ -342,7 +343,11 @@ func directoriesToFiles(in []string, includeTests bool) ([]string, error) { if err := filepath.WalkDir(strings.TrimSuffix(x, "/..."), func(path string, d fs.DirEntry, err error) error { if err != nil { return err - } else if strings.HasSuffix(path, ".go") && (d.Type()&fs.ModeSymlink) == 0 { + } + if d.Name() =="plz-out" { + return filepath.SkipDir + } + if strings.HasSuffix(path, ".go") && (d.Type()&fs.ModeSymlink) == 0 { files = append(files, path) } return nil diff --git a/tools/please_go/packageinfo/packageinfo.go b/tools/please_go/packageinfo/packageinfo.go index 8e547ac..f8d8784 100644 --- a/tools/please_go/packageinfo/packageinfo.go +++ b/tools/please_go/packageinfo/packageinfo.go @@ -20,7 +20,7 @@ import ( ) // WritePackageInfo writes a series of package info files to the given file. -func WritePackageInfo(importPath string, srcRoot, importconfig string, imports map[string]string, installPkgs []string, subrepo, module string, w io.Writer) error { +func WritePackageInfo(importPath, srcRoot, target, importconfig string, imports map[string]string, installPkgs []string, subrepo, module string, w io.Writer) error { // Discover all Go files in the module goFiles := map[string][]string{} module = modulePath(module, importPath) @@ -63,7 +63,7 @@ func WritePackageInfo(importPath string, srcRoot, importconfig string, imports m pkgs := make([]*packages.Package, 0, len(goFiles)) for dir := range goFiles { pkgDir := strings.TrimPrefix(strings.TrimPrefix(dir, srcRoot), "/") - pkg, err := createPackage(filepath.Join(importPath, pkgDir), dir, subrepo, module) + pkg, err := createPackage(filepath.Join(importPath, pkgDir), dir, target, subrepo, module) if _, ok := err.(*build.NoGoError); ok { continue // Don't really care, this happens sometimes for modules } else if err != nil { @@ -111,7 +111,7 @@ func WritePackageInfo(importPath string, srcRoot, importconfig string, imports m return e.Encode(pkgs) } -func createPackage(pkgPath, pkgDir, subrepo, module string) (*packages.Package, error) { +func createPackage(pkgPath, pkgDir, target, subrepo, module string) (*packages.Package, error) { if pkgDir == "" || pkgDir == "." { // This happens when we're in the repo root, ImportDir refuses to read it for some reason. path, err := filepath.Abs(pkgDir) @@ -125,13 +125,13 @@ func createPackage(pkgPath, pkgDir, subrepo, module string) (*packages.Package, return nil, err } bpkg.ImportPath = pkgPath - return FromBuildPackage(bpkg, subrepo, module), nil + return FromBuildPackage(bpkg, target, subrepo, module), nil } // FromBuildPackage creates a packages Package from a build Package. -func FromBuildPackage(pkg *build.Package, subrepo, module string) *packages.Package { +func FromBuildPackage(pkg *build.Package, target, subrepo, module string) *packages.Package { p := &packages.Package{ - ID: pkg.ImportPath, + ID: target, Name: pkg.Name, PkgPath: pkg.ImportPath, GoFiles: make([]string, len(pkg.GoFiles)), diff --git a/tools/please_go/please_go.go b/tools/please_go/please_go.go index c34de65..c0de7ed 100644 --- a/tools/please_go/please_go.go +++ b/tools/please_go/please_go.go @@ -78,12 +78,14 @@ var opts = struct { ImportMap map[string]string `short:"m" long:"import_map" description:"Existing map of imports"` Subrepo string `short:"s" long:"subrepo" description:"Subrepo root that this package is within"` Module string `long:"mod" description:"The module this is within, if present"` + Target string `short:"t" long:"target" description:"The build target for this package"` } `command:"package_info" alias:"p" description:"Creates an info file about a Go package"` ModuleInfo struct { ModulePath string `short:"m" long:"module_path" required:"true" description:"Import path of the module in question"` Srcs string `long:"srcs" env:"SRCS_SRCS" required:"true" description:"Source files of the module"` ImportConfig string `long:"importconfig" env:"SRCS_IC" description:"Importconfig file for locating gc export data"` Packages []string `short:"p" long:"packages" description:"Packages to include in the module"` + Target string `short:"t" long:"target" description:"The build target for this package"` } `command:"module_info" alias:"m" description:"Creates an info file about a series of packages in a go_module"` Generate struct { SrcRoot string `short:"r" long:"src_root" description:"The src root of the module to inspect"` @@ -177,14 +179,14 @@ var subCommands = map[string]func() int{ }, "package_info": func() int { pi := opts.PackageInfo - if err := packageinfo.WritePackageInfo(pi.ImportPath, pi.Pkg, "", pi.ImportMap, nil, pi.Subrepo, pi.Module, os.Stdout); err != nil { + if err := packageinfo.WritePackageInfo(pi.ImportPath, pi.Pkg, pi.Target, "", pi.ImportMap, nil, pi.Subrepo, pi.Module, os.Stdout); err != nil { log.Fatalf("failed to write package info: %s", err) } return 0 }, "module_info": func() int { mi := opts.ModuleInfo - if err := packageinfo.WritePackageInfo(mi.ModulePath, mi.Srcs, mi.ImportConfig, nil, mi.Packages, "", "", os.Stdout); err != nil { + if err := packageinfo.WritePackageInfo(mi.ModulePath, mi.Srcs, mi.Target, mi.ImportConfig, nil, mi.Packages, "", "", os.Stdout); err != nil { log.Fatalf("failed to write module info: %s", err) } return 0