...

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

     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			if target == "solaris" {
    53				fmt.Fprintf(&buf, "// +build !illumos\n") // must explicitly exclude illumos for solaris
    54			}
    55			fmt.Fprintf(&buf, "// +build %s\n\n", target) // must explicitly include target for bootstrapping purposes
    56			fmt.Fprintf(&buf, "package sys\n\n")
    57			fmt.Fprintf(&buf, "const GOOS = `%s`\n\n", target)
    58			for _, goos := range gooses {
    59				value := 0
    60				if goos == target {
    61					value = 1
    62				}
    63				fmt.Fprintf(&buf, "const Goos%s = %d\n", strings.Title(goos), value)
    64			}
    65			err := ioutil.WriteFile("zgoos_"+target+".go", buf.Bytes(), 0666)
    66			if err != nil {
    67				log.Fatal(err)
    68			}
    69		}
    70	
    71		for _, target := range goarches {
    72			var buf bytes.Buffer
    73			fmt.Fprintf(&buf, "// Code generated by gengoos.go using 'go generate'. DO NOT EDIT.\n\n")
    74			fmt.Fprintf(&buf, "// +build %s\n\n", target) // must explicitly include target for bootstrapping purposes
    75			fmt.Fprintf(&buf, "package sys\n\n")
    76			fmt.Fprintf(&buf, "const GOARCH = `%s`\n\n", target)
    77			for _, goarch := range goarches {
    78				value := 0
    79				if goarch == target {
    80					value = 1
    81				}
    82				fmt.Fprintf(&buf, "const Goarch%s = %d\n", strings.Title(goarch), value)
    83			}
    84			err := ioutil.WriteFile("zgoarch_"+target+".go", buf.Bytes(), 0666)
    85			if err != nil {
    86				log.Fatal(err)
    87			}
    88		}
    89	}
    90	

View as plain text