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: dont fail if there is a .go directory #1899

Merged
merged 1 commit into from Nov 13, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion internal/builders/golang/build.go
Expand Up @@ -227,7 +227,7 @@ func checkMain(build config.Build) error {
return ferr
}
if stat.IsDir() {
packs, err := parser.ParseDir(token.NewFileSet(), main, nil, 0)
packs, err := parser.ParseDir(token.NewFileSet(), main, fileFilter, 0)
if err != nil {
return fmt.Errorf("failed to parse dir: %s: %w", main, err)
}
Expand All @@ -250,6 +250,10 @@ func checkMain(build config.Build) error {
return fmt.Errorf("build for %s does not contain a main function", build.Binary)
}

func fileFilter(info os.FileInfo) bool {
return !info.IsDir()
}

func hasMain(file *ast.File) bool {
for _, decl := range file.Decls {
fn, isFn := decl.(*ast.FuncDecl)
Expand Down
27 changes: 27 additions & 0 deletions internal/builders/golang/build_test.go
Expand Up @@ -342,6 +342,33 @@ func TestBuildCodeInSubdir(t *testing.T) {
require.NoError(t, err)
}

func TestBuildWithDotGoDir(t *testing.T) {
folder, back := testlib.Mktmp(t)
defer back()
require.NoError(t, os.Mkdir(filepath.Join(folder, ".go"), 0755))
writeGoodMain(t, folder)
var config = config.Project{
Builds: []config.Build{
{
ID: "foo",
Env: []string{"GO111MODULE=off"},
Binary: "foo",
Targets: []string{runtimeTarget},
GoBinary: "go",
},
},
}
var ctx = context.New(config)
ctx.Git.CurrentTag = "5.6.7"
var build = ctx.Config.Builds[0]
require.NoError(t, Default.Build(ctx, build, api.Options{
Target: runtimeTarget,
Name: build.Binary,
Path: filepath.Join(folder, "dist", runtimeTarget, build.Binary),
Ext: "",
}))
}

func TestBuildFailed(t *testing.T) {
folder, back := testlib.Mktmp(t)
defer back()
Expand Down