From c61b128d69a631f087dc49ac5e40de28331c0cd7 Mon Sep 17 00:00:00 2001 From: rgodden <7768980+goddenrich@users.noreply.github.com> Date: Wed, 4 Feb 2026 15:59:49 +0000 Subject: [PATCH] find embed files and embed patterns --- tools/driver/packages/packages.go | 37 +++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/tools/driver/packages/packages.go b/tools/driver/packages/packages.go index 80759172..bcf0dddc 100644 --- a/tools/driver/packages/packages.go +++ b/tools/driver/packages/packages.go @@ -157,16 +157,17 @@ func packagesToResponse(rootpath string, pkgs []*packages.Package, dirs map[stri for i, file := range pkg.GoFiles { // This is pretty awkward; we need to try to figure out where these files exist now, // which isn't particularly clear to the build actions that generated them. - if pathExists(file) { - pkg.GoFiles[i] = filepath.Join(rootpath, file) - } else if path := filepath.Join(rootpath, "plz-out/subrepos", file); pathExists(path) { - pkg.GoFiles[i] = path - } else if path := filepath.Join(rootpath, "plz-out/gen", file); pathExists(path) { - pkg.GoFiles[i] = path - } + pkg.GoFiles[i] = findFile(rootpath, file) } pkg.CompiledGoFiles = pkg.GoFiles pkg.ExportFile = filepath.Join(rootpath, pkg.ExportFile) + for i, file := range pkg.EmbedFiles { + pkg.EmbedFiles[i] = findFile(rootpath, file) + } + for i, pattern := range pkg.EmbedPatterns { + pkg.EmbedPatterns[i] = findFilePattern(rootpath, pattern) + } + } if !seenRuntime { // Handle stdlib imports if we didn't already find them @@ -190,6 +191,28 @@ func packagesToResponse(rootpath string, pkgs []*packages.Package, dirs map[stri }, nil } +func findFile(rootpath, file string) string { + if pathExists(file) { + return filepath.Join(rootpath, file) + } else if path := filepath.Join(rootpath, "plz-out/subrepos", file); pathExists(path) { + return path + } else if path := filepath.Join(rootpath, "plz-out/gen", file); pathExists(path) { + return path + } + return filepath.Join(rootpath, file) +} + +func findFilePattern(rootpath, pattern string) string { + if matches, err := filepath.Glob(filepath.Join(rootpath, pattern)); err != nil && len(matches) > 0 { + return filepath.Join(rootpath, pattern) + } else if matches, err := filepath.Glob(filepath.Join(rootpath, "plz-out/subrepos", pattern)); err != nil && len(matches) > 0 { + return filepath.Join(rootpath, "plz-out/subrepos", pattern) + } else if matches, err := filepath.Glob(filepath.Join(rootpath, "plz-out/gen", pattern)); err != nil && len(matches) > 0 { + return filepath.Join(rootpath, "plz-out/gen", pattern) + } + return filepath.Join(rootpath, pattern) +} + // loadPackageInfo loads all the package information by executing Please. // A cooler way of handling this in future would be to do this in-process; for that we'd // need to define the SDK we keep talking about as a supported programmatic interface.