summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/go/go/0001-cmd-go-make-content-based-hash-generation-less-pedan.patch
blob: f9db5df4eb9621a4913798a8078d32e91166831e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
From 61de6067f5ad127d246543527947a357647f95e5 Mon Sep 17 00:00:00 2001
From: Khem Raj <raj.khem@gmail.com>
Date: Mon, 28 Mar 2022 10:59:03 -0700
Subject: [PATCH] cmd/go: make content-based hash generation less pedantic

Go 1.10's build tool now uses content-based hashes to
determine when something should be built or re-built.
This same mechanism is used to maintain a built-artifact
cache for speeding up builds.

However, the hashes it generates include information that
doesn't work well with OE, nor with using a shared runtime
library.

First, it embeds path names to source files, unless
building within GOROOT.  This prevents the building
of a package in GOPATH for later staging into GOROOT.

This patch adds support for the environment variable
GOPATH_OMIT_IN_ACTIONID.  If present, path name
embedding is disabled.

Upstream-Status: Inappropriate [OE specific]

Signed-off-by: Alex Kube <alexander.j.kube@gmail.com>
Signed-off-by: Matt Madison <matt@madison.systems>
Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 src/cmd/go/internal/envcmd/env.go |  2 +-
 src/cmd/go/internal/work/exec.go  | 42 +++++++++++++++++++++++++------
 2 files changed, 35 insertions(+), 9 deletions(-)

--- a/src/cmd/go/internal/envcmd/env.go
+++ b/src/cmd/go/internal/envcmd/env.go
@@ -169,7 +169,7 @@ func ExtraEnvVars() []cfg.EnvVar {
 func ExtraEnvVarsCostly() []cfg.EnvVar {
 	var b work.Builder
 	b.Init()
-	cppflags, cflags, cxxflags, fflags, ldflags, err := b.CFlags(&load.Package{})
+	cppflags, cflags, cxxflags, fflags, ldflags, err := b.CFlags(&load.Package{}, false)
 	if err != nil {
 		// Should not happen - b.CFlags was given an empty package.
 		fmt.Fprintf(os.Stderr, "go: invalid cflags: %v\n", err)
--- a/src/cmd/go/internal/work/exec.go
+++ b/src/cmd/go/internal/work/exec.go
@@ -213,6 +213,8 @@ func (b *Builder) Do(ctx context.Context
 	writeActionGraph()
 }
 
+var omitGopath = os.Getenv("GOPATH_OMIT_IN_ACTIONID") != ""
+
 // buildActionID computes the action ID for a build action.
 func (b *Builder) buildActionID(a *Action) cache.ActionID {
 	p := a.Package
@@ -234,7 +236,7 @@ func (b *Builder) buildActionID(a *Actio
 		if p.Module != nil {
 			fmt.Fprintf(h, "module %s@%s\n", p.Module.Path, p.Module.Version)
 		}
-	} else if p.Goroot {
+	} else if p.Goroot || omitGopath {
 		// The Go compiler always hides the exact value of $GOROOT
 		// when building things in GOROOT.
 		//
@@ -266,9 +268,9 @@ func (b *Builder) buildActionID(a *Actio
 	}
 	if len(p.CgoFiles)+len(p.SwigFiles)+len(p.SwigCXXFiles) > 0 {
 		fmt.Fprintf(h, "cgo %q\n", b.toolID("cgo"))
-		cppflags, cflags, cxxflags, fflags, ldflags, _ := b.CFlags(p)
+		cppflags, cflags, cxxflags, fflags, ldflags, _ := b.CFlags(p, true)
 
-		ccExe := b.ccExe()
+		ccExe := filterCompilerFlags(b.ccExe())
 		fmt.Fprintf(h, "CC=%q %q %q %q\n", ccExe, cppflags, cflags, ldflags)
 		// Include the C compiler tool ID so that if the C
 		// compiler changes we rebuild the package.
@@ -281,14 +283,14 @@ func (b *Builder) buildActionID(a *Actio
 			}
 		}
 		if len(p.CXXFiles)+len(p.SwigCXXFiles) > 0 {
-			cxxExe := b.cxxExe()
+			cxxExe := filterCompilerFlags(b.cxxExe())
 			fmt.Fprintf(h, "CXX=%q %q\n", cxxExe, cxxflags)
 			if cxxID, err := b.gccToolID(cxxExe[0], "c++"); err == nil {
 				fmt.Fprintf(h, "CXX ID=%q\n", cxxID)
 			}
 		}
 		if len(p.FFiles) > 0 {
-			fcExe := b.fcExe()
+			fcExe := filterCompilerFlags(b.fcExe())
 			fmt.Fprintf(h, "FC=%q %q\n", fcExe, fflags)
 			if fcID, err := b.gccToolID(fcExe[0], "f95"); err == nil {
 				fmt.Fprintf(h, "FC ID=%q\n", fcID)
@@ -304,7 +306,7 @@ func (b *Builder) buildActionID(a *Actio
 			fmt.Fprintf(h, "fuzz %q\n", fuzzFlags)
 		}
 	}
-	fmt.Fprintf(h, "modinfo %q\n", p.Internal.BuildInfo)
+	//fmt.Fprintf(h, "modinfo %q\n", p.Internal.BuildInfo)
 
 	// Configuration specific to compiler toolchain.
 	switch cfg.BuildToolchainName {
@@ -2679,8 +2681,23 @@ func envList(key, def string) []string {
 	return args
 }
 
+var filterFlags = os.Getenv("CGO_PEDANTIC") == ""
+
+func filterCompilerFlags(flags []string) []string {
+	var newflags []string
+	if !filterFlags {
+		return flags
+	}
+	for _, flag := range flags {
+		if strings.HasPrefix(flag, "-m") {
+			newflags = append(newflags, flag)
+		}
+	}
+	return newflags
+}
+
 // CFlags returns the flags to use when invoking the C, C++ or Fortran compilers, or cgo.
-func (b *Builder) CFlags(p *load.Package) (cppflags, cflags, cxxflags, fflags, ldflags []string, err error) {
+func (b *Builder) CFlags(p *load.Package, filtered bool) (cppflags, cflags, cxxflags, fflags, ldflags []string, err error) {
 	defaults := "-g -O2"
 
 	if cppflags, err = buildFlags("CPPFLAGS", "", p.CgoCPPFLAGS, checkCompilerFlags); err != nil {
@@ -2698,6 +2715,13 @@ func (b *Builder) CFlags(p *load.Package
 	if ldflags, err = buildFlags("LDFLAGS", defaults, p.CgoLDFLAGS, checkLinkerFlags); err != nil {
 		return
 	}
+	if filtered {
+		cppflags = filterCompilerFlags(cppflags)
+		cflags = filterCompilerFlags(cflags)
+		cxxflags = filterCompilerFlags(cxxflags)
+		fflags = filterCompilerFlags(fflags)
+		ldflags = filterCompilerFlags(ldflags)
+	}
 
 	return
 }
@@ -2713,7 +2737,7 @@ var cgoRe = lazyregexp.New(`[/\\:]`)
 
 func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgofiles, gccfiles, gxxfiles, mfiles, ffiles []string) (outGo, outObj []string, err error) {
 	p := a.Package
-	cgoCPPFLAGS, cgoCFLAGS, cgoCXXFLAGS, cgoFFLAGS, cgoLDFLAGS, err := b.CFlags(p)
+	cgoCPPFLAGS, cgoCFLAGS, cgoCXXFLAGS, cgoFFLAGS, cgoLDFLAGS, err := b.CFlags(p, false)
 	if err != nil {
 		return nil, nil, err
 	}
@@ -3174,7 +3198,7 @@ func (b *Builder) swigIntSize(objdir str
 
 // Run SWIG on one SWIG input file.
 func (b *Builder) swigOne(a *Action, p *load.Package, file, objdir string, pcCFLAGS []string, cxx bool, intgosize string) (outGo, outC string, err error) {
-	cgoCPPFLAGS, cgoCFLAGS, cgoCXXFLAGS, _, _, err := b.CFlags(p)
+	cgoCPPFLAGS, cgoCFLAGS, cgoCXXFLAGS, _, _, err := b.CFlags(p, false)
 	if err != nil {
 		return "", "", err
 	}