Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions tools/driver/packages/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down