]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.cc] runtime: generate GOOS- and GOARCH-specific files with go generate
authorRuss Cox <rsc@golang.org>
Tue, 18 Nov 2014 17:07:50 +0000 (12:07 -0500)
committerRuss Cox <rsc@golang.org>
Tue, 18 Nov 2014 17:07:50 +0000 (12:07 -0500)
Eventually I'd like almost everything cmd/dist generates
to be done with 'go generate' and checked in, to simplify
the bootstrap process. The only thing cmd/dist really needs
to do is write things like the current experiment info and
the current version.

This is a first step toward that. It replaces the _NaCl etc
constants with generated ones goos_nacl, goos_darwin,
goarch_386, and so on.

LGTM=dave, austin
R=austin, dave, bradfitz
CC=golang-codereviews, iant, r
https://golang.org/cl/174290043

27 files changed:
src/cmd/dist/build.c
src/cmd/dist/buildruntime.c
src/runtime/arch1_386.go
src/runtime/arch1_amd64.go
src/runtime/arch1_arm.go
src/runtime/gengoos.go [new file with mode: 0644]
src/runtime/malloc2.go
src/runtime/runtime2.go
src/runtime/stack1.go
src/runtime/stack2.go
src/runtime/zgoarch_386.go [new file with mode: 0644]
src/runtime/zgoarch_amd64.go [new file with mode: 0644]
src/runtime/zgoarch_amd64p32.go [new file with mode: 0644]
src/runtime/zgoarch_arm.go [new file with mode: 0644]
src/runtime/zgoarch_power64.go [new file with mode: 0644]
src/runtime/zgoarch_power64le.go [new file with mode: 0644]
src/runtime/zgoos_android.go [new file with mode: 0644]
src/runtime/zgoos_darwin.go [new file with mode: 0644]
src/runtime/zgoos_dragonfly.go [new file with mode: 0644]
src/runtime/zgoos_freebsd.go [new file with mode: 0644]
src/runtime/zgoos_linux.go [new file with mode: 0644]
src/runtime/zgoos_nacl.go [new file with mode: 0644]
src/runtime/zgoos_netbsd.go [new file with mode: 0644]
src/runtime/zgoos_openbsd.go [new file with mode: 0644]
src/runtime/zgoos_plan9.go [new file with mode: 0644]
src/runtime/zgoos_solaris.go [new file with mode: 0644]
src/runtime/zgoos_windows.go [new file with mode: 0644]

index e4f307bee593a4089d5d59c1556f9ca8234c95c2..bfb3d15b826b9f2799106cb3accafe4de9d5c70a 100644 (file)
@@ -615,8 +615,6 @@ static struct {
        {"anames9.c", mkanames},
        {"zdefaultcc.go", mkzdefaultcc},
        {"zsys_", mkzsys},
-       {"zgoarch_", mkzgoarch},
-       {"zgoos_", mkzgoos},
        {"zversion.go", mkzversion},
        {"zaexperiment.h", mkzexperiment},
 
@@ -1419,12 +1417,13 @@ clean(void)
                        xremove(bpathf(&b, "%s/%s", bstr(&path), cleantab[i]+4));
        }
 
-       // remove src/runtime/z* unconditionally
+       // remove src/runtime/z* unconditionally,
+       // except leave zgoos and zgoarch, now maintained with go generate.
        vreset(&dir);
        bpathf(&path, "%s/src/runtime", goroot);
        xreaddir(&dir, bstr(&path));
        for(j=0; j<dir.len; j++) {
-               if(hasprefix(dir.p[j], "z"))
+               if(hasprefix(dir.p[j], "z") && !hasprefix(dir.p[j], "zg"))
                        xremove(bpathf(&b, "%s/%s", bstr(&path), dir.p[j]));
        }
 
index e561937fb7282fbc4a23888a862e444b9bc30d97..38e99e11628fcd45d8d74b549365a9da93006d1e 100644 (file)
@@ -67,66 +67,6 @@ mkzexperiment(char *dir, char *file)
        bfree(&exp);
 }
 
-// mkzgoarch writes zgoarch_$GOARCH.go:
-//
-//     package runtime
-//     const theGoarch = <goarch>
-//
-void
-mkzgoarch(char *dir, char *file)
-{
-       Buf b, out;
-
-       USED(dir);
-       
-       binit(&b);
-       binit(&out);
-       
-       bwritestr(&out, bprintf(&b,
-               "// auto generated by go tool dist\n"
-               "\n"
-               "package runtime\n"
-               "\n"
-               "const theGoarch = `%s`\n", goarch));
-
-       writefile(&out, file, 0);
-       
-       bfree(&b);
-       bfree(&out);
-}
-
-// mkzgoos writes zgoos_$GOOS.go:
-//
-//     package runtime
-//     const theGoos = <goos>
-//
-void
-mkzgoos(char *dir, char *file)
-{
-       Buf b, out;
-
-       USED(dir);
-       
-       binit(&b);
-       binit(&out);
-
-       bwritestr(&out, "// auto generated by go tool dist\n\n");
-
-       if(streq(goos, "linux")) {
-               bwritestr(&out, "// +build !android\n\n");
-       }
-       
-       bwritestr(&out, bprintf(&b,
-               "package runtime\n"
-               "\n"
-               "const theGoos = `%s`\n", goos));
-
-       writefile(&out, file, 0);
-       
-       bfree(&b);
-       bfree(&out);
-}
-
 #define MAXWINCB 2000 /* maximum number of windows callbacks allowed */
 
 // mkzsys writes zsys_$GOOS_$GOARCH.s,
index 7746dfbf061844428c556f47c840d2e4142ea990..a73e207eddce825ef40d28884d743daa07d975df 100644 (file)
@@ -9,7 +9,7 @@ const (
        _BigEndian        = 0
        _CacheLineSize    = 64
        _RuntimeGogoBytes = 64
-       _PhysPageSize     = _NaCl*65536 + (1-_NaCl)*4096 // 4k normally; 64k on NaCl
+       _PhysPageSize     = goos_nacl*65536 + (1-goos_nacl)*4096 // 4k normally; 64k on NaCl
        _PCQuantum        = 1
        _Int64Align       = 4
 )
index 83c9c2dc9c623ce8bb523557d15a6d636323e476..794b7f65c4899c0b716e91d110aee7bae140db41 100644 (file)
@@ -8,7 +8,7 @@ const (
        thechar           = '6'
        _BigEndian        = 0
        _CacheLineSize    = 64
-       _RuntimeGogoBytes = 64 + (_Plan9|_Solaris|_Windows)*16
+       _RuntimeGogoBytes = 64 + (goos_plan9|goos_solaris|goos_windows)*16
        _PhysPageSize     = 4096
        _PCQuantum        = 1
        _Int64Align       = 8
index 5cb79fd686e7dfbe49e2cfdd544742d64d446ab1..6662eaeac396a8938aa1daf412eb592abd2f98e7 100644 (file)
@@ -9,7 +9,7 @@ const (
        _BigEndian        = 0
        _CacheLineSize    = 32
        _RuntimeGogoBytes = 60
-       _PhysPageSize     = 65536*_NaCl + 4096*(1-_NaCl)
+       _PhysPageSize     = 65536*goos_nacl + 4096*(1-goos_nacl)
        _PCQuantum        = 4
        _Int64Align       = 4
 )
diff --git a/src/runtime/gengoos.go b/src/runtime/gengoos.go
new file mode 100644 (file)
index 0000000..029575b
--- /dev/null
@@ -0,0 +1,82 @@
+// Copyright 2014 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build ignore
+
+package main
+
+import (
+       "bytes"
+       "fmt"
+       "io/ioutil"
+       "log"
+       "strconv"
+       "strings"
+)
+
+var gooses, goarches []string
+
+func main() {
+       data, err := ioutil.ReadFile("../go/build/syslist.go")
+       if err != nil {
+               log.Fatal(err)
+       }
+       const (
+               goosPrefix   = `const goosList = `
+               goarchPrefix = `const goarchList = `
+       )
+       for _, line := range strings.Split(string(data), "\n") {
+               if strings.HasPrefix(line, goosPrefix) {
+                       text, err := strconv.Unquote(strings.TrimPrefix(line, goosPrefix))
+                       if err != nil {
+                               log.Fatalf("parsing goosList %#q: %v", strings.TrimPrefix(line, goosPrefix), err)
+                       }
+                       gooses = strings.Fields(text)
+               }
+               if strings.HasPrefix(line, goarchPrefix) {
+                       text, err := strconv.Unquote(strings.TrimPrefix(line, goarchPrefix))
+                       if err != nil {
+                               log.Fatal("parsing goarchList: %v", err)
+                       }
+                       goarches = strings.Fields(text)
+               }
+       }
+
+       for _, target := range gooses {
+               var buf bytes.Buffer
+               fmt.Fprintf(&buf, "// generated by gengoos.go using 'go generate'\n\n")
+               fmt.Fprintf(&buf, "// +build %s\n\n", target) // usually redundant, but not always; see linux vs android
+               fmt.Fprintf(&buf, "package runtime\n\n")
+               fmt.Fprintf(&buf, "const theGoos = `%s`\n\n", target)
+               for _, goos := range gooses {
+                       value := 0
+                       if goos == target {
+                               value = 1
+                       }
+                       fmt.Fprintf(&buf, "const goos_%s = %d\n", goos, value)
+               }
+               err := ioutil.WriteFile("zgoos_"+target+".go", buf.Bytes(), 0666)
+               if err != nil {
+                       log.Fatal(err)
+               }
+       }
+
+       for _, target := range goarches {
+               var buf bytes.Buffer
+               fmt.Fprintf(&buf, "// generated by gengoos.go using 'go generate'\n\n")
+               fmt.Fprintf(&buf, "package runtime\n\n")
+               fmt.Fprintf(&buf, "const theGoarch = `%s`\n\n", target)
+               for _, goarch := range goarches {
+                       value := 0
+                       if goarch == target {
+                               value = 1
+                       }
+                       fmt.Fprintf(&buf, "const goarch_%s = %d\n", goarch, value)
+               }
+               err := ioutil.WriteFile("zgoarch_"+target+".go", buf.Bytes(), 0666)
+               if err != nil {
+                       log.Fatal(err)
+               }
+       }
+}
index e4bd963d3060f0afa75defad8fbf94f79f375760..c175c2aec7b2259c0ba07be64a22b975cd4f3bb3 100644 (file)
@@ -126,7 +126,7 @@ const (
        // See http://golang.org/issue/5402 and http://golang.org/issue/5236.
        // On other 64-bit platforms, we limit the arena to 128GB, or 37 bits.
        // On 32-bit, we don't bother limiting anything, so we use the full 32-bit address.
-       _MHeapMap_TotalBits = (_64bit*_Windows)*35 + (_64bit*(1-_Windows))*37 + (1-_64bit)*32
+       _MHeapMap_TotalBits = (_64bit*goos_windows)*35 + (_64bit*(1-goos_windows))*37 + (1-_64bit)*32
        _MHeapMap_Bits      = _MHeapMap_TotalBits - _PageShift
 
        _MaxMem = uintptr(1<<_MHeapMap_TotalBits - 1)
index c999b3072dbd993cbe19a2cba8b5185edf0f630f..7987a737308bc0e47c88333f0763a551f3b2eaf3 100644 (file)
@@ -45,7 +45,13 @@ const (
        _Pdead
 )
 
-// XXX inserting below here
+// The next line makes 'go generate' write the zgen_*.go files with
+// per-OS and per-arch information, including constants
+// named goos_$GOOS and goarch_$GOARCH for every
+// known GOOS and GOARCH. The constant is 1 on the
+// current system, 0 otherwise; multiplying by them is
+// useful for defining GOOS- or GOARCH-specific constants.
+//go:generate go run gengoos.go
 
 type mutex struct {
        // Futex-based impl treats it as uint32 key,
@@ -395,14 +401,6 @@ type itab struct {
        fun    [0]uintptr
 }
 
-const (
-       // TODO: Generate in cmd/dist.
-       _NaCl    = 0
-       _Windows = 0
-       _Solaris = 0
-       _Plan9   = 0
-)
-
 // Lock-free stack node.
 type lfnode struct {
        next    *lfnode
index 40dfc76a6dde6c4555a5930c3c5bf11784f7fc4c..ad83e589512ce5e9d36db9a203939dc4d3b384b4 100644 (file)
@@ -775,7 +775,7 @@ func shrinkstack(gp *g) {
        }
 
        /* TODO
-       if _Windows && gp.m != nil && gp.m.libcallsp != 0 {
+       if goos_windows && gp.m != nil && gp.m.libcallsp != 0 {
                return
        }
        */
index c3718c205e5e48e8110cb65ecc249a0a99601e2e..e50b32c784ab655781be39cceb72d213e4181917 100644 (file)
@@ -59,7 +59,7 @@ const (
        // to each stack below the usual guard area for OS-specific
        // purposes like signal handling. Used on Windows and on
        // Plan 9 because they do not use a separate stack.
-       _StackSystem = _Windows*512*ptrSize + _Plan9*512
+       _StackSystem = goos_windows*512*ptrSize + goos_plan9*512
 
        // The minimum size of stack used by Go code
        _StackMin = 2048
diff --git a/src/runtime/zgoarch_386.go b/src/runtime/zgoarch_386.go
new file mode 100644 (file)
index 0000000..057a746
--- /dev/null
@@ -0,0 +1,12 @@
+// generated by gengoos.go using 'go generate'
+
+package runtime
+
+const theGoarch = `386`
+
+const goarch_386 = 1
+const goarch_amd64 = 0
+const goarch_amd64p32 = 0
+const goarch_arm = 0
+const goarch_power64 = 0
+const goarch_power64le = 0
diff --git a/src/runtime/zgoarch_amd64.go b/src/runtime/zgoarch_amd64.go
new file mode 100644 (file)
index 0000000..a712407
--- /dev/null
@@ -0,0 +1,12 @@
+// generated by gengoos.go using 'go generate'
+
+package runtime
+
+const theGoarch = `amd64`
+
+const goarch_386 = 0
+const goarch_amd64 = 1
+const goarch_amd64p32 = 0
+const goarch_arm = 0
+const goarch_power64 = 0
+const goarch_power64le = 0
diff --git a/src/runtime/zgoarch_amd64p32.go b/src/runtime/zgoarch_amd64p32.go
new file mode 100644 (file)
index 0000000..2b6a142
--- /dev/null
@@ -0,0 +1,12 @@
+// generated by gengoos.go using 'go generate'
+
+package runtime
+
+const theGoarch = `amd64p32`
+
+const goarch_386 = 0
+const goarch_amd64 = 0
+const goarch_amd64p32 = 1
+const goarch_arm = 0
+const goarch_power64 = 0
+const goarch_power64le = 0
diff --git a/src/runtime/zgoarch_arm.go b/src/runtime/zgoarch_arm.go
new file mode 100644 (file)
index 0000000..4030210
--- /dev/null
@@ -0,0 +1,12 @@
+// generated by gengoos.go using 'go generate'
+
+package runtime
+
+const theGoarch = `arm`
+
+const goarch_386 = 0
+const goarch_amd64 = 0
+const goarch_amd64p32 = 0
+const goarch_arm = 1
+const goarch_power64 = 0
+const goarch_power64le = 0
diff --git a/src/runtime/zgoarch_power64.go b/src/runtime/zgoarch_power64.go
new file mode 100644 (file)
index 0000000..cc361f0
--- /dev/null
@@ -0,0 +1,12 @@
+// generated by gengoos.go using 'go generate'
+
+package runtime
+
+const theGoarch = `power64`
+
+const goarch_386 = 0
+const goarch_amd64 = 0
+const goarch_amd64p32 = 0
+const goarch_arm = 0
+const goarch_power64 = 1
+const goarch_power64le = 0
diff --git a/src/runtime/zgoarch_power64le.go b/src/runtime/zgoarch_power64le.go
new file mode 100644 (file)
index 0000000..41294e6
--- /dev/null
@@ -0,0 +1,12 @@
+// generated by gengoos.go using 'go generate'
+
+package runtime
+
+const theGoarch = `power64le`
+
+const goarch_386 = 0
+const goarch_amd64 = 0
+const goarch_amd64p32 = 0
+const goarch_arm = 0
+const goarch_power64 = 0
+const goarch_power64le = 1
diff --git a/src/runtime/zgoos_android.go b/src/runtime/zgoos_android.go
new file mode 100644 (file)
index 0000000..abfba80
--- /dev/null
@@ -0,0 +1,19 @@
+// generated by gengoos.go using 'go generate'
+
+// +build android
+
+package runtime
+
+const theGoos = `android`
+
+const goos_android = 1
+const goos_darwin = 0
+const goos_dragonfly = 0
+const goos_freebsd = 0
+const goos_linux = 0
+const goos_nacl = 0
+const goos_netbsd = 0
+const goos_openbsd = 0
+const goos_plan9 = 0
+const goos_solaris = 0
+const goos_windows = 0
diff --git a/src/runtime/zgoos_darwin.go b/src/runtime/zgoos_darwin.go
new file mode 100644 (file)
index 0000000..eb39b53
--- /dev/null
@@ -0,0 +1,19 @@
+// generated by gengoos.go using 'go generate'
+
+// +build darwin
+
+package runtime
+
+const theGoos = `darwin`
+
+const goos_android = 0
+const goos_darwin = 1
+const goos_dragonfly = 0
+const goos_freebsd = 0
+const goos_linux = 0
+const goos_nacl = 0
+const goos_netbsd = 0
+const goos_openbsd = 0
+const goos_plan9 = 0
+const goos_solaris = 0
+const goos_windows = 0
diff --git a/src/runtime/zgoos_dragonfly.go b/src/runtime/zgoos_dragonfly.go
new file mode 100644 (file)
index 0000000..f6e839d
--- /dev/null
@@ -0,0 +1,19 @@
+// generated by gengoos.go using 'go generate'
+
+// +build dragonfly
+
+package runtime
+
+const theGoos = `dragonfly`
+
+const goos_android = 0
+const goos_darwin = 0
+const goos_dragonfly = 1
+const goos_freebsd = 0
+const goos_linux = 0
+const goos_nacl = 0
+const goos_netbsd = 0
+const goos_openbsd = 0
+const goos_plan9 = 0
+const goos_solaris = 0
+const goos_windows = 0
diff --git a/src/runtime/zgoos_freebsd.go b/src/runtime/zgoos_freebsd.go
new file mode 100644 (file)
index 0000000..3c47aef
--- /dev/null
@@ -0,0 +1,19 @@
+// generated by gengoos.go using 'go generate'
+
+// +build freebsd
+
+package runtime
+
+const theGoos = `freebsd`
+
+const goos_android = 0
+const goos_darwin = 0
+const goos_dragonfly = 0
+const goos_freebsd = 1
+const goos_linux = 0
+const goos_nacl = 0
+const goos_netbsd = 0
+const goos_openbsd = 0
+const goos_plan9 = 0
+const goos_solaris = 0
+const goos_windows = 0
diff --git a/src/runtime/zgoos_linux.go b/src/runtime/zgoos_linux.go
new file mode 100644 (file)
index 0000000..5d899e3
--- /dev/null
@@ -0,0 +1,19 @@
+// generated by gengoos.go using 'go generate'
+
+// +build linux
+
+package runtime
+
+const theGoos = `linux`
+
+const goos_android = 0
+const goos_darwin = 0
+const goos_dragonfly = 0
+const goos_freebsd = 0
+const goos_linux = 1
+const goos_nacl = 0
+const goos_netbsd = 0
+const goos_openbsd = 0
+const goos_plan9 = 0
+const goos_solaris = 0
+const goos_windows = 0
diff --git a/src/runtime/zgoos_nacl.go b/src/runtime/zgoos_nacl.go
new file mode 100644 (file)
index 0000000..b5c4281
--- /dev/null
@@ -0,0 +1,19 @@
+// generated by gengoos.go using 'go generate'
+
+// +build nacl
+
+package runtime
+
+const theGoos = `nacl`
+
+const goos_android = 0
+const goos_darwin = 0
+const goos_dragonfly = 0
+const goos_freebsd = 0
+const goos_linux = 0
+const goos_nacl = 1
+const goos_netbsd = 0
+const goos_openbsd = 0
+const goos_plan9 = 0
+const goos_solaris = 0
+const goos_windows = 0
diff --git a/src/runtime/zgoos_netbsd.go b/src/runtime/zgoos_netbsd.go
new file mode 100644 (file)
index 0000000..b2e4522
--- /dev/null
@@ -0,0 +1,19 @@
+// generated by gengoos.go using 'go generate'
+
+// +build netbsd
+
+package runtime
+
+const theGoos = `netbsd`
+
+const goos_android = 0
+const goos_darwin = 0
+const goos_dragonfly = 0
+const goos_freebsd = 0
+const goos_linux = 0
+const goos_nacl = 0
+const goos_netbsd = 1
+const goos_openbsd = 0
+const goos_plan9 = 0
+const goos_solaris = 0
+const goos_windows = 0
diff --git a/src/runtime/zgoos_openbsd.go b/src/runtime/zgoos_openbsd.go
new file mode 100644 (file)
index 0000000..331c96d
--- /dev/null
@@ -0,0 +1,19 @@
+// generated by gengoos.go using 'go generate'
+
+// +build openbsd
+
+package runtime
+
+const theGoos = `openbsd`
+
+const goos_android = 0
+const goos_darwin = 0
+const goos_dragonfly = 0
+const goos_freebsd = 0
+const goos_linux = 0
+const goos_nacl = 0
+const goos_netbsd = 0
+const goos_openbsd = 1
+const goos_plan9 = 0
+const goos_solaris = 0
+const goos_windows = 0
diff --git a/src/runtime/zgoos_plan9.go b/src/runtime/zgoos_plan9.go
new file mode 100644 (file)
index 0000000..f29eb45
--- /dev/null
@@ -0,0 +1,19 @@
+// generated by gengoos.go using 'go generate'
+
+// +build plan9
+
+package runtime
+
+const theGoos = `plan9`
+
+const goos_android = 0
+const goos_darwin = 0
+const goos_dragonfly = 0
+const goos_freebsd = 0
+const goos_linux = 0
+const goos_nacl = 0
+const goos_netbsd = 0
+const goos_openbsd = 0
+const goos_plan9 = 1
+const goos_solaris = 0
+const goos_windows = 0
diff --git a/src/runtime/zgoos_solaris.go b/src/runtime/zgoos_solaris.go
new file mode 100644 (file)
index 0000000..ac613db
--- /dev/null
@@ -0,0 +1,19 @@
+// generated by gengoos.go using 'go generate'
+
+// +build solaris
+
+package runtime
+
+const theGoos = `solaris`
+
+const goos_android = 0
+const goos_darwin = 0
+const goos_dragonfly = 0
+const goos_freebsd = 0
+const goos_linux = 0
+const goos_nacl = 0
+const goos_netbsd = 0
+const goos_openbsd = 0
+const goos_plan9 = 0
+const goos_solaris = 1
+const goos_windows = 0
diff --git a/src/runtime/zgoos_windows.go b/src/runtime/zgoos_windows.go
new file mode 100644 (file)
index 0000000..43710d8
--- /dev/null
@@ -0,0 +1,19 @@
+// generated by gengoos.go using 'go generate'
+
+// +build windows
+
+package runtime
+
+const theGoos = `windows`
+
+const goos_android = 0
+const goos_darwin = 0
+const goos_dragonfly = 0
+const goos_freebsd = 0
+const goos_linux = 0
+const goos_nacl = 0
+const goos_netbsd = 0
+const goos_openbsd = 0
+const goos_plan9 = 0
+const goos_solaris = 0
+const goos_windows = 1