github.com/gidoBOSSftw5731/go/src@v0.0.0-20210226122457-d24b0edbf019/runtime/internal/sys/gengoos.go (about)

     1  // Copyright 2014 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build ignore
     6  // +build ignore
     7  
     8  package main
     9  
    10  import (
    11  	"bytes"
    12  	"fmt"
    13  	"log"
    14  	"os"
    15  	"strconv"
    16  	"strings"
    17  )
    18  
    19  var gooses, goarches []string
    20  
    21  func main() {
    22  	data, err := os.ReadFile("../../../go/build/syslist.go")
    23  	if err != nil {
    24  		log.Fatal(err)
    25  	}
    26  	const (
    27  		goosPrefix   = `const goosList = `
    28  		goarchPrefix = `const goarchList = `
    29  	)
    30  	for _, line := range strings.Split(string(data), "\n") {
    31  		if strings.HasPrefix(line, goosPrefix) {
    32  			text, err := strconv.Unquote(strings.TrimPrefix(line, goosPrefix))
    33  			if err != nil {
    34  				log.Fatalf("parsing goosList: %v", err)
    35  			}
    36  			gooses = strings.Fields(text)
    37  		}
    38  		if strings.HasPrefix(line, goarchPrefix) {
    39  			text, err := strconv.Unquote(strings.TrimPrefix(line, goarchPrefix))
    40  			if err != nil {
    41  				log.Fatalf("parsing goarchList: %v", err)
    42  			}
    43  			goarches = strings.Fields(text)
    44  		}
    45  	}
    46  
    47  	for _, target := range gooses {
    48  		if target == "nacl" {
    49  			continue
    50  		}
    51  		var buf bytes.Buffer
    52  		fmt.Fprintf(&buf, "// Code generated by gengoos.go using 'go generate'. DO NOT EDIT.\n\n")
    53  		if target == "linux" {
    54  			fmt.Fprintf(&buf, "// +build !android\n") // must explicitly exclude android for linux
    55  		}
    56  		if target == "solaris" {
    57  			fmt.Fprintf(&buf, "// +build !illumos\n") // must explicitly exclude illumos for solaris
    58  		}
    59  		if target == "darwin" {
    60  			fmt.Fprintf(&buf, "// +build !ios\n") // must explicitly exclude ios for darwin
    61  		}
    62  		fmt.Fprintf(&buf, "// +build %s\n\n", target) // must explicitly include target for bootstrapping purposes
    63  		fmt.Fprintf(&buf, "package sys\n\n")
    64  		fmt.Fprintf(&buf, "const GOOS = `%s`\n\n", target)
    65  		for _, goos := range gooses {
    66  			value := 0
    67  			if goos == target {
    68  				value = 1
    69  			}
    70  			fmt.Fprintf(&buf, "const Goos%s = %d\n", strings.Title(goos), value)
    71  		}
    72  		err := os.WriteFile("zgoos_"+target+".go", buf.Bytes(), 0666)
    73  		if err != nil {
    74  			log.Fatal(err)
    75  		}
    76  	}
    77  
    78  	for _, target := range goarches {
    79  		if target == "amd64p32" {
    80  			continue
    81  		}
    82  		var buf bytes.Buffer
    83  		fmt.Fprintf(&buf, "// Code generated by gengoos.go using 'go generate'. DO NOT EDIT.\n\n")
    84  		fmt.Fprintf(&buf, "// +build %s\n\n", target) // must explicitly include target for bootstrapping purposes
    85  		fmt.Fprintf(&buf, "package sys\n\n")
    86  		fmt.Fprintf(&buf, "const GOARCH = `%s`\n\n", target)
    87  		for _, goarch := range goarches {
    88  			value := 0
    89  			if goarch == target {
    90  				value = 1
    91  			}
    92  			fmt.Fprintf(&buf, "const Goarch%s = %d\n", strings.Title(goarch), value)
    93  		}
    94  		err := os.WriteFile("zgoarch_"+target+".go", buf.Bytes(), 0666)
    95  		if err != nil {
    96  			log.Fatal(err)
    97  		}
    98  	}
    99  }