From 8bf8a942b2ae4b511bff4f9b6877fd20394a3107 Mon Sep 17 00:00:00 2001 From: Jon Poole Date: Mon, 9 Oct 2023 15:07:15 +0100 Subject: [PATCH 1/3] Don't set _module on go_binary rules in go_repo --- tools/please_go/generate/rules.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/please_go/generate/rules.go b/tools/please_go/generate/rules.go index 802af054..86f65cc6 100644 --- a/tools/please_go/generate/rules.go +++ b/tools/please_go/generate/rules.go @@ -55,5 +55,7 @@ func populateRule(r *build.Rule, targetState *Rule) { }, }) } - r.SetAttr("_module", NewStringExpr(targetState.module)) + if r.Kind() == "go_library" { + r.SetAttr("_module", NewStringExpr(targetState.module)) + } } From 925266da46efa39fff5472cae76c2fdb77a9086e Mon Sep 17 00:00:00 2001 From: Jon Poole Date: Mon, 9 Oct 2023 15:07:48 +0100 Subject: [PATCH 2/3] Version bump --- tools/please_go/ChangeLog | 4 ++++ tools/please_go/VERSION | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/please_go/ChangeLog b/tools/please_go/ChangeLog index 8de52759..75834162 100644 --- a/tools/please_go/ChangeLog +++ b/tools/please_go/ChangeLog @@ -1,3 +1,7 @@ +Version 1.4.4 +------------- + * Don't set `_module` on go_binary commands in `go_repo` + Version 1.4.3 ------------- * Don't try and pipe test output as it doesn't flush when the TestMain calls os.Exit diff --git a/tools/please_go/VERSION b/tools/please_go/VERSION index 3c80e4f0..e1df5de7 100644 --- a/tools/please_go/VERSION +++ b/tools/please_go/VERSION @@ -1 +1 @@ -1.4.3 \ No newline at end of file +1.4.4 \ No newline at end of file From 109c7fe66338003943eb28a5d9191f0955d924c1 Mon Sep 17 00:00:00 2001 From: Jon Poole Date: Mon, 9 Oct 2023 15:10:34 +0100 Subject: [PATCH 3/3] Refactor --- tools/please_go/generate/generate.go | 5 +++-- tools/please_go/generate/rules.go | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/please_go/generate/generate.go b/tools/please_go/generate/generate.go index d0c68eff..5ee42c5a 100644 --- a/tools/please_go/generate/generate.go +++ b/tools/please_go/generate/generate.go @@ -203,7 +203,7 @@ func (g *Generate) generate(dir string) error { return err } - lib := g.libRule(pkg, dir) + lib := g.ruleForPackage(pkg, dir) if lib == nil { return nil } @@ -336,7 +336,7 @@ func (g *Generate) depTargets(imports []string) []string { return deps } -func (g *Generate) libRule(pkg *build.Package, dir string) *Rule { +func (g *Generate) ruleForPackage(pkg *build.Package, dir string) *Rule { if len(pkg.GoFiles) == 0 && len(pkg.CgoFiles) == 0 { return nil } @@ -356,6 +356,7 @@ func (g *Generate) libRule(pkg *build.Package, dir string) *Rule { hdrs: pkg.HFiles, deps: g.depTargets(pkg.Imports), embedPatterns: pkg.EmbedPatterns, + isCMD: pkg.IsCommand(), } } diff --git a/tools/please_go/generate/rules.go b/tools/please_go/generate/rules.go index 86f65cc6..80d089c6 100644 --- a/tools/please_go/generate/rules.go +++ b/tools/please_go/generate/rules.go @@ -16,7 +16,7 @@ type Rule struct { deps []string embedPatterns []string // TODO(jpoole): handle external test - external bool + external, isCMD bool } func populateRule(r *build.Rule, targetState *Rule) { @@ -55,7 +55,7 @@ func populateRule(r *build.Rule, targetState *Rule) { }, }) } - if r.Kind() == "go_library" { + if !targetState.isCMD { r.SetAttr("_module", NewStringExpr(targetState.module)) } }