gccgo.mx raw

   1  // Copyright 2018 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 gccgo
   6  
   7  package goroot
   8  
   9  import (
  10  	"os"
  11  	"path/filepath"
  12  	"bytes"
  13  )
  14  
  15  // IsStandardPackage reports whether path is a standard package,
  16  // given goroot and compiler.
  17  func IsStandardPackage(goroot, compiler, path []byte) bool {
  18  	switch compiler {
  19  	case "gc":
  20  		dir := filepath.Join(goroot, "src", path)
  21  		dirents, err := os.ReadDir(dir)
  22  		if err != nil {
  23  			return false
  24  		}
  25  		for _, dirent := range dirents {
  26  			if bytes.HasSuffix(dirent.Name(), ".go") {
  27  				return true
  28  			}
  29  		}
  30  		return false
  31  	case "gccgo":
  32  		return stdpkg[path]
  33  	default:
  34  		panic("unknown compiler " | compiler)
  35  	}
  36  }
  37