Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame^] | 1 | From a3db4da51df37d163ff9e8c1e1057280c648c545 Mon Sep 17 00:00:00 2001 |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 2 | From: Khem Raj <raj.khem@gmail.com> |
| 3 | Date: Mon, 28 Mar 2022 10:59:03 -0700 |
| 4 | Subject: [PATCH] cmd/go: make content-based hash generation less pedantic |
| 5 | |
| 6 | Go 1.10's build tool now uses content-based hashes to |
| 7 | determine when something should be built or re-built. |
| 8 | This same mechanism is used to maintain a built-artifact |
| 9 | cache for speeding up builds. |
| 10 | |
| 11 | However, the hashes it generates include information that |
| 12 | doesn't work well with OE, nor with using a shared runtime |
| 13 | library. |
| 14 | |
| 15 | First, it embeds path names to source files, unless |
| 16 | building within GOROOT. This prevents the building |
| 17 | of a package in GOPATH for later staging into GOROOT. |
| 18 | |
| 19 | This patch adds support for the environment variable |
| 20 | GOPATH_OMIT_IN_ACTIONID. If present, path name |
| 21 | embedding is disabled. |
| 22 | |
| 23 | Upstream-Status: Inappropriate [OE specific] |
| 24 | |
| 25 | Signed-off-by: Alex Kube <alexander.j.kube@gmail.com> |
| 26 | Signed-off-by: Matt Madison <matt@madison.systems> |
| 27 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame^] | 28 | |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 29 | --- |
| 30 | src/cmd/go/internal/envcmd/env.go | 2 +- |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame^] | 31 | src/cmd/go/internal/work/exec.go | 42 ++++++++++++++++++++++++------- |
| 32 | 2 files changed, 34 insertions(+), 10 deletions(-) |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 33 | |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame^] | 34 | diff --git a/src/cmd/go/internal/envcmd/env.go b/src/cmd/go/internal/envcmd/env.go |
| 35 | index 529351d..df791b0 100644 |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 36 | --- a/src/cmd/go/internal/envcmd/env.go |
| 37 | +++ b/src/cmd/go/internal/envcmd/env.go |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame^] | 38 | @@ -176,7 +176,7 @@ func ExtraEnvVars() []cfg.EnvVar { |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 39 | 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 Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame^] | 47 | diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go |
| 48 | index c88b315..a06455c 100644 |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 49 | --- a/src/cmd/go/internal/work/exec.go |
| 50 | +++ b/src/cmd/go/internal/work/exec.go |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame^] | 51 | @@ -213,6 +213,8 @@ func (b *Builder) Do(ctx context.Context, root *Action) { |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 52 | 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 Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame^] | 60 | @@ -234,7 +236,7 @@ func (b *Builder) buildActionID(a *Action) cache.ActionID { |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 61 | 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 Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame^] | 69 | @@ -266,9 +268,9 @@ func (b *Builder) buildActionID(a *Action) cache.ActionID { |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 70 | } |
| 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 Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame^] | 81 | @@ -281,14 +283,14 @@ func (b *Builder) buildActionID(a *Action) cache.ActionID { |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 82 | } |
| 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 Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame^] | 98 | @@ -305,7 +307,7 @@ func (b *Builder) buildActionID(a *Action) cache.ActionID { |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 99 | } |
| 100 | } |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame^] | 101 | 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 Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 105 | |
| 106 | // Configuration specific to compiler toolchain. |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame^] | 107 | @@ -2705,8 +2707,23 @@ func envList(key, def string) []string { |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 108 | 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 Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame^] | 132 | @@ -2724,6 +2741,13 @@ func (b *Builder) CFlags(p *load.Package) (cppflags, cflags, cxxflags, fflags, l |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 133 | 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 Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame^] | 146 | @@ -2739,7 +2763,7 @@ var cgoRe = lazyregexp.New(`[/\\:]`) |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 147 | |
| 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 Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame^] | 155 | @@ -3246,7 +3270,7 @@ func (b *Builder) swigIntSize(objdir string) (intsize string, err error) { |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 156 | |
| 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 | } |