summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/go/go-1.13/0007-cmd-go-make-GOROOT-precious-by-default.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-devtools/go/go-1.13/0007-cmd-go-make-GOROOT-precious-by-default.patch')
-rw-r--r--meta/recipes-devtools/go/go-1.13/0007-cmd-go-make-GOROOT-precious-by-default.patch113
1 files changed, 113 insertions, 0 deletions
diff --git a/meta/recipes-devtools/go/go-1.13/0007-cmd-go-make-GOROOT-precious-by-default.patch b/meta/recipes-devtools/go/go-1.13/0007-cmd-go-make-GOROOT-precious-by-default.patch
new file mode 100644
index 0000000000..e232c79199
--- /dev/null
+++ b/meta/recipes-devtools/go/go-1.13/0007-cmd-go-make-GOROOT-precious-by-default.patch
@@ -0,0 +1,113 @@
1From 9ba507e076c744f4d394418e4a849e68cd426a4a Mon Sep 17 00:00:00 2001
2From: Alex Kube <alexander.j.kube@gmail.com>
3Date: Wed, 23 Oct 2019 21:18:56 +0430
4Subject: [PATCH 7/9] cmd/go: make GOROOT precious by default
5
6Upstream-Status: Inappropriate [OE specific]
7
8The go build tool normally rebuilds whatever it detects is
9stale. This can be a problem when GOROOT is intended to
10be read-only and the go runtime has been built as a shared
11library, since we don't want every application to be rebuilding
12the shared runtime - particularly in cross-build/packaging
13setups, since that would lead to 'abi mismatch' runtime errors.
14
15This patch prevents the install and linkshared actions from
16installing to GOROOT unless overridden with the GOROOT_OVERRIDE
17environment variable.
18
19Adapted to Go 1.13 from patches originally submitted to
20the meta/recipes-devtools/go tree by
21Matt Madison <matt@madison.systems>.
22
23Signed-off-by: Alexander J Kube <alexander.j.kube@gmail.com>
24---
25 src/cmd/go/internal/work/action.go | 3 +++
26 src/cmd/go/internal/work/build.go | 6 ++++++
27 src/cmd/go/internal/work/exec.go | 25 +++++++++++++++++++++++++
28 3 files changed, 34 insertions(+)
29
30diff --git a/src/cmd/go/internal/work/action.go b/src/cmd/go/internal/work/action.go
31index 33b7818..7617b4c 100644
32--- a/src/cmd/go/internal/work/action.go
33+++ b/src/cmd/go/internal/work/action.go
34@@ -662,6 +662,9 @@ func (b *Builder) addTransitiveLinkDeps(a, a1 *Action, shlib string) {
35 if p1 == nil || p1.Shlib == "" || haveShlib[filepath.Base(p1.Shlib)] {
36 continue
37 }
38+ if goRootPrecious && (p1.Standard || p1.Goroot) {
39+ continue
40+ }
41 haveShlib[filepath.Base(p1.Shlib)] = true
42 // TODO(rsc): The use of ModeInstall here is suspect, but if we only do ModeBuild,
43 // we'll end up building an overall library or executable that depends at runtime
44diff --git a/src/cmd/go/internal/work/build.go b/src/cmd/go/internal/work/build.go
45index 9305b2d..6560317 100644
46--- a/src/cmd/go/internal/work/build.go
47+++ b/src/cmd/go/internal/work/build.go
48@@ -155,6 +155,8 @@ See also: go install, go get, go clean.
49
50 const concurrentGCBackendCompilationEnabledByDefault = true
51
52+var goRootPrecious bool = true
53+
54 func init() {
55 // break init cycle
56 CmdBuild.Run = runBuild
57@@ -167,6 +169,10 @@ func init() {
58
59 AddBuildFlags(CmdBuild)
60 AddBuildFlags(CmdInstall)
61+
62+ if x := os.Getenv("GOROOT_OVERRIDE"); x != "" {
63+ goRootPrecious = false
64+ }
65 }
66
67 // Note that flags consulted by other parts of the code
68diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go
69index ccebaf8..59450d7 100644
70--- a/src/cmd/go/internal/work/exec.go
71+++ b/src/cmd/go/internal/work/exec.go
72@@ -455,6 +455,23 @@ func (b *Builder) build(a *Action) (err error) {
73 return errors.New("binary-only packages are no longer supported")
74 }
75
76+ if goRootPrecious && (a.Package.Standard || a.Package.Goroot) {
77+ _, err := os.Stat(a.Package.Target)
78+ if err == nil {
79+ a.built = a.Package.Target
80+ a.Target = a.Package.Target
81+ a.buildID = b.fileHash(a.Package.Target)
82+ a.Package.Stale = false
83+ a.Package.StaleReason = "GOROOT-resident package"
84+ return nil
85+ }
86+ a.Package.Stale = true
87+ a.Package.StaleReason = "missing or invalid GOROOT-resident package"
88+ if b.IsCmdList {
89+ return nil
90+ }
91+ }
92+
93 if err := b.Mkdir(a.Objdir); err != nil {
94 return err
95 }
96@@ -1499,6 +1516,14 @@ func BuildInstallFunc(b *Builder, a *Action) (err error) {
97 return nil
98 }
99
100+ if goRootPrecious && a.Package != nil {
101+ p := a.Package
102+ if p.Standard || p.Goroot {
103+ err := fmt.Errorf("attempting to install package %s into read-only GOROOT", p.ImportPath)
104+ return err
105+ }
106+ }
107+
108 if err := b.Mkdir(a.Objdir); err != nil {
109 return err
110 }
111--
1122.17.1 (Apple Git-112)
113