// newEmbedResolver builds a list of files that may be embedded. This is
// approximately all files in a Bazel package including explicitly declared
// generated files and files in subdirectories without build files.
// Files in other Bazel packages are not listed, since it might not be possible
// to reference those files if they aren't listed in an export_files
// declaration.
//
// This function walks subdirectory trees and may be expensive. Don't call it
// unless a go:embed directive is actually present.
//
// dir is the absolute path to the directory containing the embed directive.
//
// rel is the relative path from the workspace root to the same directory
// (or "" if the directory is the workspace root itself).
//
// validBuildFileNames is the configured list of recognized build file names.
// These are used to identify Bazel packages in subdirectories that Gazelle
// did not visit.
//
// pkgRels is a set of relative paths from the workspace root to directories
// that contain (or will contain) build files. It doesn't need to contain
// entries for the entire workspace, but it should contain entries for
// subdirectories processed earlier (this avoids redundant O(n^2) I/O).
//
// subdirs, regFiles, and genFiles are lists of subdirectories, regular files,
// and declared generated files in dir, respectively.
newEmbedResolver builds a list of files that may be embedded. This is
approximately all files in a Bazel package including explicitly declared
generated files and files in subdirectories without build files.
Files in other Bazel packages are not listed, since it might not be possible
to reference those files if they aren't listed in an export_files
declaration.

This function walks subdirectory trees and may be expensive. Don't call it
unless a go:embed directive is actually present.

dir is the absolute path to the directory containing the embed directive.

rel is the relative path from the workspace root to the same directory
(or "" if the directory is the workspace root itself).

validBuildFileNames is the configured list of recognized build file names.
These are used to identify Bazel packages in subdirectories that Gazelle
did not visit.

pkgRels is a set of relative paths from the workspace root to directories
that contain (or will contain) build files. It doesn't need to contain
entries for the entire workspace, but it should contain entries for
subdirectories processed earlier (this avoids redundant O(n^2) I/O).

subdirs, regFiles, and genFiles are lists of subdirectories, regular files,
and declared generated files in dir, respectively.
// newEmbedResolver builds a list of files that may be embedded . This is // approximately all files in a Bazel package including explicitly declared // generated files and files in subdirectories without build files . // Files in other Bazel packages are not listed since it might not be possible // to reference those files if they aren ' t listed in an export_files // declaration . // // This function walks subdirectory trees and may be expensive . Don ' t call it // unless a go : embed directive is actually present . // // dir is the absolute path to the directory containing the embed directive . // // rel is the relative path from the workspace root to the same directory // ( or " " if the directory is the workspace root itself ) . // // validBuildFileNames is the configured list of recognized build file names . // These are used to identify Bazel packages in subdirectories that Gazelle // did not visit . // // pkgRels is a set of relative paths from the workspace root to directories // that contain ( or will contain ) build files . It doesn ' t need to contain // entries for the entire workspace but it should contain entries for // subdirectories processed earlier ( this avoids redundant O ( n^2 ) I / O ) . // // subdirs regFiles and genFiles are lists of subdirectories regular files // and declared generated files in dir respectively .
func newEmbedResolver(dir, rel string, validBuildFileNames []string, pkgRels map[string]bool, subdirs, regFiles, genFiles []string) *embedResolver {
	var files []embeddableFile
	for _, fs := range [...][]string{regFiles, genFiles} {
		for _, f := range fs {
			if !isBadEmbedName(f) {
				files = append(files, embeddableFile{path: f})
			}
		}
	}
	for _, subdir := range subdirs {
		err := filepath.Walk(filepath.Join(dir, subdir), func(p string, info os.FileInfo, err error) error {
			if err != nil {
				return err
			}
			fileRel, _ := filepath.Rel(dir, p)
			base := filepath.Base(p)
			if !info.IsDir() {
				if !isBadEmbedName(base) {
					files = append(files, embeddableFile{path: fileRel})
				}
				return nil
			}
			if isBadEmbedName(base) {
				return filepath.SkipDir
			}
			if pkgRels[path.Join(rel, fileRel)] {
				return filepath.SkipDir
			}
			for _, name := range validBuildFileNames {
				if _, err := os.Stat(filepath.Join(p, name)); err == nil {
					return filepath.SkipDir
				}
			}
			files = append(files, embeddableFile{path: fileRel, isDir: true})
			return nil
		})
		if err != nil {
			log.Printf("listing embeddable files in %s: %v", dir, err)
		}
	}
	return &embedResolver{files: files}
}
func newEmbedResolver ( dir , rel string , validBuildFileNames [ ] string , pkgRels map [ string ] bool , subdirs , regFiles , genFiles [ ] string ) * embedResolver { var files [ ] embeddableFile for _ , fs := range [ ... ] [ ] string { regFiles , genFiles } { for _ , f := range fs { if ! isBadEmbedName ( f ) { files = append ( files , embeddableFile { path : f } ) } } } for _ , subdir := range subdirs { err := filepath . Walk ( filepath . Join ( dir , subdir ) , func ( p string , info os . FileInfo , err error ) error { if err != nil { return err } fileRel , _ := filepath . Rel ( dir , p ) base := filepath . Base ( p ) if ! info . IsDir ( ) { if ! isBadEmbedName ( base ) { files = append ( files , embeddableFile { path : fileRel } ) } return nil } if isBadEmbedName ( base ) { return filepath . SkipDir } if pkgRels [ path . Join ( rel , fileRel ) ] { return filepath . SkipDir } for _ , name := range validBuildFileNames { if _ , err := os . Stat ( filepath . Join ( p , name ) ) ; err == nil { return filepath . SkipDir } } files = append ( files , embeddableFile { path : fileRel , isDir : true } ) return nil } ) if err != nil { log . Printf ( " " , dir , err ) } } return & embedResolver { files : files } }
newEmbedResolver builds a list of files that may be embedded.
newEmbedResolver builds a list of files that may be embedded .
// Directory contains a Go package and will contain a build file, // if it doesn't already. // Directory already contains a build file.