Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame^] | 1 | From 61de6067f5ad127d246543527947a357647f95e5 Mon Sep 17 00:00:00 2001 |
| 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> |
| 28 | --- |
| 29 | src/cmd/go/internal/envcmd/env.go | 2 +- |
| 30 | src/cmd/go/internal/work/exec.go | 42 +++++++++++++++++++++++++------ |
| 31 | 2 files changed, 35 insertions(+), 9 deletions(-) |
| 32 | |
| 33 | --- a/src/cmd/go/internal/envcmd/env.go |
| 34 | +++ b/src/cmd/go/internal/envcmd/env.go |
| 35 | @@ -169,7 +169,7 @@ func ExtraEnvVars() []cfg.EnvVar { |
| 36 | func ExtraEnvVarsCostly() []cfg.EnvVar { |
| 37 | var b work.Builder |
| 38 | b.Init() |
| 39 | - cppflags, cflags, cxxflags, fflags, ldflags, err := b.CFlags(&load.Package{}) |
| 40 | + cppflags, cflags, cxxflags, fflags, ldflags, err := b.CFlags(&load.Package{}, false) |
| 41 | if err != nil { |
| 42 | // Should not happen - b.CFlags was given an empty package. |
| 43 | fmt.Fprintf(os.Stderr, "go: invalid cflags: %v\n", err) |
| 44 | --- a/src/cmd/go/internal/work/exec.go |
| 45 | +++ b/src/cmd/go/internal/work/exec.go |
| 46 | @@ -213,6 +213,8 @@ func (b *Builder) Do(ctx context.Context |
| 47 | writeActionGraph() |
| 48 | } |
| 49 | |
| 50 | +var omitGopath = os.Getenv("GOPATH_OMIT_IN_ACTIONID") != "" |
| 51 | + |
| 52 | // buildActionID computes the action ID for a build action. |
| 53 | func (b *Builder) buildActionID(a *Action) cache.ActionID { |
| 54 | p := a.Package |
| 55 | @@ -234,7 +236,7 @@ func (b *Builder) buildActionID(a *Actio |
| 56 | if p.Module != nil { |
| 57 | fmt.Fprintf(h, "module %s@%s\n", p.Module.Path, p.Module.Version) |
| 58 | } |
| 59 | - } else if p.Goroot { |
| 60 | + } else if p.Goroot || omitGopath { |
| 61 | // The Go compiler always hides the exact value of $GOROOT |
| 62 | // when building things in GOROOT. |
| 63 | // |
| 64 | @@ -266,9 +268,9 @@ func (b *Builder) buildActionID(a *Actio |
| 65 | } |
| 66 | if len(p.CgoFiles)+len(p.SwigFiles)+len(p.SwigCXXFiles) > 0 { |
| 67 | fmt.Fprintf(h, "cgo %q\n", b.toolID("cgo")) |
| 68 | - cppflags, cflags, cxxflags, fflags, ldflags, _ := b.CFlags(p) |
| 69 | + cppflags, cflags, cxxflags, fflags, ldflags, _ := b.CFlags(p, true) |
| 70 | |
| 71 | - ccExe := b.ccExe() |
| 72 | + ccExe := filterCompilerFlags(b.ccExe()) |
| 73 | fmt.Fprintf(h, "CC=%q %q %q %q\n", ccExe, cppflags, cflags, ldflags) |
| 74 | // Include the C compiler tool ID so that if the C |
| 75 | // compiler changes we rebuild the package. |
| 76 | @@ -281,14 +283,14 @@ func (b *Builder) buildActionID(a *Actio |
| 77 | } |
| 78 | } |
| 79 | if len(p.CXXFiles)+len(p.SwigCXXFiles) > 0 { |
| 80 | - cxxExe := b.cxxExe() |
| 81 | + cxxExe := filterCompilerFlags(b.cxxExe()) |
| 82 | fmt.Fprintf(h, "CXX=%q %q\n", cxxExe, cxxflags) |
| 83 | if cxxID, err := b.gccToolID(cxxExe[0], "c++"); err == nil { |
| 84 | fmt.Fprintf(h, "CXX ID=%q\n", cxxID) |
| 85 | } |
| 86 | } |
| 87 | if len(p.FFiles) > 0 { |
| 88 | - fcExe := b.fcExe() |
| 89 | + fcExe := filterCompilerFlags(b.fcExe()) |
| 90 | fmt.Fprintf(h, "FC=%q %q\n", fcExe, fflags) |
| 91 | if fcID, err := b.gccToolID(fcExe[0], "f95"); err == nil { |
| 92 | fmt.Fprintf(h, "FC ID=%q\n", fcID) |
| 93 | @@ -304,7 +306,7 @@ func (b *Builder) buildActionID(a *Actio |
| 94 | fmt.Fprintf(h, "fuzz %q\n", fuzzFlags) |
| 95 | } |
| 96 | } |
| 97 | - fmt.Fprintf(h, "modinfo %q\n", p.Internal.BuildInfo) |
| 98 | + //fmt.Fprintf(h, "modinfo %q\n", p.Internal.BuildInfo) |
| 99 | |
| 100 | // Configuration specific to compiler toolchain. |
| 101 | switch cfg.BuildToolchainName { |
| 102 | @@ -2679,8 +2681,23 @@ func envList(key, def string) []string { |
| 103 | return args |
| 104 | } |
| 105 | |
| 106 | +var filterFlags = os.Getenv("CGO_PEDANTIC") == "" |
| 107 | + |
| 108 | +func filterCompilerFlags(flags []string) []string { |
| 109 | + var newflags []string |
| 110 | + if !filterFlags { |
| 111 | + return flags |
| 112 | + } |
| 113 | + for _, flag := range flags { |
| 114 | + if strings.HasPrefix(flag, "-m") { |
| 115 | + newflags = append(newflags, flag) |
| 116 | + } |
| 117 | + } |
| 118 | + return newflags |
| 119 | +} |
| 120 | + |
| 121 | // CFlags returns the flags to use when invoking the C, C++ or Fortran compilers, or cgo. |
| 122 | -func (b *Builder) CFlags(p *load.Package) (cppflags, cflags, cxxflags, fflags, ldflags []string, err error) { |
| 123 | +func (b *Builder) CFlags(p *load.Package, filtered bool) (cppflags, cflags, cxxflags, fflags, ldflags []string, err error) { |
| 124 | defaults := "-g -O2" |
| 125 | |
| 126 | if cppflags, err = buildFlags("CPPFLAGS", "", p.CgoCPPFLAGS, checkCompilerFlags); err != nil { |
| 127 | @@ -2698,6 +2715,13 @@ func (b *Builder) CFlags(p *load.Package |
| 128 | if ldflags, err = buildFlags("LDFLAGS", defaults, p.CgoLDFLAGS, checkLinkerFlags); err != nil { |
| 129 | return |
| 130 | } |
| 131 | + if filtered { |
| 132 | + cppflags = filterCompilerFlags(cppflags) |
| 133 | + cflags = filterCompilerFlags(cflags) |
| 134 | + cxxflags = filterCompilerFlags(cxxflags) |
| 135 | + fflags = filterCompilerFlags(fflags) |
| 136 | + ldflags = filterCompilerFlags(ldflags) |
| 137 | + } |
| 138 | |
| 139 | return |
| 140 | } |
| 141 | @@ -2713,7 +2737,7 @@ var cgoRe = lazyregexp.New(`[/\\:]`) |
| 142 | |
| 143 | func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgofiles, gccfiles, gxxfiles, mfiles, ffiles []string) (outGo, outObj []string, err error) { |
| 144 | p := a.Package |
| 145 | - cgoCPPFLAGS, cgoCFLAGS, cgoCXXFLAGS, cgoFFLAGS, cgoLDFLAGS, err := b.CFlags(p) |
| 146 | + cgoCPPFLAGS, cgoCFLAGS, cgoCXXFLAGS, cgoFFLAGS, cgoLDFLAGS, err := b.CFlags(p, false) |
| 147 | if err != nil { |
| 148 | return nil, nil, err |
| 149 | } |
| 150 | @@ -3174,7 +3198,7 @@ func (b *Builder) swigIntSize(objdir str |
| 151 | |
| 152 | // Run SWIG on one SWIG input file. |
| 153 | func (b *Builder) swigOne(a *Action, p *load.Package, file, objdir string, pcCFLAGS []string, cxx bool, intgosize string) (outGo, outC string, err error) { |
| 154 | - cgoCPPFLAGS, cgoCFLAGS, cgoCXXFLAGS, _, _, err := b.CFlags(p) |
| 155 | + cgoCPPFLAGS, cgoCFLAGS, cgoCXXFLAGS, _, _, err := b.CFlags(p, false) |
| 156 | if err != nil { |
| 157 | return "", "", err |
| 158 | } |