...
Run Format

Source file src/runtime/internal/sys/gengoos.go

Documentation: runtime/internal/sys

     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  // +build ignore
     6  
     7  package main
     8  
     9  import (
    10  	"bytes"
    11  	"fmt"
    12  	"io/ioutil"
    13  	"log"
    14  	"strconv"
    15  	"strings"
    16  )
    17  
    18  var gooses, goarches []string
    19  
    20  func main() {
    21  	data, err := ioutil.ReadFile("../../../go/build/syslist.go")
    22  	if err != nil {
    23  		log.Fatal(err)
    24  	}
    25  	const (
    26  		goosPrefix   = `const goosList = `
    27  		goarchPrefix = `const goarchList = `
    28  	)
    29  	for _, line := range strings.Split(string(data), "\n") {
    30  		if strings.HasPrefix(line, goosPrefix) {
    31  			text, err := strconv.Unquote(strings.TrimPrefix(line, goosPrefix))
    32  			if err != nil {
    33  				log.Fatalf("parsing goosList: %v", err)
    34  			}
    35  			gooses = strings.Fields(text)
    36  		}
    37  		if strings.HasPrefix(line, goarchPrefix) {
    38  			text, err := strconv.Unquote(strings.TrimPrefix(line, goarchPrefix))
    39  			if err != nil {
    40  				log.Fatalf("parsing goarchList: %v", err)
    41  			}
    42  			goarches = strings.Fields(text)
    43  		}
    44  	}
    45  
    46  	for _, target := range gooses {
    47  		var buf bytes.Buffer
    48  		fmt.Fprintf(&buf, "// Code generated by gengoos.go using 'go generate'. DO NOT EDIT.\n\n")
    49  		if target == "linux" {
    50  			fmt.Fprintf(&buf, "// +build !android\n") // must explicitly exclude android for linux
    51  		}
    52  		fmt.Fprintf(&buf, "// +build %s\n\n", target) // must explicitly include target for bootstrapping purposes
    53  		fmt.Fprintf(&buf, "package sys\n\n")
    54  		fmt.Fprintf(&buf, "const GOOS = `%s`\n\n", target)
    55  		for _, goos := range gooses {
    56  			value := 0
    57  			if goos == target {
    58  				value = 1
    59  			}
    60  			fmt.Fprintf(&buf, "const Goos%s = %d\n", strings.Title(goos), value)
    61  		}
    62  		err := ioutil.WriteFile("zgoos_"+target+".go", buf.Bytes(), 0666)
    63  		if err != nil {
    64  			log.Fatal(err)
    65  		}
    66  	}
    67  
    68  	for _, target := range goarches {
    69  		var buf bytes.Buffer
    70  		fmt.Fprintf(&buf, "// Code generated by gengoos.go using 'go generate'. DO NOT EDIT.\n\n")
    71  		fmt.Fprintf(&buf, "// +build %s\n\n", target) // must explicitly include target for bootstrapping purposes
    72  		fmt.Fprintf(&buf, "package sys\n\n")
    73  		fmt.Fprintf(&buf, "const GOARCH = `%s`\n\n", target)
    74  		for _, goarch := range goarches {
    75  			value := 0
    76  			if goarch == target {
    77  				value = 1
    78  			}
    79  			fmt.Fprintf(&buf, "const Goarch%s = %d\n", strings.Title(goarch), value)
    80  		}
    81  		err := ioutil.WriteFile("zgoarch_"+target+".go", buf.Bytes(), 0666)
    82  		if err != nil {
    83  			log.Fatal(err)
    84  		}
    85  	}
    86  }
    87  

View as plain text