github.com/cloudflare/circl@v1.5.0/.etc/all_imports.go (about)

     1  //go:build ignore
     2  // +build ignore
     3  
     4  // Generates a Go program with all the public imports of CIRCL. It is used to
     5  // test compilation using static (buildmode=default) and dynamic linking
     6  // (buildmode=plugin).
     7  package main
     8  
     9  import (
    10  	"flag"
    11  	"fmt"
    12  	"io/fs"
    13  	"os"
    14  	"strings"
    15  )
    16  
    17  func main() {
    18  	outputFileName := flag.String("out", "circl.go", "name of the output file.")
    19  	flag.Parse()
    20  
    21  	f, err := os.Create(*outputFileName)
    22  	if err != nil {
    23  		panic(err)
    24  	}
    25  	defer f.Close()
    26  
    27  	skipDirs := []string{".", "testdata", "internal", "templates"}
    28  	circl := "github.com/cloudflare/circl/"
    29  
    30  	fmt.Fprintln(f, "package main")
    31  	err = fs.WalkDir(os.DirFS("."), ".", func(path string, d fs.DirEntry, err error) error {
    32  		if err != nil {
    33  			panic(err)
    34  		}
    35  		if d.IsDir() {
    36  			for _, sd := range skipDirs {
    37  				if strings.Contains(path, sd) {
    38  					return nil
    39  				}
    40  			}
    41  			fmt.Fprintf(f, "import _ \"%v%v\"\n", circl, path)
    42  		}
    43  		return nil
    44  	})
    45  	if err != nil {
    46  		panic(err)
    47  	}
    48  	fmt.Fprintln(f, "func main() {}")
    49  }