Skip to content

Commit

Permalink
Fix go:embed failing to add embedsrcs for subdirectories named bu…
Browse files Browse the repository at this point in the history
…ild (bazel-contrib#1539)

* Only consider filepath with build in the name only if they are not directories

* Add tests for the nested build directory
  • Loading branch information
sgavinio authored May 24, 2023
1 parent 9b1af8f commit a1be474
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion language/go/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func newEmbedResolver(dir, rel string, validBuildFileNames []string, pkgRels map
return filepath.SkipDir
}
for _, name := range validBuildFileNames {
if _, err := os.Stat(filepath.Join(p, name)); err == nil {
if bFileInfo, err := os.Stat(filepath.Join(p, name)); err == nil && !bFileInfo.IsDir() {
// Directory already contains a build file.
return filepath.SkipDir
}
Expand Down
1 change: 1 addition & 0 deletions language/go/testdata/embedsrcs/BUILD.want
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ go_library(
"m_static.txt",
"n_/static.txt",
"o_dir/_hidden.txt",
"p_dir/build.old/static.txt",
],
importpath = "example.com/repo/embedsrcs",
visibility = ["//visibility:public"],
Expand Down
2 changes: 1 addition & 1 deletion language/go/testdata/embedsrcs/embedsrcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package embedsrcs

import "embed"

//go:embed *m_* n_/* all:o*
//go:embed *m_* n_/* p_dir/* all:o*
var fs embed.FS
2 changes: 2 additions & 0 deletions language/go/testdata/embedsrcs/p_dir/build.old/static.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# p_dir/build.old/static.txt should be embedded because while the subdirectory is named `build.old`,
# it is a directory and not an actual BUILD file.

0 comments on commit a1be474

Please sign in to comment.