blob: 8cbed930174ba6dabcf423b98e06b173f7d4d9dc [file] [log] [blame]
Patrick Williams92b42cb2022-09-03 06:53:57 -05001From a3db4da51df37d163ff9e8c1e1057280c648c545 Mon Sep 17 00:00:00 2001
Patrick Williams03907ee2022-05-01 06:28:52 -05002From: Khem Raj <raj.khem@gmail.com>
3Date: Mon, 28 Mar 2022 10:59:03 -0700
4Subject: [PATCH] cmd/go: make content-based hash generation less pedantic
5
6Go 1.10's build tool now uses content-based hashes to
7determine when something should be built or re-built.
8This same mechanism is used to maintain a built-artifact
9cache for speeding up builds.
10
11However, the hashes it generates include information that
12doesn't work well with OE, nor with using a shared runtime
13library.
14
15First, it embeds path names to source files, unless
16building within GOROOT. This prevents the building
17of a package in GOPATH for later staging into GOROOT.
18
19This patch adds support for the environment variable
20GOPATH_OMIT_IN_ACTIONID. If present, path name
21embedding is disabled.
22
23Upstream-Status: Inappropriate [OE specific]
24
25Signed-off-by: Alex Kube <alexander.j.kube@gmail.com>
26Signed-off-by: Matt Madison <matt@madison.systems>
27Signed-off-by: Khem Raj <raj.khem@gmail.com>
Patrick Williams92b42cb2022-09-03 06:53:57 -050028
Patrick Williams03907ee2022-05-01 06:28:52 -050029---
30 src/cmd/go/internal/envcmd/env.go | 2 +-
Patrick Williams92b42cb2022-09-03 06:53:57 -050031 src/cmd/go/internal/work/exec.go | 42 ++++++++++++++++++++++++-------
32 2 files changed, 34 insertions(+), 10 deletions(-)
Patrick Williams03907ee2022-05-01 06:28:52 -050033
Patrick Williams92b42cb2022-09-03 06:53:57 -050034diff --git a/src/cmd/go/internal/envcmd/env.go b/src/cmd/go/internal/envcmd/env.go
35index 529351d..df791b0 100644
Patrick Williams03907ee2022-05-01 06:28:52 -050036--- a/src/cmd/go/internal/envcmd/env.go
37+++ b/src/cmd/go/internal/envcmd/env.go
Patrick Williams92b42cb2022-09-03 06:53:57 -050038@@ -176,7 +176,7 @@ func ExtraEnvVars() []cfg.EnvVar {
Patrick Williams03907ee2022-05-01 06:28:52 -050039 func ExtraEnvVarsCostly() []cfg.EnvVar {
40 var b work.Builder
41 b.Init()
42- cppflags, cflags, cxxflags, fflags, ldflags, err := b.CFlags(&load.Package{})
43+ cppflags, cflags, cxxflags, fflags, ldflags, err := b.CFlags(&load.Package{}, false)
44 if err != nil {
45 // Should not happen - b.CFlags was given an empty package.
46 fmt.Fprintf(os.Stderr, "go: invalid cflags: %v\n", err)
Patrick Williams92b42cb2022-09-03 06:53:57 -050047diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go
48index c88b315..a06455c 100644
Patrick Williams03907ee2022-05-01 06:28:52 -050049--- a/src/cmd/go/internal/work/exec.go
50+++ b/src/cmd/go/internal/work/exec.go
Patrick Williams92b42cb2022-09-03 06:53:57 -050051@@ -213,6 +213,8 @@ func (b *Builder) Do(ctx context.Context, root *Action) {
Patrick Williams03907ee2022-05-01 06:28:52 -050052 writeActionGraph()
53 }
54
55+var omitGopath = os.Getenv("GOPATH_OMIT_IN_ACTIONID") != ""
56+
57 // buildActionID computes the action ID for a build action.
58 func (b *Builder) buildActionID(a *Action) cache.ActionID {
59 p := a.Package
Patrick Williams92b42cb2022-09-03 06:53:57 -050060@@ -234,7 +236,7 @@ func (b *Builder) buildActionID(a *Action) cache.ActionID {
Patrick Williams03907ee2022-05-01 06:28:52 -050061 if p.Module != nil {
62 fmt.Fprintf(h, "module %s@%s\n", p.Module.Path, p.Module.Version)
63 }
64- } else if p.Goroot {
65+ } else if p.Goroot || omitGopath {
66 // The Go compiler always hides the exact value of $GOROOT
67 // when building things in GOROOT.
68 //
Patrick Williams92b42cb2022-09-03 06:53:57 -050069@@ -266,9 +268,9 @@ func (b *Builder) buildActionID(a *Action) cache.ActionID {
Patrick Williams03907ee2022-05-01 06:28:52 -050070 }
71 if len(p.CgoFiles)+len(p.SwigFiles)+len(p.SwigCXXFiles) > 0 {
72 fmt.Fprintf(h, "cgo %q\n", b.toolID("cgo"))
73- cppflags, cflags, cxxflags, fflags, ldflags, _ := b.CFlags(p)
74+ cppflags, cflags, cxxflags, fflags, ldflags, _ := b.CFlags(p, true)
75
76- ccExe := b.ccExe()
77+ ccExe := filterCompilerFlags(b.ccExe())
78 fmt.Fprintf(h, "CC=%q %q %q %q\n", ccExe, cppflags, cflags, ldflags)
79 // Include the C compiler tool ID so that if the C
80 // compiler changes we rebuild the package.
Patrick Williams92b42cb2022-09-03 06:53:57 -050081@@ -281,14 +283,14 @@ func (b *Builder) buildActionID(a *Action) cache.ActionID {
Patrick Williams03907ee2022-05-01 06:28:52 -050082 }
83 }
84 if len(p.CXXFiles)+len(p.SwigCXXFiles) > 0 {
85- cxxExe := b.cxxExe()
86+ cxxExe := filterCompilerFlags(b.cxxExe())
87 fmt.Fprintf(h, "CXX=%q %q\n", cxxExe, cxxflags)
88 if cxxID, err := b.gccToolID(cxxExe[0], "c++"); err == nil {
89 fmt.Fprintf(h, "CXX ID=%q\n", cxxID)
90 }
91 }
92 if len(p.FFiles) > 0 {
93- fcExe := b.fcExe()
94+ fcExe := filterCompilerFlags(b.fcExe())
95 fmt.Fprintf(h, "FC=%q %q\n", fcExe, fflags)
96 if fcID, err := b.gccToolID(fcExe[0], "f95"); err == nil {
97 fmt.Fprintf(h, "FC ID=%q\n", fcID)
Patrick Williams92b42cb2022-09-03 06:53:57 -050098@@ -305,7 +307,7 @@ func (b *Builder) buildActionID(a *Action) cache.ActionID {
Patrick Williams03907ee2022-05-01 06:28:52 -050099 }
100 }
Patrick Williams92b42cb2022-09-03 06:53:57 -0500101 if p.Internal.BuildInfo != "" {
102- fmt.Fprintf(h, "modinfo %q\n", p.Internal.BuildInfo)
103+ //fmt.Fprintf(h, "modinfo %q\n", p.Internal.BuildInfo)
104 }
Patrick Williams03907ee2022-05-01 06:28:52 -0500105
106 // Configuration specific to compiler toolchain.
Patrick Williams92b42cb2022-09-03 06:53:57 -0500107@@ -2705,8 +2707,23 @@ func envList(key, def string) []string {
Patrick Williams03907ee2022-05-01 06:28:52 -0500108 return args
109 }
110
111+var filterFlags = os.Getenv("CGO_PEDANTIC") == ""
112+
113+func filterCompilerFlags(flags []string) []string {
114+ var newflags []string
115+ if !filterFlags {
116+ return flags
117+ }
118+ for _, flag := range flags {
119+ if strings.HasPrefix(flag, "-m") {
120+ newflags = append(newflags, flag)
121+ }
122+ }
123+ return newflags
124+}
125+
126 // CFlags returns the flags to use when invoking the C, C++ or Fortran compilers, or cgo.
127-func (b *Builder) CFlags(p *load.Package) (cppflags, cflags, cxxflags, fflags, ldflags []string, err error) {
128+func (b *Builder) CFlags(p *load.Package, filtered bool) (cppflags, cflags, cxxflags, fflags, ldflags []string, err error) {
129 defaults := "-g -O2"
130
131 if cppflags, err = buildFlags("CPPFLAGS", "", p.CgoCPPFLAGS, checkCompilerFlags); err != nil {
Patrick Williams92b42cb2022-09-03 06:53:57 -0500132@@ -2724,6 +2741,13 @@ func (b *Builder) CFlags(p *load.Package) (cppflags, cflags, cxxflags, fflags, l
Patrick Williams03907ee2022-05-01 06:28:52 -0500133 if ldflags, err = buildFlags("LDFLAGS", defaults, p.CgoLDFLAGS, checkLinkerFlags); err != nil {
134 return
135 }
136+ if filtered {
137+ cppflags = filterCompilerFlags(cppflags)
138+ cflags = filterCompilerFlags(cflags)
139+ cxxflags = filterCompilerFlags(cxxflags)
140+ fflags = filterCompilerFlags(fflags)
141+ ldflags = filterCompilerFlags(ldflags)
142+ }
143
144 return
145 }
Patrick Williams92b42cb2022-09-03 06:53:57 -0500146@@ -2739,7 +2763,7 @@ var cgoRe = lazyregexp.New(`[/\\:]`)
Patrick Williams03907ee2022-05-01 06:28:52 -0500147
148 func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgofiles, gccfiles, gxxfiles, mfiles, ffiles []string) (outGo, outObj []string, err error) {
149 p := a.Package
150- cgoCPPFLAGS, cgoCFLAGS, cgoCXXFLAGS, cgoFFLAGS, cgoLDFLAGS, err := b.CFlags(p)
151+ cgoCPPFLAGS, cgoCFLAGS, cgoCXXFLAGS, cgoFFLAGS, cgoLDFLAGS, err := b.CFlags(p, false)
152 if err != nil {
153 return nil, nil, err
154 }
Patrick Williams92b42cb2022-09-03 06:53:57 -0500155@@ -3246,7 +3270,7 @@ func (b *Builder) swigIntSize(objdir string) (intsize string, err error) {
Patrick Williams03907ee2022-05-01 06:28:52 -0500156
157 // Run SWIG on one SWIG input file.
158 func (b *Builder) swigOne(a *Action, p *load.Package, file, objdir string, pcCFLAGS []string, cxx bool, intgosize string) (outGo, outC string, err error) {
159- cgoCPPFLAGS, cgoCFLAGS, cgoCXXFLAGS, _, _, err := b.CFlags(p)
160+ cgoCPPFLAGS, cgoCFLAGS, cgoCXXFLAGS, _, _, err := b.CFlags(p, false)
161 if err != nil {
162 return "", "", err
163 }