Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix embed on windows #1361

Merged
merged 2 commits into from
Dec 31, 2022
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions language/go/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ go_test(
"//walk",
"@com_github_bazelbuild_buildtools//build:go_default_library",
"@com_github_google_go_cmp//cmp",
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
"@org_golang_x_tools//go/vcs",
],
)
Expand Down
1 change: 1 addition & 0 deletions language/go/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func newEmbedResolver(dir, rel string, validBuildFileNames []string, pkgRels map
return err
}
fileRel, _ := filepath.Rel(dir, p)
fileRel = filepath.ToSlash(fileRel)
base := filepath.Base(p)
if !info.IsDir() {
if !isBadEmbedName(base) {
Expand Down
33 changes: 27 additions & 6 deletions language/go/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package golang
import (
"io/ioutil"
"os"
"path"
"path/filepath"
"runtime"
"strings"
Expand All @@ -30,30 +31,50 @@ import (
"github.com/bazelbuild/bazel-gazelle/rule"
"github.com/bazelbuild/bazel-gazelle/walk"
bzl "github.com/bazelbuild/buildtools/build"
"github.com/bazelbuild/rules_go/go/tools/bazel"
"github.com/google/go-cmp/cmp"
)

func TestGenerateRules(t *testing.T) {
testdataDir := "testdata"
if runtime.GOOS == "windows" {
// TODO(jayconrod): set up testdata directory on windows before running test
if _, err := os.Stat("testdata"); os.IsNotExist(err) {
t.Skip("testdata missing on windows due to lack of symbolic links")
} else if err != nil {
var err error
testdataDir, err = bazel.NewTmpDir("testdata")
if err != nil {
t.Fatal(err)
}
files, _ := bazel.ListRunfiles()
parent := "language/go/testdata"
for _, rf := range files {
rel, err := filepath.Rel(parent, rf.ShortPath)
if err != nil {
continue
}
if strings.HasPrefix(rel, "..") {
// make sure we're not moving around file that we're not inrerested in
continue
}
newPath := filepath.FromSlash(path.Join(testdataDir, rel))
if err := os.MkdirAll(filepath.FromSlash(filepath.Dir(newPath)), os.ModePerm); err != nil {
t.Fatal(err)
}
if err := os.Link(filepath.FromSlash(rf.Path), newPath); err != nil {
t.Fatal(err)
}
}
}

c, langs, cexts := testConfig(
t,
"-build_file_name=BUILD.old",
"-go_prefix=example.com/repo",
"-repo_root=testdata")
"-repo_root="+testdataDir)

var loads []rule.LoadInfo
for _, lang := range langs {
loads = append(loads, lang.Loads()...)
}
walk.Walk(c, cexts, []string{"testdata"}, walk.VisitAllUpdateSubdirsMode, func(dir, rel string, c *config.Config, update bool, oldFile *rule.File, subdirs, regularFiles, genFiles []string) {
walk.Walk(c, cexts, []string{testdataDir}, walk.VisitAllUpdateSubdirsMode, func(dir, rel string, c *config.Config, update bool, oldFile *rule.File, subdirs, regularFiles, genFiles []string) {
t.Run(rel, func(t *testing.T) {
var empty, gen []*rule.Rule
for _, lang := range langs {
Expand Down