Text file src/cmd/go/testdata/script/build_overlay_cgo.txt

     1  [!cgo] skip
     2  
     3  # Test building cgo packages in overlays.
     4  
     5  cd m
     6  
     7  go build -overlay overlay.json -o main_cgo_replace$GOEXE ./cgo_hello_replace
     8  exec ./main_cgo_replace$GOEXE
     9  stdout '^hello cgo\r?\n'
    10  
    11  go build -overlay overlay.json -o main_cgo_quote$GOEXE ./cgo_hello_quote
    12  exec ./main_cgo_quote$GOEXE
    13  stdout '^hello cgo\r?\n'
    14  
    15  go build -overlay overlay.json -o main_cgo_angle$GOEXE ./cgo_hello_angle
    16  exec ./main_cgo_angle$GOEXE
    17  stdout '^hello cgo\r?\n'
    18  
    19  go list -compiled -overlay overlay.json -f '{{range .CompiledGoFiles}}{{. | printf "%s\n"}}{{end}}' ./cgo_hello_replace
    20  cp stdout compiled_cgo_sources.txt
    21  go run ../print_line_comments.go compiled_cgo_sources.txt
    22  stdout $GOPATH[/\\]src[/\\]m[/\\]cgo_hello_replace[/\\]cgo_hello_replace.go
    23  ! stdout $GOPATH[/\\]src[/\\]m[/\\]overlay[/\\]hello.c
    24  
    25  -- m/go.mod --
    26  // TODO(matloob): how do overlays work with go.mod (especially if mod=readonly)
    27  module m
    28  
    29  go 1.16
    30  
    31  -- m/overlay.json --
    32  {
    33  	"Replace": {
    34  		"printpath/main.go": "overlay/printpath.go",
    35  		"printpath/other.go": "overlay2/printpath2.go",
    36  		"call_asm/asm_gc.s": "overlay/asm_gc.s",
    37  		"call_asm/asm_gccgo.s": "overlay/asm_gccgo.s",
    38  		"test_cache/main.go": "overlay/test_cache.go",
    39  		"cgo_hello_replace/cgo_header.h": "overlay/cgo_head.h",
    40  		"cgo_hello_replace/hello.c": "overlay/hello.c",
    41  		"cgo_hello_quote/cgo_hello.go": "overlay/cgo_hello_quote.go",
    42  		"cgo_hello_quote/cgo_header.h": "overlay/cgo_head.h",
    43  		"cgo_hello_angle/cgo_hello.go": "overlay/cgo_hello_angle.go",
    44  		"cgo_hello_angle/cgo_header.h": "overlay/cgo_head.h"
    45  	}
    46  }
    47  -- m/cgo_hello_replace/cgo_hello_replace.go --
    48  package main
    49  
    50  // #include "cgo_header.h"
    51  import "C"
    52  
    53  func main() {
    54  	C.say_hello()
    55  }
    56  -- m/cgo_hello_replace/cgo_header.h --
    57   // Test that this header is replaced with one that has the proper declaration.
    58  void say_goodbye();
    59  
    60  -- m/cgo_hello_replace/hello.c --
    61  #include <stdio.h>
    62  
    63  void say_goodbye() { puts("goodbye cgo\n"); fflush(stdout); }
    64  
    65  -- m/overlay/cgo_hello_quote.go --
    66  package main
    67  
    68  // #include "cgo_header.h"
    69  import "C"
    70  
    71  func main() {
    72  	C.say_hello()
    73  }
    74  -- m/overlay/cgo_hello_angle.go --
    75  package main
    76  
    77  // #include <cgo_header.h>
    78  import "C"
    79  
    80  func main() {
    81  	C.say_hello()
    82  }
    83  -- m/overlay/cgo_head.h --
    84  void say_hello();
    85  -- m/overlay/hello.c --
    86  #include <stdio.h>
    87  
    88  void say_hello() { puts("hello cgo\n"); fflush(stdout); }
    89  -- m/cgo_hello_quote/hello.c --
    90  #include <stdio.h>
    91  
    92  void say_hello() { puts("hello cgo\n"); fflush(stdout); }
    93  -- m/cgo_hello_angle/hello.c --
    94  #include <stdio.h>
    95  
    96  void say_hello() { puts("hello cgo\n"); fflush(stdout); }
    97  
    98  -- print_line_comments.go --
    99  package main
   100  
   101  import (
   102  	"fmt"
   103  	"io/ioutil"
   104  	"log"
   105  	"os"
   106  	"strings"
   107  )
   108  
   109  func main() {
   110  	compiledGoFilesArg := os.Args[1]
   111  	b, err := ioutil.ReadFile(compiledGoFilesArg)
   112  	if err != nil {
   113  		log.Fatal(err)
   114  	}
   115  	compiledGoFiles := strings.Split(strings.TrimSpace(string(b)), "\n")
   116  	for _, f := range compiledGoFiles {
   117  		b, err := ioutil.ReadFile(f)
   118  		if err != nil {
   119  			log.Fatal(err)
   120  		}
   121  		for _, line := range strings.Split(string(b), "\n") {
   122  			if strings.HasPrefix(line, "#line") || strings.HasPrefix(line, "//line") {
   123  				fmt.Println(line)
   124  			}
   125  		}
   126  	}
   127  }
   128  

View as plain text