Black Lives Matter. Support the Equal Justice Initiative.

Source file src/cmd/go/internal/imports/tags.go

Documentation: cmd/go/internal/imports

     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  package imports
     6  
     7  import (
     8  	"cmd/go/internal/cfg"
     9  	"sync"
    10  )
    11  
    12  var (
    13  	tags     map[string]bool
    14  	tagsOnce sync.Once
    15  )
    16  
    17  // Tags returns a set of build tags that are true for the target platform.
    18  // It includes GOOS, GOARCH, the compiler, possibly "cgo",
    19  // release tags like "go1.13", and user-specified build tags.
    20  func Tags() map[string]bool {
    21  	tagsOnce.Do(func() {
    22  		tags = loadTags()
    23  	})
    24  	return tags
    25  }
    26  
    27  func loadTags() map[string]bool {
    28  	tags := map[string]bool{
    29  		cfg.BuildContext.GOOS:     true,
    30  		cfg.BuildContext.GOARCH:   true,
    31  		cfg.BuildContext.Compiler: true,
    32  	}
    33  	if cfg.BuildContext.CgoEnabled {
    34  		tags["cgo"] = true
    35  	}
    36  	for _, tag := range cfg.BuildContext.BuildTags {
    37  		tags[tag] = true
    38  	}
    39  	for _, tag := range cfg.BuildContext.ReleaseTags {
    40  		tags[tag] = true
    41  	}
    42  	return tags
    43  }
    44  
    45  var (
    46  	anyTags     map[string]bool
    47  	anyTagsOnce sync.Once
    48  )
    49  
    50  // AnyTags returns a special set of build tags that satisfy nearly all
    51  // build tag expressions. Only "ignore" and malformed build tag requirements
    52  // are considered false.
    53  func AnyTags() map[string]bool {
    54  	anyTagsOnce.Do(func() {
    55  		anyTags = map[string]bool{"*": true}
    56  	})
    57  	return anyTags
    58  }
    59  

View as plain text