blob: 56487e34e3ae2172faa9c05086c739b17ead2d34 [file] [log] [blame]
Andrew Geissler6aa7eec2023-03-03 12:41:14 -06001From 10766ca6f4007b96e3f6bf4fb496e5df74397eb9 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
Andrew Geissler6aa7eec2023-03-03 12:41:14 -06004Subject: [PATCH 1/9] cmd/go: make content-based hash generation less pedantic
Patrick Williams03907ee2022-05-01 06:28:52 -05005
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>
28---
29 src/cmd/go/internal/envcmd/env.go | 2 +-
Andrew Geissler6aa7eec2023-03-03 12:41:14 -060030 src/cmd/go/internal/work/exec.go | 44 ++++++++++++++++++++++++-------
31 2 files changed, 36 insertions(+), 10 deletions(-)
Patrick Williams03907ee2022-05-01 06:28:52 -050032
Patrick Williams92b42cb2022-09-03 06:53:57 -050033diff --git a/src/cmd/go/internal/envcmd/env.go b/src/cmd/go/internal/envcmd/env.go
Andrew Geissler6aa7eec2023-03-03 12:41:14 -060034index 66ef5ce..fb7448a 100644
Patrick Williams03907ee2022-05-01 06:28:52 -050035--- a/src/cmd/go/internal/envcmd/env.go
36+++ b/src/cmd/go/internal/envcmd/env.go
Andrew Geissler6aa7eec2023-03-03 12:41:14 -060037@@ -183,7 +183,7 @@ func ExtraEnvVarsCostly() []cfg.EnvVar {
38 }
39 }()
Patrick Williams2390b1b2022-11-03 13:47:49 -050040
Patrick Williams03907ee2022-05-01 06:28:52 -050041- cppflags, cflags, cxxflags, fflags, ldflags, err := b.CFlags(&load.Package{})
42+ cppflags, cflags, cxxflags, fflags, ldflags, err := b.CFlags(&load.Package{}, false)
43 if err != nil {
44 // Should not happen - b.CFlags was given an empty package.
45 fmt.Fprintf(os.Stderr, "go: invalid cflags: %v\n", err)
Patrick Williams92b42cb2022-09-03 06:53:57 -050046diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go
Andrew Geissler6aa7eec2023-03-03 12:41:14 -060047index d6fa847..7e4fcb3 100644
Patrick Williams03907ee2022-05-01 06:28:52 -050048--- a/src/cmd/go/internal/work/exec.go
49+++ b/src/cmd/go/internal/work/exec.go
Andrew Geissler6aa7eec2023-03-03 12:41:14 -060050@@ -223,6 +223,8 @@ func (b *Builder) Do(ctx context.Context, root *Action) {
Patrick Williams03907ee2022-05-01 06:28:52 -050051 writeActionGraph()
52 }
53
54+var omitGopath = os.Getenv("GOPATH_OMIT_IN_ACTIONID") != ""
55+
56 // buildActionID computes the action ID for a build action.
57 func (b *Builder) buildActionID(a *Action) cache.ActionID {
58 p := a.Package
Andrew Geissler6aa7eec2023-03-03 12:41:14 -060059@@ -244,7 +246,7 @@ func (b *Builder) buildActionID(a *Action) cache.ActionID {
Patrick Williams03907ee2022-05-01 06:28:52 -050060 if p.Module != nil {
61 fmt.Fprintf(h, "module %s@%s\n", p.Module.Path, p.Module.Version)
62 }
63- } else if p.Goroot {
64+ } else if p.Goroot || omitGopath {
65 // The Go compiler always hides the exact value of $GOROOT
66 // when building things in GOROOT.
67 //
Andrew Geissler6aa7eec2023-03-03 12:41:14 -060068@@ -276,9 +278,9 @@ func (b *Builder) buildActionID(a *Action) cache.ActionID {
Patrick Williams03907ee2022-05-01 06:28:52 -050069 }
70 if len(p.CgoFiles)+len(p.SwigFiles)+len(p.SwigCXXFiles) > 0 {
71 fmt.Fprintf(h, "cgo %q\n", b.toolID("cgo"))
72- cppflags, cflags, cxxflags, fflags, ldflags, _ := b.CFlags(p)
73+ cppflags, cflags, cxxflags, fflags, ldflags, _ := b.CFlags(p, true)
74
75- ccExe := b.ccExe()
Andrew Geissler517393d2023-01-13 08:55:19 -060076+ ccExe := filterCompilerFlags(b.ccExe(), true)
Patrick Williams03907ee2022-05-01 06:28:52 -050077 fmt.Fprintf(h, "CC=%q %q %q %q\n", ccExe, cppflags, cflags, ldflags)
78 // Include the C compiler tool ID so that if the C
79 // compiler changes we rebuild the package.
Andrew Geissler6aa7eec2023-03-03 12:41:14 -060080@@ -286,14 +288,14 @@ func (b *Builder) buildActionID(a *Action) cache.ActionID {
81 fmt.Fprintf(h, "CC ID=%q\n", ccID)
Patrick Williams03907ee2022-05-01 06:28:52 -050082 }
83 if len(p.CXXFiles)+len(p.SwigCXXFiles) > 0 {
84- cxxExe := b.cxxExe()
Andrew Geissler517393d2023-01-13 08:55:19 -060085+ cxxExe := filterCompilerFlags(b.cxxExe(), true)
Patrick Williams03907ee2022-05-01 06:28:52 -050086 fmt.Fprintf(h, "CXX=%q %q\n", cxxExe, cxxflags)
Andrew Geissler6aa7eec2023-03-03 12:41:14 -060087 if cxxID, _, err := b.gccToolID(cxxExe[0], "c++"); err == nil {
Patrick Williams03907ee2022-05-01 06:28:52 -050088 fmt.Fprintf(h, "CXX ID=%q\n", cxxID)
89 }
90 }
91 if len(p.FFiles) > 0 {
92- fcExe := b.fcExe()
Andrew Geissler517393d2023-01-13 08:55:19 -060093+ fcExe := filterCompilerFlags(b.fcExe(), true)
Patrick Williams03907ee2022-05-01 06:28:52 -050094 fmt.Fprintf(h, "FC=%q %q\n", fcExe, fflags)
Andrew Geissler6aa7eec2023-03-03 12:41:14 -060095 if fcID, _, err := b.gccToolID(fcExe[0], "f95"); err == nil {
Patrick Williams03907ee2022-05-01 06:28:52 -050096 fmt.Fprintf(h, "FC ID=%q\n", fcID)
Andrew Geissler6aa7eec2023-03-03 12:41:14 -060097@@ -310,7 +312,7 @@ func (b *Builder) buildActionID(a *Action) cache.ActionID {
Patrick Williams03907ee2022-05-01 06:28:52 -050098 }
99 }
Patrick Williams92b42cb2022-09-03 06:53:57 -0500100 if p.Internal.BuildInfo != "" {
101- fmt.Fprintf(h, "modinfo %q\n", p.Internal.BuildInfo)
102+ //fmt.Fprintf(h, "modinfo %q\n", p.Internal.BuildInfo)
103 }
Patrick Williams03907ee2022-05-01 06:28:52 -0500104
105 // Configuration specific to compiler toolchain.
Andrew Geissler6aa7eec2023-03-03 12:41:14 -0600106@@ -2970,8 +2972,25 @@ func envList(key, def string) []string {
Patrick Williams03907ee2022-05-01 06:28:52 -0500107 return args
108 }
109
110+var filterFlags = os.Getenv("CGO_PEDANTIC") == ""
111+
Andrew Geissler517393d2023-01-13 08:55:19 -0600112+func filterCompilerFlags(flags []string, keepfirst bool) []string {
Patrick Williams03907ee2022-05-01 06:28:52 -0500113+ var newflags []string
Andrew Geissler517393d2023-01-13 08:55:19 -0600114+ var realkeepfirst bool = keepfirst
Patrick Williams03907ee2022-05-01 06:28:52 -0500115+ if !filterFlags {
116+ return flags
117+ }
118+ for _, flag := range flags {
Andrew Geissler517393d2023-01-13 08:55:19 -0600119+ if strings.HasPrefix(flag, "-m") || realkeepfirst {
Patrick Williams03907ee2022-05-01 06:28:52 -0500120+ newflags = append(newflags, flag)
Andrew Geissler517393d2023-01-13 08:55:19 -0600121+ realkeepfirst = false
Patrick Williams03907ee2022-05-01 06:28:52 -0500122+ }
123+ }
124+ return newflags
125+}
126+
127 // CFlags returns the flags to use when invoking the C, C++ or Fortran compilers, or cgo.
128-func (b *Builder) CFlags(p *load.Package) (cppflags, cflags, cxxflags, fflags, ldflags []string, err error) {
129+func (b *Builder) CFlags(p *load.Package, filtered bool) (cppflags, cflags, cxxflags, fflags, ldflags []string, err error) {
Patrick Williams03907ee2022-05-01 06:28:52 -0500130 if cppflags, err = buildFlags("CPPFLAGS", "", p.CgoCPPFLAGS, checkCompilerFlags); err != nil {
Andrew Geissler6aa7eec2023-03-03 12:41:14 -0600131 return
132 }
133@@ -2987,6 +3006,13 @@ func (b *Builder) CFlags(p *load.Package) (cppflags, cflags, cxxflags, fflags, l
134 if ldflags, err = buildFlags("LDFLAGS", defaultCFlags, p.CgoLDFLAGS, checkLinkerFlags); err != nil {
Patrick Williams03907ee2022-05-01 06:28:52 -0500135 return
136 }
137+ if filtered {
Andrew Geissler517393d2023-01-13 08:55:19 -0600138+ cppflags = filterCompilerFlags(cppflags, false)
139+ cflags = filterCompilerFlags(cflags, false)
140+ cxxflags = filterCompilerFlags(cxxflags, false)
141+ fflags = filterCompilerFlags(fflags, false)
142+ ldflags = filterCompilerFlags(ldflags, false)
Patrick Williams03907ee2022-05-01 06:28:52 -0500143+ }
144
145 return
146 }
Andrew Geissler6aa7eec2023-03-03 12:41:14 -0600147@@ -3002,7 +3028,7 @@ var cgoRe = lazyregexp.New(`[/\\:]`)
Patrick Williams03907ee2022-05-01 06:28:52 -0500148
149 func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgofiles, gccfiles, gxxfiles, mfiles, ffiles []string) (outGo, outObj []string, err error) {
150 p := a.Package
151- cgoCPPFLAGS, cgoCFLAGS, cgoCXXFLAGS, cgoFFLAGS, cgoLDFLAGS, err := b.CFlags(p)
152+ cgoCPPFLAGS, cgoCFLAGS, cgoCXXFLAGS, cgoFFLAGS, cgoLDFLAGS, err := b.CFlags(p, false)
153 if err != nil {
154 return nil, nil, err
155 }
Andrew Geissler6aa7eec2023-03-03 12:41:14 -0600156@@ -3510,7 +3536,7 @@ func (b *Builder) swigIntSize(objdir string) (intsize string, err error) {
Patrick Williams03907ee2022-05-01 06:28:52 -0500157
158 // Run SWIG on one SWIG input file.
159 func (b *Builder) swigOne(a *Action, p *load.Package, file, objdir string, pcCFLAGS []string, cxx bool, intgosize string) (outGo, outC string, err error) {
160- cgoCPPFLAGS, cgoCFLAGS, cgoCXXFLAGS, _, _, err := b.CFlags(p)
161+ cgoCPPFLAGS, cgoCFLAGS, cgoCXXFLAGS, _, _, err := b.CFlags(p, false)
162 if err != nil {
163 return "", "", err
164 }
Andrew Geissler6aa7eec2023-03-03 12:41:14 -0600165--
1662.30.2
167